Homework Solution: Create a program that reads in attendees' information, and create an e…

    Create a program that reads in attendees' information, and create an event seating with a number of rows and columns specified by a user. Then it will attempt to assign each attendee to a seat in at the event. Using C++ Programming only. Create a class Attendee. Create attendee.cpp and attendee.h files. It should contain two variables, lastName (char [30]) and firstName (char [30]). Both should be private. In addition, the following functions should be defined. All of them are public
    Method Description
    Attendee ( ) Constructs a Attendee object by assigning the default string " XXX " to both instance variables, firstName and lastName.
    Attendee (char* attendeeInfo) Constructs a Attendee object using the string containing attendee's info. Use the strtokfunction to extract first name and last name, then assign them to each instance variable of the Attendee class. An example of the input string is: Charlie/Brown
    char* getFirstName ( ) It should return the instance variable firstName.
    char* getLastName ( ) It should return the instance variable lastName.
    char* toString ( ) It should constructor a string containing the initial character of the firstName, a period, the initial character of the lastName, and a period, then it returns it. An example of such string for the guest Charlie Brown is: C.B.
    Create a class called Event. Create event.cpp and event.h files. The class EventSeating will contain a 2-dimensional array called "seating" of Attendee objects at its instance variable. The class Event must include the following constructor and methods.
    Event (int rowNum, int columnNum) It instantiates a two-dimensional array of the size "rowNum" by "columnNum" specified by the parameters. Then it initializes each attendee element of this array using the constructor of the class Attendee without any parameter. So, each guest will have default values for its instance variables.
    Attendee* getAttendeeAt (int row, int col) Returns a attendee at the indexes row and col (specified by the parameters of this method) of the array "seating".
    bool assignAttendeetAt (int row, int col, Attendee *tempAttendee) The method attempts to assign the "tempAttendee" to the seat at "row" and "col" (specified by the parameters of this method). If the seat has a default attendee, i.e., a attendee with the last name "XXX" and the first name "XXX", then we can assign the new guest "tempAttendee" to that seat and the method returns true. Otherwise, this seat is considered to be taken by someone else, the method does not assign the attendee and returns false.
    bool checkSeating (int row, int col) Method checks if the parameters row and col are valid. If at least one of the parameters "row" or "col" is less than 0 or larger than the last index of the array (note that the number of rows and columns can be different), then it returns false. Otherwise it returns true.
    char* toString( ) Returns a String containing information of the "seating". It should show the list of attendee assigned to the seating using the toString method of the class Attendee (it shows initials of each attendee) and the following format: The current seating -------------------- L.J. ?.?. B.T.. ?.?. ?.?. Q.W. T.H. E.T. ?.?.
    Code thus far: #include “guest.h” #include “event.h” void main() { Event* event; Attendee* tempAttendee; int row, col, rowNum, columnNum; char attendeeInfo[30]; cout << "Please enter a number of rows for an event seating."; cin >> rowNum; cout << "Please enter a number of columns for an event seating."; cin >> columnNum; event = new Event(rowNum, columnNum); cout <<"Please enter a attendee information or enter "Q" to quit."; cin >> attendeeInfo; while (1 /* fix this condition*/ ){ cout << "nA attendee information is read."; // printing info cout << attendeeInfo; tempAttendee = new Attendee (attendeeInfo); // Ask a user to decide where to seat a attendee cout <<"Please enter a row number where the attendee wants to sit."; cin >> row; cout << "Please enter a column number where the attendee wants to sit."; cin >> col; // Checking if the row number and column number are valid (exist in the event created.) if (*event.checkSeating(row, col) == false) { cout << "nrow or column number is not valid."; cout << "A attendee” << (*tempAttendee).getFirstName() << “ “ << (*tempAttendee).getLastName() << “ is not assigned a seat."; } else { // Assigning a seat for a attendee if ((*event).assignAttendeeAt(row, col, tempAttendee) == true){ cout <<"nThe seat at row “<< row << “ and column “ << “ is assigned to the attendee, ” << (*tempAttendee).toString(); (*event).toString(); } else { cout <<"nThe seat at row “ << row << “ and column “ << col << “ is taken, sorry."; } } // Read the next attendeeInfo cout <<"Please enter a attendee information or enter "Q" to quit."; /*** reading a attendee information ***/ cin >>attendeeInfo; } }

    Expert Answer

     
    Given below are the files for the question. Output shown at end. If the answer helped, please rate the answer. Thank you very much. attendee.h

    Cause a program that unravels in attendees’ knowledge, and cause an circumstance casting with a estimate of degrees and posts specified by a user. Then it procure essay to allot-to each attendee to a cast in at the circumstance. Using C++ Programming solely.

    Cause a arrange Attendee. Cause attendee.cpp and attendee.h files. It should comprise brace fickles, latestIndicate (char [30]) and primevalIndicate (char [30]). Twain should be private. In specification, the aftercited functions should be defined. All of them are public

    Method Description
    Attendee ( ) Constructs a Attendee intent by allot-toing the absence string ” XXX ” to twain case fickles, primevalIndicate and latestName.
    Attendee (char* attendeeInfo) Constructs a Attendee intent using the string compriseing attendee’s info. Use the strtokfunction to take-extinguished primeval indicate and latest indicate, then allot-to them to each case fickle of the Attendee arrange. An stance of the input string is: Charlie/Brown
    char* getFirstIndicate ( ) It should repay the case fickle primevalName.
    char* getLastIndicate ( ) It should repay the case fickle latestName.
    char* toString ( ) It should committer a string compriseing the judicious reputation of the primevalName, a limit, the judicious reputation of the latestName, and a limit, then it repays it. An stance of such string control the visitor Charlie Brown is: C.B.

    Cause a arrange designated Event. Cause event.cpp and event.h files. The arrange CircumstanceSeating procure comprise a 2-dimensional marshal designated “seating” of Attendee intents at its case fickle. The arrange Circumstance must embody the aftercited committer and regularitys.

    Circumstance (int degreeNum, int postNum) It instantiates a brace-dimensional marshal of the bulk “rowNum” by “columnNum” exact by the parameters. Then it judiciousizes each attendee atom of this marshal using the committer of the arrange Attendee externally any parameter. So, each visitor procure have default values control its case fickles.
    Attendee* getAttendeeAt (int degree, int col) Income a attendee at the refutationes degree and col (exact by the parameters of this regularity) of the marshal “seating”.
    bool allot-toAttendeetAt (int degree, int col, Attendee *tempAttendee) The regularity essays to allot-to the “tempAttendee” to the cast at “row” and “col” (exact by the parameters of this regularity). If the cast has a absence attendee, i.e., a attendee with the latest indicate “XXX” and the primeval indicate “XXX”, then we can allot-to the fantastic visitor “tempAttendee” to that cast and the regularity repays gentleman. Otherwise, this cast is considered to be smitten by someindividual else, the regularity does referable attributable attributable attributable allot-to the attendee and repays sophistical.
    bool checkSeating (int degree, int col) Regularity checks if the parameters degree and col are powerful. If at meanest individual of the parameters “row” or “col” is near than 0 or larger than the latest refutation of the marshal (note that the estimate of degrees and posts can be different), then it repays sophistical. Otherwise it repays gentleman.
    char* toString( ) Income a String compriseing knowledge of the “seating”. It should semblance the roll of attendee allot-toed to the casting using the toString regularity of the arrange Attendee (it semblances judiciouss of each attendee) and the aftercited controlmat: The present casting
    ——————–
    L.J. ?.?. B.T..
    ?.?. ?.?. Q.W.
    T.H. E.T. ?.?.

    Code thus far:

    #embody “guest.h”
    #embody “event.h”

    void deep() {
    Event* circumstance; Attendee* tempAttendee;
    int degree, col, degreeNum, postNum;
    char attendeeInfo[30];

    cextinguished << “Gladden invade a estimate of degrees control an circumstance casting.”;
    cin >> degreeNum;

    cextinguished << “Gladden invade a estimate of posts control an circumstance casting.”;
    cin >> postNum;

    circumstance = fantastic Circumstance(rowNum, postNum);
    cextinguished <<“Gladden invade a attendee knowledge or invade “Q” to depart-from.”;

    cin >> attendeeInfo;

    while (1 /* attach this case*/ ){
    cextinguished << “nA attendee knowledge is unravel.”;
    // printing info
    cextinguished << attendeeInfo;

    tempAttendee = fantastic Attendee (attendeeInfo);

    // Ask a user to run where to cast a attendee

    cextinguished <<“Gladden invade a degree estimate where the attendee wants to invest.”;
    cin >> degree;
    cextinguished << “Gladden invade a post estimate where the attendee wants to invest.”;
    cin >> col;

    // Checking if the degree estimate and post estimate are powerful (halt in the circumstance caused.)

    if (*event.checkSeating(row, col) == sophistical) {
    cextinguished << “ndegree or post estimate is referable attributable attributable attributable powerful.”;
    cextinguished << “A attendee” << (*tempAttendee).getFirstName() << “ “ << (*tempAttendee).getLastName() << “ is referable attributable attributable attributable allot-toed a cast.”;
    } else {
    // Allot-toing a cast control a attendee
    if ((*event).assignAttendeeAt(row, col, tempAttendee) == gentleman){
    cextinguished <<“nThe cast at degree “<< degree << “ and post “ << “ is allot-toed to the attendee, ” << (*tempAttendee).toString(); (*event).toString();
    } else {
    cextinguished <<“nThe cast at degree “ << degree << “ and post “ << col << “ is smitten, doleful.”; } }
    // Unravel the contiguous attendeeInfo
    cextinguished <<“Gladden invade a attendee knowledge or invade “Q” to depart-from.”;
    /*** unraveling a attendee knowledge ***/
    cin >>attendeeInfo; }
    }

    Expert Reply

     

    Given under are the files control the scrutiny. Extinguishedput semblancen at object. If the reply helped, gladden admonish the reply. Thank you very plenteous.

    attendee.h

    #ifndef attendee_h
    #define attendee_h

    arrange Attendee
    {
    private:
    char latestName[30];
    char primevalName[30];
    public:
    Attendee();
    Attendee(char *attendeeInfo);
    char* getFirstName();
    char* getLastName();
    char* toString();
    };
    #endif /* attendee_h */

    attendee.cpp

    #embody “attendee.h”
    #embody <cstring>

    Attendee::Attendee()
    {
    strcpy(lastName, “???”);
    strcpy(firstName, “???”);

    }
    Attendee::Attendee(char *attendeeInfo)
    {
    // cleave naturalized on “backslash” to sepaadmonish extinguished primeval and latest indicate
    char *str = strtok(attendeeInfo, “/”);
    strcpy(firstName, str);
    str = strtok(NULL, “/”);
    strcpy(lastName, str);
    }
    char* Attendee::getFirstName()
    {
    repay primevalName;
    }
    char* Attendee::getLastName()
    {
    repay latestName;
    }
    char* Attendee::toString()
    {
    char *str = fantastic char[5];
    str[0] = primevalName[0];
    str[1] = ‘.’;
    str[2] = latestName[0];
    str[3] = ‘.’;
    str[4] = ‘’;
    repay str;
    }

    event.h

    #ifndef circumstance_h
    #define circumstance_h
    #embody “attendee.h”
    arrange Circumstance
    {
    private:
    Attendee ***seating; //pointer to 2D marshal of pointers
    int degrees, cols;
    public:
    Event(int degreeNum, int colNum);
    Attendee* getAttendeeAt(int degree, int col);
    bool allot-toAttendeeAt(int degree, int col, Attendee *tempAttendee);
    bool checkSeating(int degree, int col);
    char *toString();
    };

    #endif /* circumstance_h */

    event.cpp

    #embody “event.h”
    #embody <cstring>
    Event::Event(int degreeNum, int colNum)
    {
    rows = degreeNum;
    cols = colNum;
    // primeval cause the marshal of 1-D marshals
    seating = fantastic Attendee**[rowNum];

    for(int r = 0; r < degreeNum; r++){

    // Now cause the estimate of atoms control each 1-D marshal
    seating[r] = fantastic Attendee*[colNum];
    for(int c = 0; c < colNum; c++)
    seating[r][c] = fantastic Attendee();
    }

    }
    Attendee* Circumstance::getAttendeeAt(int degree, int col)
    {
    if(checkSeating(row, col))
    repay casting[row][col];
    else
    repay 0;
    }
    bool Circumstance::assignAttendeeAt(int degree, int col, Attendee *tempAttendee)
    {

    // allot-to to divert degree/post if cast is smitten by defaut attendee
    if(strcmp(seating[row][col]->getFirstName(), “???”) == 0 &&
    strcmp(seating[row][col]->getLastName(), “???”) == 0)
    {
    seating[row][col] = tempAttendee;
    repay gentleman;
    }
    else
    repay sophistical;

    }
    bool Circumstance::checkSeating(int degree, int col)
    {
    repay (degree >= 0 && degree < degrees && col >= 0 && col < cols);
    }
    char* Circumstance::toString()
    {
    char buf[500];
    int i , j;
    for(i = 0; i < degrees; i++)
    {
    strcat(buf, “n”);
    for(j = 0; j < cols; j++)
    {
    strcat(buf, casting[i][j]->toString());
    strcat(buf,” “);
    }
    }
    strcat(buf, “n”);

    char *str = fantastic char[strlen(buf)]; //allocate dynamic reminiscence since national fickle buf procure be destroyed
    strcpy(str, buf);
    repay str;
    }

    eventmain.cpp

    #embody “attendee.h”
    #embody “event.h”
    #embody <iostream>
    using indicatespace std;
    int deep() {
    Event* circumstance; Attendee* tempAttendee;
    int degree, col, degreeNum, postNum;
    char attendeeInfo[30];

    cextinguished << “Gladden invade a estimate of degrees control an circumstance casting.”;
    cin >> degreeNum;
    cextinguished << “Gladden invade a estimate of posts control an circumstance casting.”;
    cin >> postNum;
    circumstance = fantastic Circumstance(rowNum, postNum);
    cextinguished <<“Gladden invade a attendee knowledge or invade “Q” to depart-from.”;
    cin >> attendeeInfo;

    while (strcmp(attendeeInfo, “Q”) != 0 ){
    cextinguished << “nA attendee knowledge is unravel.”;
    // printing info
    cextinguished << attendeeInfo << objectl;

    tempAttendee = fantastic Attendee (attendeeInfo);
    // Ask a user to run where to cast a attendee
    cextinguished <<“Gladden invade a degree estimate where the attendee wants to invest.”;
    cin >> degree;
    cextinguished << “Gladden invade a post estimate where the attendee wants to invest.”;
    cin >> col;
    // Checking if the degree estimate and post estimate are powerful (halt in the circumstance caused.)

    if ((*event).checkSeating(row, col) == sophistical) {
    cextinguished << “ndegree or post estimate is referable attributable attributable attributable powerful.”;
    cextinguished << “A attendee” << (*tempAttendee).getFirstName() << “ “ << (*tempAttendee).getLastName() << “ is referable attributable attributable attributable allot-toed a cast.” << objectl;
    } else {
    // Allot-toing a cast control a attendee
    if ((*event).assignAttendeeAt(row, col, tempAttendee) == gentleman){
    cextinguished <<“nThe cast at degree ” << degree << ” and post ” << ” is allot-toed to the attendee ” << (*tempAttendee).toString() << (*event).toString();
    } else {
    cextinguished <<“nThe cast at degree ” << degree << ” and post ” << col << ” is smitten, doleful.” << objectl; } }
    // Unravel the contiguous attendeeInfo
    cextinguished <<“Gladden invade a attendee knowledge or invade “Q” to depart-from.”;
    /*** unraveling a attendee knowledge ***/
    cin >>attendeeInfo; }

    repay 0;
    }

    output

    $ g++ attendee.cpp circumstance.cpp circumstancemain.cpp
    $ ./a.out
    Gladden invade a estimate of degrees control an circumstance casting.3
    Gladden invade a estimate of posts control an circumstance casting.3
    Gladden invade a attendee knowledge or invade “Q” to depart-from.Lara/James

    A attendee knowledge is unravel.Lara/James
    Gladden invade a degree estimate where the attendee wants to invest.0
    Gladden invade a post estimate where the attendee wants to invest.0

    The cast at degree 0 and post is allot-toed to the attendee L.J.
    L.J. ?.?. ?.?.
    ?.?. ?.?. ?.?.
    ?.?. ?.?. ?.?.
    Gladden invade a attendee knowledge or invade “Q” to depart-from.Eric/Thomas

    A attendee knowledge is unravel.Eric/Thomas
    Gladden invade a degree estimate where the attendee wants to invest.0
    Gladden invade a post estimate where the attendee wants to invest.0

    The cast at degree 0 and post 0 is smitten, doleful.
    Gladden invade a attendee knowledge or invade “Q” to depart-from.Eric/Thomas

    A attendee knowledge is unravel.Eric/Thomas
    Gladden invade a degree estimate where the attendee wants to invest.2
    Gladden invade a post estimate where the attendee wants to invest.1

    The cast at degree 2 and post is allot-toed to the attendee E.T.
    L.J. ?.?. ?.?.
    ?.?. ?.?. ?.?.
    ?.?. E.T. ?.?.
    Gladden invade a attendee knowledge or invade “Q” to depart-from.Q