In: Computer Science
1. Write pseudocode for the following program. You do not have
to write actual C++ code.
Assume you have a text file, that has been encrypted by adding 10
to the ASCII value of each character in the message. Design a
decryption program that would reverse this process, and display the
original message to the console.to the new array.
2.Write the code for the specified program. Use proper style and
naming. Test and upload your code as a CPP file.
Write a program that keeps track of a speakers’ bureau. The program
should use a structure to store the following data about a speaker:
Name and Fee Required.
The program should use an array of at least 10 structures. It
should let the user enter data into the array, and then display the
lowest fee of any of the speakers. Use a modular design for your
program (separate functions for input and processing).
#include <iostream>
using namespace std;
//constructing speaker using structure
struct speaker{
string name;
double fee;
};
//to take the speaker name and fee from user and store them in array arr
void takeInput(struct speaker arr[],int size){
string name;
double fee;
for(int i=0;i<size;i++){
cout<<"Please enter the name of speaker :"<<endl;
cin>>name;
arr[i].name=name;
cout<<"Please enter the fee of speaker :"<<endl;
cin>>fee;
arr[i].fee=fee;
}
}
//main
int main(){
int min;
//creating array of structure
struct speaker arr[10];
//calling takeInput() to take input
takeInput(arr,10);
//assigning the first speaker fee in min variable
min=arr[0].fee;
cout<<"Finding the speaker having the lowest fee..."<<endl;
//finding the lowest fee of any of the speakers
for(int i=1;i<10;i++){
if(arr[i].fee<min){
min=arr[i].fee;
}
}
//printing the lowest fee
cout<<"The lowest fee of any of the speakers is "<<min;
}
This is a C++ code that keeps track of a speakers’ bureau.
Sample Input and output:
Please enter the name of speaker :
John
Please enter the fee of speaker :
120
Please enter the name of speaker :
James
Please enter the fee of speaker :
140
Please enter the name of speaker :
Rob
Please enter the fee of speaker :
130
Please enter the name of speaker :
Ronald
Please enter the fee of speaker :
150
Please enter the name of speaker :
Beakley
Please enter the fee of speaker :
65
Please enter the name of speaker :
Jeff
Please enter the fee of speaker :
210
Please enter the name of speaker :
Robin
Please enter the fee of speaker :
170
Please enter the name of speaker :
Mett
Please enter the fee of speaker :
190
Please enter the name of speaker :
Dennis
Please enter the fee of speaker :
200
Please enter the name of speaker :
Rey
Please enter the fee of speaker :
250
Finding the speaker having the lowest fee...
The lowest fee of any of the speakers is 65
Code screenshots:
Code Output:
Pseudocode of problem #1
Pseudocode explainations:
Here we just read each characters from the text file one by one and have updated it's ASCII value as
'ch' = 'ch' - 10
As we are doing decryption which is just a reverse process of encryptoin in which we have encrypted the textFile character of message by adding 10 to the ASCII value of each character of message.
Here in decrption we have to decrement 10 from the ASCII value of each character in the message of textFile so that we will obtain the original message.
for example let's have the message in textFile as :
HELLO.
Here characters are : {H,E,L,L,O}
ASCII Values are:
H - 72
E - 69
L - 76
L - 76
0 - 79
Now after applying encryption the message will become:
H - 72 + 10 = 82 = R
E - 69 + 10 = 79 = O
L - 76 + 10 = 86 = V
L - 76 + 10 = 86 = V
0 - 79 + 10 = 89 = Y
=>ROVVY
Now we will apply our decryption on ROVVY as:
R - 82-10=>72 - H
O - 79-10=>69 - E
V - 86-10=>76 - L
V - 86-10=>76 - L
Y - 89-10=>79 - O
So in this way our decryption function will work...