Question: The program below encodes a number using the formula below with a secret key: encoded number = ( original number + key ) x 5

The program below encodes a number using the formula below with a secret key:
encoded number =(original number + key) x 5
#include
using namespace std;
// Your code for A2 should be inserted here
int main(){
Encoder eKey(123);
int encodedValue, decodedValue;
int value =31;
cout << "original value: "<< value << endl;
encodedValue = eKey.encode(value);
cout << "encoded value: "<< encodedValue << endl;
decodedValue = eKey.decode(encodedValue);
cout << "decoded value: "<< decodedValue << endl;
return 0;
}
Sample output:
original value: 31
encoded value: 770
decoded value: 31
Implement the Encoder class with the following:
(a) The class scope with appropriate access specifier labels. (2 marks)
(b) A private data member key (integer).(2 marks)
(c) A default constructor that initializes the value of key to 3.(4 marks)
(d) A constructor with ONE parameter, that initializes the value of key with the argument.
(4 marks)
(e) A public member function encode() that takes a number (integer) as parameter, and returns
the encoded number (integer) using formula above with the key value. (4 marks)
(f) A public member function decode() that takes a number (integer) as parameter, and returns
the decoded number (integer) using the key value. (4 marks)

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!