This is my final study guide and the professor never posted an answer key. So It
ID: 3721662 • Letter: T
Question
This is my final study guide and the professor never posted an answer key. So It would really help for me to have something to study with the correct answers thank you. okay i re posted the pictures there are 16. i can see them on pc and app.
CS 202-Computer Science II Finals Sample Release date: Monday, 4/30/2018 Test Objectives: A comprehensive evaluation of the course material. Everywhere, the use of pointers, bracket-notation, and the built-in C-string library functions are allowed Program 1 (60 pts): You are given the working definitions and implementations of two Classes (description-only shown here): elass publie //Cover() default con?tructor. ?.t..bar te f.1.. //Cover (bool hard) paru.triaed eonatrueter. "te hard to hard /foperatoree overload, outpute hard te the ealling object (cout.ete) //operator >> overload. assign.. har.. 0/1 value tro. calling object input (c?n,etc.) //GetValue O Bethod. returna hard by value "nd doea not B0?? fy ealling object private bool hardi clase client( publies /cilent 0 default construetor.leavessane uiaitialised Client (conet char ae) parametrised construetor, copies e-string nane to nae //cilent (const Clientsother) copy conatructor, deep-copiea data //-Client() destruetor, deallocate. Booey aa 2.0eessary //operator overload. deep-copies dat. "ad turu "teresce to calling object //operatorec overload. outputeae to the callisg objectleout.ate /loperstorx overload, grabe and copies to a npat frm calling object(cin,eto //GetNaa*()?thed· returna anaa. by addrea. sad does not sodity calling object pelvates )a (Part1 Grading Scheme: 20pts, 10pts Class Declaration-10pts Class Implementation) (Hint: A smaller subset of such specifications will be required for the actual Finals) For the first part of this program you are required to implement a Book class, which will has to adhere by these specifications char nane Each Book should have the members (all privatc) m title: a Cestring (pointer not array) representing the book tidle. . mcover: a Cover class ebicct which represents the book cover . mclient: a Client class const pointct, the person (renter) who currently has the book in their possession. If the book is not rented out to somcone this pointer should be NULI Hint: Remember const pointer means the m_client variable can be assigned to pointed to different objects, but it cannot be used to modify the object it points to). . m serial: a constant size t number, representing a unique identifier for each Book object and the Book class will also have a (private as well): e count a static size_t, keeping track of the last (greatest unique Book id (as generated via aExplanation / Answer
#include <string>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <netdb.h>
#include <stdlib.h>
#include <strings.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <netinet/ip.h>
using namespace std;
#ifndef MYSOCKET
#define MYSOCKET
const int MAXHOSTNAME=255;
class MyConnection //represents the communication connection between child process and client
{
private:
int connectionFD;
public:
MyConnection(); //print error, exit(-1); must construct with fd
MyConnection(int fd); //MyConnection is just a wrapper for the fd to allow overloading << and >>
int read(string&); //return bytes read, -1 on error; will be used in >>
int write(const string&); //return bytes written, -1 on error; will be used in <<
void close(); //close the connection
};
class MySocket
{
private:
struct sockaddr_in sock;
int socketFD;
int portNumber;
public:
MySocket(); //print error, exit(-1); must construct with port #
MySocket(int portNumber); //creates the server listening socket
//must implement =, copy, destructor
MySocket& operator=(MySocket&);
MySocket(const MySocket&);
~MySocket();
int listen(); //call once to start listening
MyConnection accept(); //call repeatedly when connecting to client; returns client stream
void close();
};
MyConnection& operator<<(MyConnection&, const string&);
MyConnection& operator>>(MyConnection&, string&);
#endif
MySocket.cpp
#include "MySocket.h"
#include <iostream>
using namespace std;
MySocket::MySocket(){exit(-1);}
MySocket::MySocket(int p):portNumber(p){}
MyConnection::MyConnection(){exit(-1);}
MyConnection::MyConnection(int fd):connectionFD(fd){}
MySocket& MySocket::operator=(MySocket& m){return m;}
MySocket::MySocket(const MySocket&){}
MySocket::~MySocket(){}
int MyConnection::read(string& s){return 0;}
int MyConnection::write(const string& s){return 0;}
int MySocket::listen(){return 0;}
MyConnection MySocket::accept(){return 0;}
void MySocket::close(){}
void MyConnection::close(){}
MyConnection& operator<<(MyConnection& me, const string& s){return me;}
MyConnection& operator>>(MyConnection& me, string& s){return me;}
server2.cpp
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <netdb.h>
#include <netinet/in.h>
#include "MySocket.h"
#include <string.h>
#include <iostream>
using namespace std;
void doprocessing (MyConnection& c);
int main( int argc, char *argv[] ) {
int pid;
MySocket m(19999);
m.listen();
while (1) {
MyConnection c = m.accept();
/* Create child process */
pid = fork();
if (pid < 0) {
perror("ERROR on fork");
exit(1);
}
if (pid == 0) {
/* This is the client process */
m.close();
doprocessing(c);
exit(0);
}
else {
c.close();
}
} /* end of while */
}
void doprocessing (MyConnection& c) {
int n;
string inS;
while (true)
{
c >> inS;
cout << "Here is the message: " << inS << " ";
c << "I got your message: " << inS << " ";
}
if (inS.length() == 0) exit(0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.