-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchapter8Notes.cpp
129 lines (78 loc) · 2.48 KB
/
chapter8Notes.cpp
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <iostream>
#include <array>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <string>
//Simple C++ program to encrypt and decrypt a string
#include <iostream>
int main()
{
int i, x;
char str[100];
std::cout << "Please enter a string:\t";
std::cin >> str;
std::cout << "\nPlease choose following options:\n";
std::cout << "1 = Encrypt the string.\n";
std::cout << "2 = Decrypt the string.\n";
std::cin >> x;
//using switch case statements
switch(x)
{
//first case for encrypting a string
case 1:
for(i = 0; (i < 100 && str[i] != '\0'); i++)
str[i] = str[i] + 2; //the key for encryption is 3 that is added to ASCII value
std::cout << "\nEncrypted string: " << str << std::endl;
break;
//second case for decrypting a string
case 2:
for(i = 0; (i < 100 && str[i] != '\0'); i++)
str[i] = str[i] - 2; //the key for encryption is 3 that is subtracted to ASCII value
std::cout << "\nDecrypted string: " << str << std::endl;
break;
default:
std::cout << "\nInvalid Input !!!\n";
}
return 0;
}
/*
String Notes
char a[80];
std::cout << "Enter some input:\n";
std::cin.getline(a, 80);
std::cout << a << " End of output\n";
char short_string[5];
std::cout << "Enter some input:\n";
std::cin.getline(short_string, 5);
std::cout << short_string << " End of Output\n";
std::string phrase;
std::string adjective = "fried";
std::string noun = "ants";
std::string wish = "Bon appetit!";
phrase = "I love " + adjective + " " + noun + "!";
std::cout << phrase << std::endl;
std::cout << wish << std::endl;
std::string first_name;
std::string last_name;
std::string record_name;
std::string motto = "Your records are our records.";
new_line();
record_name = last_name + ", " + first_name;
std::cout << "Your name in our records is: ";
std::cout << record_name << std::endl;
DECRYPT NAME
int main(){
std::string name;
char ch = 'y';
do{
std::cout << "Enter name: " << std::endl;
std::getline(std::cin, name);
std::cout << "initials " << name[0] << " " << name[name.find (" ") + 1] << std::endl;
std::cout << "Do you want to continue (y or n)" << std::endl;
std::cin >> ch;
std::cin.ignore(1, '\n');
} while (ch == 'y' || ch == 'Y');
return 0;
}
*/