Practicing Methods
The code contains a struct called Cypher
which basically represents a kind of Caesar cipher.
Read the code and fill in the blanks to make sure it works properly. The following is how the final program is supposed to be:
setText
method converts the passed text into encoded text and stores it into the fieldtext
. This method takes onestring
argument calledtext
, and the method does not return any value;rawText
returns thetext
field content. This method takes no arguments;decodedText
decodes thetext
field content and returns the result. This method also doesn't take any arguments.
index.cs
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
struct Cypher
{
public string text;
___
{
string encodedText = "";
foreach(char chr in text)
encodedText += (char) (chr + 7);
___ = encodedText;
}
public string rawText()
{
___
}
___
{
string decodedText = "";
foreach (char chr in this.text)
decodedText += (char)(chr - 7);
___
}
}
class ConsoleApp
{
static void Main(string[] args)
{
1234567891011121314151617181920212223242526272829303132333435363738394041424344using System; struct Cypher { public string text; ___ { string encodedText = ""; foreach(char chr in text) encodedText += (char) (chr + 7); ___ = encodedText; } public string rawText() { ___ } ___ { string decodedText = ""; foreach (char chr in this.text) decodedText += (char)(chr - 7); ___ } } class ConsoleApp { static void Main(string[] args) { Cypher text1 = new Cypher(); text1.setText("This is an example sentence."); Console.WriteLine(text1.rawText()); Console.WriteLine(text1.decodedText()); } }
Var alt klart?
Tak for dine kommentarer!
Sektion 2. Kapitel 7
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat