Question: Write a pseudocode for the following c++ program #include #include #include #include #define MAX 200 using namespace std; // Read in the data from file
Write a pseudocode for the following c++ program
#include
// Read in the data from file and stores it in data character array int readFile(char data[], string fileName) { // Counter for number of characters in the file int counter = 0; // File stream object declared ifstream fRead; // Open the file InputFile.txt for reading fRead.open(fileName.c_str()); // Check that file can be opened or not // is_open() function returns true if a file is open and associated with this stream object. // Otherwise returns false. if(!fRead.is_open()) { // Displays error message cout<<" Error: Unable to open the file!"< // Loops till not end of the file // eof() function returns true if the stream's eofbit error state flag is set (which signals that the End-of-File has been reached // by the last input operation). Otherwise returns false. while(!fRead.eof()) { // Reads each character from file and stores it in character array data and increase the counter value by one fRead>>data[counter++]; }// End of while condition // Close the file fRead.close(); // Returns number of characters return counter; }// End of function // Function to display the contents void display(char data[], int len) { // Loops till length of the array for(int c = 0; c < len; c++) cout<>key; // Loops till the length of the original array data while(c < len) { // Write the encrypted data to file outFile<<(char)(data[c]^key); // Stores the encrypted data to character array enc enc[c] = (char)(data[c]^key); // Increase the counter by one c++; }// End of while loop }// End of function // Function to decrypt the array contents and store the result in character array dec void decrypt(char enc[], char dec[], int len, string fileName) { // ofstream class object created ofstream outFile; //Opens the file for writing onto a text file outFile.open(fileName.c_str()); int c = 0; char key; // Accepts the key cout<<" Enter the key character: "; cin>>key; // Loops till the end of encrypted array enc while(c < len) { // Write the decrypted data to file outFile<<(char)(enc[c]^key)< cout<<" Original file contents: "; // Calls the function to display file contents display(data, len); // Calls the function to encrypt data and store it in file and character array enc encrypt(data, enc, len, "enc.txt"); cout<<" After encryption: "; // Calls the function to display file contents display(enc,len); // Calls the function to read the contents of file and store the encrypted data in character array enc len = readFile(enc, "enc.txt"); // Calls the function to decrypt data and store it in file and character array dec decrypt(enc, dec, len, "dec.txt"); cout<<" After decryption: "; // Calls the function to display file contents display(dec,len); }// End of function
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
