Question: C++ HW5 - Inheritance & Polymorphism -- PLEASE MAKE SURE YOU COMMENT ON YOUR CODE SO I CAN ALSO LEARN FROM IT. SPECIAL EMPHASIS ON

C++ HW5 - Inheritance & Polymorphism -- PLEASE MAKE SURE YOU COMMENT ON YOUR CODE SO I CAN ALSO LEARN FROM IT.

SPECIAL EMPHASIS ON THE TWO UTILITY FILES BECAUSE THAT'S WHERE I AM STUCK. Thanks!

Objective: The purpose of this assignment is for students to gain a better understanding of C++ inheritance and polymorphism mechanics.

Please note: you will find sample int main() and input files for first five test cases in Blackboard( Homework/Homework5).

Description

This homework will simulate encrypted communication between two clients, who are connected via a server. There will be five classes required in total. This means you will need to turn in 11 files server.h, server.cpp, client.h, client.cpp, messageServer.h, messageServer.cpp, encodedServer.h, encodedServer.cpp,utility.h,utility.cpp, main.cpp.

Class Description's:

Server Class

 Abstract Class  Protected: o Pointer sender of type Client o Pointer receiver of type Client  Public: o Pure virtual function establishConnection() o Pure virtual function sendMessage() o swapClients()  This function should be defined within the server.cpp file

Client Class

 Private: o Attribute  id  of type int o Attribute  message  of type string o Attribute  possesKey  of type bool o Attribute  key[26] of type char  For the purpose of ease,the key will be static for your assignment  key [26]={'B','A','D','C','F','E','H','G','J','I','L','K','N','M','P','O','R','Q','T','S','V','U','X','W','Z','Y'}; This will create the key in Client and translates to A = B, B = A, D = C and C = D and continue with this pattern. This means that position 0 equals A, 1 = B, 2 = C.  Public: o Parameterized Constructor that takes an int as an argument  The passed int will set the id attribute o Mutators  getID  Will return the value of id  setID  Will set the value of id  getMessage  Will return the value of message  setMessage  Will set the value of message  setPossesKey  Will set if the client has access to the key o decode()  This function will be called from the getMessage mutator and will check if the possesKey is true,and if it is,decodes the message. 

MessageServer Class -> Inherits from Server

 Public: o Default Constructor  Pointers will not point to anything yet o Implement establishConnections()  Accepts 2 arguments, the pointers for sender and receiver. This function should then set the pointers accordingly. o Implement sendMessage()  Accepts one argument, the string to be sent. 

EncodedServer Class -> Inherits from Server

 Private: o char key [26]={'B','A','D','C','F','E','H','G','J','I','L','K','N','M','P','O','R','Q','T','S','V','U','X','W','Z','Y'}; This key is the same as the key in client for coding and decoding messages.  Public: o Default Constructor  Pointers will not point to anything yet o Implement establishConnections()  Accepts 2 arguments- the pointers for sender and receiver. This function should then set the pointers accordingly. o Implement sendMessage()  Accepts one argument- the string to be sent.  Will call encodeMessage to change the originally passed message. o encodeMessage ()  Returns type string and accepts a single argument of type string. 

Utility class

Private: o ifstream myfile; // to read the input file o string outputFile=""; //to store the output stores all communication messages between the two clients separated by a comma. o string input[100]; // to read every line from file in this array input o int number_of_lines ; // contains total number of line in the file Public o encodedConnection(Client , Client , encodedServer , string ); this function performs encoded communication between two clients If the connection is encoded, you should ask client 1 if client 2 should have access to key, and then ask client 2 if client 1 should have access to the key. You should accept messages from the clients until someone enters a "*" without the quotes. All messages should be entered in all capital letters After the message has been sent to the other client it should be retrieved from the client via a mutator and appended to an string outputFile with the client who sent the message and then the message. This string(outputFile) is returned back to int main() function. o standardConnection(Client , Client , messageServer , string); this function performs standard non encoding communication between two clients You should accept messages from the clients until someone enters a "*" without the quotes. All messages should be entered in all capital letters After the message has been sent to the other client it should be retrieved from the client via a mutator and appended to an string outputFile with the client who sent the message and then the message. This string(outputFile) is returned back to int main() function. o string * readInputFromFile(string fileName);  reads input from the file and stores it as a array of strings.  returns the array of string, containing the contents of file inputted. o string outputString();  returns the string containing all messages exchanged between two clients. 

Main function:

 Create two Client Objects o Client1 o Client2  Create 1 messageSever and 1 encodedServer  Read the file name from Zybook prompt. The file contains all your inputs.  The inputs are stored in a file. o The input file is read by the readInputFromFile() defined in utility class  Ask if the two clients would like a connection o If and only if both clients respond yes will the connection be created  If the connection is to be created, ask if the messages should be encoded.  If response if 'Y' or 'y' messages would be encoded,  for any response other then Y or y, messages would not be encoded. o If one or both of the clients enter no, then the output should contain No connection made. without the quotes  You should accept messages from the clients until someone enters a "*" without the quotes.  All messages should be entered in all capital letters (test cases will have all capital letter input, this information is for your own testing)  printOutput = utilityObj.outputString();  print the "printOutput" to the terminal 

INPUT and Output - Input will be stored in a file. Output will be printed to the zybook terminal.

Sample input file description for encoded communication:

y -> y or Y indicates client 1 agrees to communicate y -> y or Y indicates client 2 agrees to communicate y -> y or Y indicate encoded communication y -> Client 1 agrees to share key with Client 2 y -> Client 2 agrees to share key with Client 1 TP -> message send from Client 1 to Client 2 LONG -> message send from Client 2 to Client 1 RED GREEN -> message send from Client 1 to Client 2 WHITE IS -> message send from Client 2 to Client 1 * -> Client1 wants to terminate communication 

Sample input file description for non encoded standard communication:

y -> y or Y indicates client 1 agrees to communicate y -> y or Y indicates client 2 agrees to communicate n -> indicates standard non encoded communication TP -> message send from Client 1 to Client 2 LONG -> message send from Client 2 to Client 1 RED GREEN -> message send from Client 1 to Client 2 * -> Client2 terminates communication 

Sample Input file 1 contents: Encoded communication

y y y y y TP LONG BMC THANKS * 

Output for the above input

Client1:TP, Client2:LONG, Client1:BMC, Client2:THANKS 

Sample Input file 2 contents: Non Encoded communication

y y n TP LONG SHORT LONG MAM GAME BALL BMC STOPS NO STOP PLEASE * 

Output for the above input

Client1:TP LONG SHORT, Client2:LONG MAM GAME BALL, Client1:BMC STOPS, Client2:NO STOP PLEASE 

Sample Input file contents for a encoded communication

y y y y n TP LONG BMC THANKS * 

Expected Output

Client1:TP, Client2:KPMH, Client1:BMC, Client2:SGBMLT 

Sample Input file contents for non encoded standard communication

y y n INHARITANCE POLYMORPHISM NO INHARITANCE NO POLYMORPHISM * 

Expected Output

Client1:INHARITANCE, Client2:POLYMORPHISM, Client1:NO INHARITANCE, Client2:NO POLYMORPHISM 

Please Note:

The code that does not compile or gets stuck in an infinite loop will receive ZERO points.

Your code will be graded based on test cases (5 test cases available plus 5 more test cases hidden from students) provided in zybooks

Late Homework Submission Penalty:

Code submitted late by 24 hours (by Thursday 11:59 pm) with receive 20% penalty

Code submitted late by 48 hours (by Friday 11:59 pm) with receive 40% penalty

Sample Main class:

#include  #include  #include "server.h" #include "client.h" #include "messageServer.h" #include "encodedServer.h" #include "utility.h" using namespace std; int main() { Client Client1(1), Client2(2); messageServer server1; encodedServer server2; utility utilityObj; string input1 = "", input2 = "", userChoice = ""; string printOutput; string fileName; cin >> fileName; /* fileContents - pointer to array of string. Stores the contents of the entire input file. */ string * fileContents = utilityObj.readInputFromFile(fileName); string * tracker = fileContents; input1 = fileContents[0]; tracker++; input2 = fileContents[1]; tracker++; if ((input1 == "y" || input1 == "Y") && (input2 == "y" || input2 == "Y")) { userChoice = fileContents[2]; tracker++; if (userChoice == "y" || userChoice == "Y") //use encoded server { utilityObj.encodedConnection(Client1, Client2, server2, tracker); } else // use normal messageServer { utilityObj.standardConnection(Client1, Client2, server1, tracker); } } //if ends else { printOutput = "No connection made."; cout< 

Compile command: g++ main.cpp client.cpp encodedServer.cpp messageServer.cpp server.cpp utility.cpp -Wall -Wextra -Wuninitialized -o a.out

Thanks!

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!