Question
Hello, Please message for rest of the code. Chegg has determine that the post is too long. My c++ program isn't producing the correct result.
Hello,
Please message for rest of the code. Chegg has determine that the post is too long.
My c++ program isn't producing the correct result. The least few output isn't computing properly. Please help me fix my code so that last few lines will look like the following:
$$$$Use eapp3 and dapp3 to test the program.$$$$
Call eapp3 to display its data.
The original data is: 4 5 6 0. The encrypted data is: 3 7 1 2.
Get encrypted data from eapp3 and use the data on the dapp3 to test program.
The original data is: 1743. The decrypted data is: 7640.
The original data is: 1 7 4 3. The encrypted data is: 0 4 6 7.
$$$$Use eapp6 and dapp6 to test the program.$$$$
Call dapp6 to display its data.
The original data is: 0 0 0 0. The encrypted data is: 0 0 0 0.
Get decrypted data from dapp6 and use the data on the eapp6 to test program.
The original data is: 7 8 9 0. The encrypted data is: 6 7 4 5.
Here are my codes. The only one that can NOT be changed is the test file cpp.
//DECRYPT.h
#include #include #ifndef Decrypt_h #define Decrypt_h
using namespace std;
class Decrypt { private: int num; int arrD[8] = {};
public:
Decrypt(int); Decrypt(int arr[]); void displayOriginalData();//display original input int storeData(int); // calculate and store encryption void displayDecryptedData(); // display encryption int getDecryptedData();
};
#endif
//DECRYPT.cpp
#include #include "Decrypt.h" //include definition of class Encrypt using namespace std;
Decrypt::Decrypt(int num) //Decrypt constructor called {
int arrD[8] = {}; cout << "*D* The Decrypt constructor is called"; cout << " and the passed in number is " << num << ".** " << endl;
if (num <= 0) { num = 1234; arrD[4] = ((num / 1000)) % 10; arrD[5] = ((num / 100)) % 10; arrD[6] = ((num / 10)) % 10; arrD[7] = (num % 10) % 10; cout << " XXXXX The inputed number is less than or equal to 0." << " The number is reset to 1234. XXXXX" << endl; cout << " The original data is: " << arrD[4] << " " << arrD[5] << " " << arrD[6] << " " << arrD[7] << "." << endl; } else if (num > 9999999) { for (int i = 0; num > 9999; i++) { num /= 10; } arrD[4] = ((num / 1000)) % 10; arrD[5] = ((num / 100)) % 10; arrD[6] = ((num / 10)) % 10; arrD[7] = (num % 10) % 10; cout << " The original data is: " << arrD[4] << " " << arrD[5] << " " << arrD[6] << " " << arrD[7] << "." << endl;
} else if (num > 9999) { arrD[4] = ((num / 1000)) % 10; arrD[5] = ((num / 100)) % 10; arrD[6] = ((num / 10)) % 10; arrD[7] = (num % 10) % 10; num = arrD[4] * 1000 + arrD[5] * 100 + arrD[6] * 10 + arrD[7]; cout << " The original data is: " << arrD[4] << " " << arrD[5] << " " << arrD[6] << " " << arrD[7] << "." << endl; } else { arrD[4] = ((num / 1000)) % 10; arrD[5] = ((num / 100)) % 10; arrD[6] = ((num / 10)) % 10; arrD[7] = (num % 10) % 10; cout << " The original data is: " << arrD[4] << arrD[5] << arrD[6] << arrD[7] << "." << endl; }
arrD[0] = (num % 10 + 3) % 10; arrD[1] = ((num / 10) % 10 + 3) % 10; arrD[2] = ((num / 100) % 10 + 3) % 10; arrD[3] = (num / 1000 + 3) % 10;
num = arrD[1] * 1000 + arrD[0] * 100 + arrD[3] * 10 + arrD[2];
cout << " The decrypted data is: " << num << "." << endl << endl; }
Decrypt::Decrypt(int arr[]) //Decrypt constructor called {
int arrD[8] = {}; cout << "*D* The Decrypt constructor is called"; cout << " and the passed in number is " << num << ".** " << endl;
if (num <= 0) { num = 1234; arrD[4] = ((num / 1000)) % 10; arrD[5] = ((num / 100)) % 10; arrD[6] = ((num / 10)) % 10; arrD[7] = (num % 10) % 10; cout << " XXXXX The inputed number is less than or equal to 0." << " The number is reset to 1234. XXXXX" << endl; cout << " The original data is: " << arrD[4] << " " << arrD[5] << " " << arrD[6] << " " << arrD[7] << "." << endl; } else if (num > 9999999) { for (int i = 0; num > 9999; i++) { num /= 10; } arrD[4] = ((num / 1000)) % 10; arrD[5] = ((num / 100)) % 10; arrD[6] = ((num / 10)) % 10; arrD[7] = (num % 10) % 10; cout << " The original data is: " << arrD[4] << " " << arrD[5] << " " << arrD[6] << " " << arrD[7] << "." << endl;
} else if (num > 9999) { arrD[4] = ((num / 1000)) % 10; arrD[5] = ((num / 100)) % 10; arrD[6] = ((num / 10)) % 10; arrD[7] = (num % 10) % 10; num = arrD[4] * 1000 + arrD[5] * 100 + arrD[6] * 10 + arrD[7]; cout << " The original data is: " << arrD[4] << " " << arrD[5] << " " << arrD[6] << " " << arrD[7] << "." << endl; } else { arrD[4] = ((num / 1000)) % 10; arrD[5] = ((num / 100)) % 10; arrD[6] = ((num / 10)) % 10; arrD[7] = (num % 10) % 10; cout << " The original data is: " << arrD[4] << arrD[5] << arrD[6] << arrD[7] << "." << endl; }
arrD[0] = (num % 10 + 3) % 10; arrD[1] = ((num / 10) % 10 + 3) % 10; arrD[2] = ((num / 100) % 10 + 3) % 10; arrD[3] = (num / 1000 + 3) % 10;
num = arrD[1] * 1000 + arrD[0] * 100 + arrD[3] * 10 + arrD[2];
cout << " The decrypted data is: " << num << "." << endl << endl;
}
int Decrypt::getDecryptedData() { arrD[0] = (num % 10 + 3) % 10; arrD[1] = ((num / 10) % 10 + 3) % 10; arrD[2] = ((num / 100) % 10 + 3) % 10; arrD[3] = (num / 1000 + 3) % 10;
num = arrD[1] * 1000 + arrD[0] * 100 + arrD[3] * 10 + arrD[2]; return num; }
int Decrypt::storeData(int n) { this->num = n; // copying data - key part that I was missning. Had help and was shown "this->" to make code work. Everything else is original. if (num <= 0) { num = 1234; arrD[4] = ((num / 1000)) % 10; arrD[5] = ((num / 100)) % 10; arrD[6] = ((num / 10)) % 10; arrD[7] = (num % 10) % 10; cout << " XXXXX The inputed number is less than or equal to 0." << " The number is reset to 1234. XXXXX" << endl; cout << " The original data is: " << arrD[4] << " " << arrD[5] << " " << arrD[6] << " " << arrD[7] << "." << endl; } else if (num > 9999999) { for (int i = 0; num > 9999; i++) { num /= 10; } arrD[4] = ((num / 1000)) % 10; arrD[5] = ((num / 100)) % 10; arrD[6] = ((num / 10)) % 10; arrD[7] = (num % 10) % 10; cout << " The original data is: " << arrD[4] << " " << arrD[5] << " " << arrD[6] << " " << arrD[7] << "." << endl;
} else if (num > 9999) { arrD[4] = ((num / 1000)) % 10; arrD[5] = ((num / 100)) % 10; arrD[6] = ((num / 10)) % 10; arrD[7] = (num % 10) % 10; num = arrD[4] * 1000 + arrD[5] * 100 + arrD[6] * 10 + arrD[7]; cout << " The original data is: " << arrD[4] << " " << arrD[5] << " " << arrD[6] << " " << arrD[7] << "." << endl; } else { arrD[4] = ((num / 1000)) % 10; arrD[5] = ((num / 100)) % 10; arrD[6] = ((num / 10)) % 10; arrD[7] = (num % 10) % 10; cout << " The original data is: " << arrD[4] << arrD[5] << arrD[6] << arrD[7] << "." << endl; }
arrD[0] = (num % 10 + 3) % 10; arrD[1] = ((num / 10) % 10 + 3) % 10; arrD[2] = ((num / 100) % 10 + 3) % 10; arrD[3] = (num / 1000 + 3) % 10;
num = arrD[1] * 1000 + arrD[0] * 100 + arrD[3] * 10 + arrD[2];
cout << " The decrypted data is: " << num << "." << endl << endl; return num; }
void Decrypt::displayDecryptedData() {
cout << " The encrypted data is: " << arrD[2] << " " << arrD[3] << " " << arrD[0] << " " << arrD[1] << "." << endl; }
void Decrypt::displayOriginalData() //displaying result { cout << " The original data is: " << arrD[4] << " " << arrD[5] << " " << arrD[6] << " " << arrD[7] << "." << endl; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started