Write a psuedocode for this program.
#include <iostream>
using namespace std;
string message;
string mappedKey;
void messageAndKey(){
string msg;
cout << "Enter message: ";
getline(cin, msg);
cin.ignore();
//message to uppercase
for(int i = 0; i < msg.length(); i++){
msg[i] = toupper(msg[i]);
}
string key;
cout << "Enter key: ";
getline(cin, key);
cin.ignore();
//key to uppercase
for(int i = 0; i < key.length(); i++){
key[i] = toupper(key[i]);
}
//mapping key to message
string keyMap = "";
for (int i = 0,j = 0; i <msg.length();i++){
if(msg[i] ==32){
keyMap += 32;
} else {
if(j<key.length()){
keyMap += key[j];
j++;
} else {
j = 0;
keyMap += key[j];
j++;
}
} //if-else
} //for
message = msg;
mappedKey = keyMap;
}
int vTable[26][26];
void visibleTable(){
for (int i = 0; i < 26; i++){
for (int j = 0; j < 26; j++){
int temp;
if((i+65)+j > 90){
temp = ((i+65)+j) - 26;
vTable[i][j] = temp;
} else {
temp = (i+65)+j;
vTable[i][j] = temp;
}
}
}
for(int i = 0; i <26; i++){
for(int j = 0; j < 26; j++){
cout << (char)vTable[i][j] << " ";
}
cout << endl;
}
}
int tableArr[26][26];
void createVigenereTable(){
for (int i = 0; i < 26; i++){
for (int j = 0; j < 26; j++){
int temp;
if((i+65)+j > 90){
temp = ((i+65)+j) - 26;
tableArr[i][j] = temp;
} else {
temp = (i+65)+j;
tableArr[i][j] = temp;
}
}
}
}
void cipherEncryption(string message, string mappedKey){
createVigenereTable();
string encryptedText = "";
for(int i = 0; i < message.length(); i++){
if(message[i] == 32 && mappedKey[i] == 32){
encryptedText += " ";
} else {
int x = (int)message[i]-65;
int y = (int)mappedKey[i]-65;
encryptedText += (char)tableArr[x][y];
}
}
cout << "Encrypted Text: " << encryptedText;
cout << "\nRestart the program for more encryption or decryption.";
}
int itrCount(int key, int msg){
int counter = 0;
string result = "";
for(int i = 0; i < 26; i++){
if(key+i > 90){
result += (char)(key+(i-26));
} else {
result += (char)(key+i);
}
} //for
for(int i = 0; i < result.length(); i++){
if(result[i] == msg){
break;
} else {
counter++;
}
}
return counter;
}
void cipherDecryption(string message, string mappedKey){
string decryptedText = "";
for(int i = 0; i < message.length(); i++){
if(message[i] == 32 && mappedKey[i] == 32){
decryptedText += " ";
} else {
int temp = itrCount((int)mappedKey[i], (int)message[i]);
decryptedText += (char)(65+temp);
}
}
cout << "Decrypted Text: " << decryptedText;
cout << "Please restart the program for more encryption or decryption.";
}
int main()
{
int choice;
cout << "*****************************************************************************\n ";
cout << "This program encrypts or decrypts messages. \n Press 1 to encrypt, 2 to decrypt or 3 to see the table. \n When inputs are entered, press ENTER two times to procceed.";
cout << "*****************************************************************************\n";
cin >> choice;
cin.ignore();
if (choice == 1)
{
cout << "Encryption was chosen. \n" << endl;
messageAndKey();
cipherEncryption(message, mappedKey);
} else if (choice == 2)
{
cout << "Decryption was chosen. \n" << endl;
messageAndKey();
cipherDecryption(message, mappedKey);
}
else if (choice ==3 )
{
cout << "The table has been chosen. \n Please press 3 to confirm.";
cin >> choice;
if (choice == 3)
{
visibleTable();
}
}
else {
cout << "Wrong Choice. \n Please restart the program" << endl;
}
return 0;
}
The pseudo code for the program is given below.
In case of any query please contact me in comments.
// Pseudo code below
The following program lets you encrypt and decrypt using the key provided
1. function messageAndKey()
{
1.prompt user to input the message in message and
then covert the input message in uppercase and
then store it in message array letter by letter.
2.prompt user to input the key in key variable and
then covert the input key in uppercase and
then store it in key array letter by letter.
3.next step is to map key to message
Loop until one loop variable is less than
message.length()
inside loop
if letter of message array at index
i equal to 32
then add 32 to
keymap variable.
else
if second loop
variable j is less than key.length()
add key to keymap
else
make second variable j equal to 0 and add key to
key map
increment
j
increment i
end loop
4. Store message and mapped key i some variable
end
}
2.Create a 2-d array
3.function visibleTable()
{
loop till variable i less than 26
inner loop run till j less than
26
if i+65+j is
greater than 90
store i+65+j-26 in a temporary variable
else
store i+65+j in temporary variable
end if
store the value
of temporary variable in the 2-d array at i,j position.
end for
end for
print the 2-D array in form of matrix
loop till variable i less than 26
inner loop run till j less than
26
print 2-D array
value at i,j
end for
end for
end
}
4.Create a 2-d array
5. function createVigenereTable(){
loop till variable i less than 26
inner loop run till j less than
26
if i+65+j is
greater than 90
store i+65+j-26 in a temporary variable
else
store i+65+j in temporary variable
end if
store the value
of temporary variable in the new 2-d array at i,j position.
end for
end for
end
}
6. function cipherEncryption(argument one , argument two)
{
call function createVigenereTable()
loop till i is less than message.length()
if value of argument one at i is
equal to 32 and value of argument two at i is 32
add " " to
encrypted text variable.
else
store value of
argument one in variable x after subtracting 65
store value of
argument two in variable y after subtracting 65
add value of
second 2-D array at x,y to encrypted text.
end if
end for
print out the encrypted text.
end
}
6. function itrCount(argument one,argument two) to count number
of iterations.
{
loop till i is less than 26
if argument one + i is greater than
90
add argument one
+ i -26 to result variable
else
add argument one
+ i to result variable.
end if
end for
loop till i is less than result.length()
if value of result at i is equal to
argument two
then break
else
increment
counter variable
end if
end for
return counter variable
end
}
7.function cipherDecryption(argument one argument two){
loop till i is less than argument one length
if value of argument one at i is
equal to 32 and value of argument two at i is equal to 32
add " " to
decryptedText variable
else
call and store
function itrCount(for argument two at i, argument one at i) value
in temp variable
add 65 + temp
variable to decrypted text.
end if
end for
print the decrypted text
end
}
8.{In the main function
print out the menu where user can choose from various
options i.e. 1. for encrypt
2. for decrypt 3. to see table and
instructions to use.
take user choice
if user chooses 1 to encrypt
then call function
messageAndKey()
call function cipherEncryption()
with appropriate arguments
else
if user chooses option 2 to decrpypt
then call messageAndKey()
function
then call cipherDecryption()
function with appropriate arguments
else
if user chooses option 3
then prompt user to confirm
then if user confirms call
visibleTable() function
else
ask user to enter correct
choice
end if
end
}
Screenshots
Write a psuedocode for this program. #include <iostream> using namespace std; string message; string mappedKey; void...
#include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car { private: string reportingMark; int carNumber; string kind; bool loaded; string choice; string destination; public: Car() { reportingMark = ""; carNumber = 0; kind = "Others"; loaded = 0; destination = "NONE"; } ~Car() { } void setUpCar(string &reportingMark, int &carNumber, string &kind, bool &loaded, string &destination); }; void input(string &reportingMark, int &carNumber, string &kind, bool &loaded,string choice, string &destination); void output(string &reportingMark, int &carNumber,...
#include #include #include #include #include #include #include using namespace std; const int MAX = 26; string addRandomString(int n) { char alphabet[MAX] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; string res = ""; for (int i = 0; i < n; i++) res = res + alphabet[rand() % MAX]; return res;...
please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName(); double getNumberExams(); double getScoresAndCalculateTotal(double E); double calculateAverage(double n, double t); char determineLetterGrade(); void displayAverageGrade(); int main() { string StudentName; double NumberExam, Average, ScoresAndCalculateTotal; char LetterGrade; StudentName = getStudentName(); NumberExam = getNumberExams(); ScoresAndCalculateTotal= getScoresAndCalculateTotal(NumberExam); Average = calculateAverage(NumberExam, ScoresAndCalculateTotal); return 0; } string getStudentName() { string StudentName; cout << "\n\nEnter Student Name:"; getline(cin, StudentName); return StudentName; } double getNumberExams() { double NumberExam; cout << "\n\n Enter...
CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...
#include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; struct transition{ // transition structure char start_state, to_state; char symbol_read; }; void read_DFA(struct transition *t, char *f, int &final_states, int &transitions){ int i, j, count = 0; ifstream dfa_file; string line; stringstream ss; dfa_file.open("dfa.txt"); getline(dfa_file, line); // reading final states for(i = 0; i < line.length(); i++){ if(line[i] >= '0' && line[i] <= '9') f[count++] = line[i]; } final_states = count; // total number of final states // reading...
***************Fix code recursive function #include <iostream> #include <cctype> #include <string> using namespace std; void printUsageInfo(string executableName) { cout << "Usage: " << executableName << " [-c] [-s] string ... " << endl; cout << " -c: turn on case sensitivity" << endl; cout << " -s: turn off ignoring spaces" << endl; exit(1); //prints program usage message in case no strings were found at command line } string tolower(string str) { for(unsigned int i = 0; i < str.length(); i++)...
Write a cpp program Server.h #ifndef SERVER_H #define SERVER_H #include #include #include #include using namespace std; class Server { public: Server(); Server(string, int); ~Server(); string getPiece(int); private: string *ascii; mutex access; }; #endif -------------------------------------------------------------------------------------------------------------------------- Server.cpp #include "Server.h" #include #include Server::Server(){} Server::Server(string filename, int threads) { vector loaded; ascii = new string[threads]; ifstream in; string line; in.open(filename); if (!in.is_open()) { cout << "Could not open file...
Need help with the flow chart of this program #include #include using namespace std; string months[] = {"January","February ","March","April","May","June","July","August","September","October","November","December"}; int days_in_months[] = {31,28,31,30,31,30,31,31,30,31,30,31}; class Date //Sample Class for the C++ Tutorial { private: int month; //Data member int day; // Data member int year; public: Date(int m, int d, int y) { if(m<1 || m >12) month = 1; else month = m; if(d<1 || d >days_in_months[month-1]) day = 1; else day = d; if(y<2001) year = 2001; else year...
#include <fstream> #include <iostream> #include <cstdlib> using namespace std; // Place charcnt prototype (declaration) here int charcnt(string filename, char ch); int main() { string filename; char ch; int chant = 0; cout << "Enter the name of the input file: "; cin >> filename; cout << endl; cout << "Enter a character: "; cin.ignore(); // ignores newline left in stream after previous input statement cin.get(ch); cout << endl; chcnt = charcnt(filename, ch); cout << "# of " «< ch« "'S:...
fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct book { int ISBN; string Author; string Title; string publisher; int Quantity; double price; }; void choice1(book books[], int& size, int MAX_SIZE) { ifstream inFile; inFile.open("inventory.txt"); if (inFile.fail()) cout <<"file could not open"<<endl; string str; while(inFile && size < MAX_SIZE) { getline(inFile, str); books[size].ISBN = atoi(str.c_str()); getline(inFile, books[size].Title); getline(inFile, books[size].Author); getline(inFile, books[size].publisher); getline(inFile,...