Question: Hello, I am trying to program in C++ and I am unable to get my both my void display function to work properly. Correct outcome

Hello,

I am trying to program in C++ and I am unable to get my both my void display function to work properly.

Correct outcome should be:

Original Data: 0 1 0 0

Encrypted Data : 7778

Here are the source code:

//Encrypt.cpp

#pragma once #include #include "Encrypt.h" //include definition of class Encrypt using namespace std;

Encrypt::Encrypt(int num) { int arrE[8] = {};

cout << "** The default constructor is called"; cout << " and the passed in number is " << num << ".** " << endl; if (num <= 0) { num = 9436; arrE[4] = ((num / 1000)) % 10; arrE[5] = ((num / 100)) % 10; arrE[6] = ((num / 10)) % 10; arrE[7] = (num % 10) % 10; cout << " XXX The inputed number is less than or equal to 0." << " The number is reset to 9436. XXXXX" << endl; cout << " The original data is: " << arrE[4] << " " << arrE[5] << " " << arrE[6] << " " << arrE[7] << "." << endl; } else if (num > 9999999) { int i; for (i = 0; num >= 9999; i++) { num /= 10; } arrE[4] = ((num / 1000)) % 10; arrE[5] = ((num / 100)) % 10; arrE[6] = ((num / 10)) % 10; arrE[7] = (num % 10) % 10; cout << " The original data is: " << arrE[4] << " " << arrE[5] << " " << arrE[6] << " " << arrE[7] << "." << endl;

} else if (num > 9999) { arrE[4] = ((num / 1000)) % 10; arrE[5] = ((num / 100)) % 10; arrE[6] = ((num / 10)) % 10; arrE[7] = (num % 10) % 10; num = arrE[4] * 1000 + arrE[5] * 100 + arrE[6] * 10 + arrE[7]; cout << " The original data is: " << arrE[4] << " " << arrE[5] << " " << arrE[6] << " " << arrE[7] << "." << endl; } else { arrE[4] = ((num / 1000)) % 10; arrE[5] = ((num / 100)) % 10; arrE[6] = ((num / 10)) % 10; arrE[7] = (num % 10) % 10;

cout << " The original data is: " << arrE[4] << " " << arrE[5] << " " << arrE[6] << " " << arrE[7] << "." << endl; } arrE[0] = ((num / 1000) % 10 + 7) % 10; arrE[1] = ((num / 100) % 10 + 7) % 10; arrE[2] = ((num / 10) % 10 + 7) % 10; arrE[3] = (num % 10 + 7) % 10;

num = arrE[2] * 1000 + arrE[3] * 100 + arrE[0] * 10 + arrE[1]; cout << " The encrypted data is: " << arrE[2] << " " << arrE[3] << " " << arrE[0] << " " << arrE[1] << "." << endl << endl; }

int Encrypt::storeData(int num) {

int arrE[8] = {}; if (num <= 0) { num = 9436; arrE[4] = ((num / 1000)) % 10; arrE[5] = ((num / 100)) % 10; arrE[6] = ((num / 10)) % 10; arrE[7] = (num % 10) % 10; cout << " XXX The inputed number is less than or equal to 0." << " The number is reset to 9436. XXXXX" << endl; cout << " The original data is: " << arrE[4] << " " << arrE[5] << " " << arrE[6] << " " << arrE[7] << "." << endl; } else if (num > 9999999) { int i; for (i = 0; num >= 9999; i++) { num /= 10; } arrE[4] = ((num / 1000)) % 10; arrE[5] = ((num / 100)) % 10; arrE[6] = ((num / 10)) % 10; arrE[7] = (num % 10) % 10; cout << " The original data is: " << arrE[4] << " " << arrE[5] << " " << arrE[6] << " " << arrE[7] << "." << endl;

} else if (num > 9999) { arrE[4] = ((num / 1000)) % 10; arrE[5] = ((num / 100)) % 10; arrE[6] = ((num / 10)) % 10; arrE[7] = (num % 10) % 10; num = arrE[4] * 1000 + arrE[5] * 100 + arrE[6] * 10 + arrE[7]; cout << " The original data is: " << arrE[4] << " " << arrE[5] << " " << arrE[6] << " " << arrE[7] << "." << endl; } else { arrE[4] = ((num / 1000)) % 10; arrE[5] = ((num / 100)) % 10; arrE[6] = ((num / 10)) % 10; arrE[7] = (num % 10) % 10; num = arrE[4] * 1000 + arrE[5] * 100 + arrE[6] * 10 + arrE[7]; }

return num; }

void Encrypt::displayEncryptedData() { cout << " The encrypted data is: " << arrE[4] << " " << arrE[5] << " " << arrE[6] << " " << arrE[7] << "." << endl; } int Encrypt::getEncryptedData(int num) { int arrE[8] = {};

arrE[0] = ((num / 1000) % 10 + 7) % 10; arrE[1] = ((num / 100) % 10 + 7) % 10; arrE[2] = ((num / 10) % 10 + 7) % 10; arrE[3] = (num % 10 + 7) % 10;

num = arrE[2] * 1000 + arrE[3] * 100 + arrE[0] * 10 + arrE[1];

return num; }

void Encrypt::displayOriginalData( ) { cout << " The original data is: " << arrE[2] << " " << arrE[3] << " " << arrE[0] << " " << arrE[1] << "." << endl; }

//Encrypt_h #include #ifndef Encrypt_h #define Encrypt_h

using namespace std;

class Encrypt { private: int num; int arrE[8] = {};

public:

Encrypt(int); void displayOriginalData();//display original input int storeData(int); // calculate and store encryption void displayEncryptedData(); // display encryption int getEncryptedData(int);

};

#endif #pragma once

And here is the test code that must NOT be changed.

// CISP400V10A2.cpp // Test program for class Encrypt. #include #include using namespace std;

int main() { Encrypt app1(0), app2(40), app3(4560), app4(6145698), app5(-6); // create Encrypt objects

cout << endl << "Reset the app1's data to 100." << endl;// display the reset of app1.

app1.storeData(100);// call app1's storeData function app1.displayOriginalData();//display the app1's current original data. app1.displayEncryptedData();// display the app1's current encrypted data. cout << endl;//Jump to the next line system("PAUSE"); return 0; // indicate successful termination } // end main

Thank you,

dl

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!