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

    Produce a program that recognizes in attendees’ instruction, and produce an incident perpetuateing with a enumescold of tiers and supports specified by a user. Then it get violate to point-extinguished each attendee to a perpetuate in at the incident. Using C++ Programming simply.

    Produce a systematize Attendee. Produce attendee.cpp and attendee.h files. It should comprise span mutables, latestCall (char [30]) and leadingCall (char [30]). Twain should be private. In enumeration, the aftercited functions should be defined. All of them are public

    Method Description
    Attendee ( ) Constructs a Attendee motive by point-outing the controlfeit string ” XXX ” to twain solicitation mutables, leadingCall and latestName.
    Attendee (char* attendeeInfo) Constructs a Attendee motive using the string compriseing attendee’s info. Use the strtokfunction to excerpt leading call and latest call, then point-extinguished them to each solicitation mutable of the Attendee systematize. An specimen of the input string is: Charlie/Brown
    char* getFirstCall ( ) It should produce the solicitation mutable leadingName.
    char* getLastCall ( ) It should produce the solicitation mutable latestName.
    char* toString ( ) It should composer a string compriseing the modescold mark of the leadingName, a bound, the modescold mark of the latestName, and a bound, then it produces it. An specimen of such string control the visitor Charlie Brown is: C.B.

    Produce a systematize designated Event. Produce event.cpp and event.h files. The systematize IncidentSeating get comprise a 2-dimensional deck designated “seating” of Attendee motives at its solicitation mutable. The systematize Incident must include the aftercited composer and courses.

    Incident (int tierNum, int supportNum) It instantiates a span-dimensional deck of the largeness “rowNum” by “columnNum” specific by the parameters. Then it moderateizes each attendee part of this deck using the composer of the systematize Attendee extinguishedside any parameter. So, each visitor get have default values control its solicitation mutables.
    Attendee* getAttendeeAt (int tier, int col) Avail a attendee at the condemnationes tier and col (specific by the parameters of this course) of the deck “seating”.
    bool point-outAttendeetAt (int tier, int col, Attendee *tempAttendee) The course violates to point-extinguished the “tempAttendee” to the perpetuate at “row” and “col” (specific by the parameters of this course). If the perpetuate has a controlfeit attendee, i.e., a attendee with the latest call “XXX” and the leading call “XXX”, then we can point-extinguished the odd visitor “tempAttendee” to that perpetuate and the course produces gentleman. Otherwise, this perpetuate is considered to be enslaved by someindividual else, the course does referable point-extinguished the attendee and produces fiction.
    bool checkSeating (int tier, int col) Course checks if the parameters tier and col are cogent. If at smallest individual of the parameters “row” or “col” is less than 0 or larger than the latest condemnation of the deck (note that the enumescold of tiers and supports can be different), then it produces fiction. Otherwise it produces gentleman.
    char* toString( ) Avail a String compriseing instruction of the “seating”. It should pomp the catalogue of attendee point-outed to the perpetuateing using the toString course of the systematize Attendee (it pomps moderates of each attendee) and the aftercited controlmat: The general perpetuateing
    ——————–
    L.J. ?.?. B.T..
    ?.?. ?.?. Q.W.
    T.H. E.T. ?.?.

    Code thus far:

    #include “guest.h”
    #include “event.h”

    void main() {
    Event* incident; Attendee* tempAttendee;
    int tier, col, tierNum, supportNum;
    char attendeeInfo[30];

    cextinguished << “Content invade a enumescold of tiers control an incident perpetuateing.”;
    cin >> tierNum;

    cextinguished << “Content invade a enumescold of supports control an incident perpetuateing.”;
    cin >> supportNum;

    incident = odd Incident(rowNum, supportNum);
    cextinguished <<“Content invade a attendee instruction or invade “Q” to coercionsake.”;

    cin >> attendeeInfo;

    while (1 /* plant this requisite*/ ){
    cextinguished << “nA attendee instruction is recognize.”;
    // printing info
    cextinguished << attendeeInfo;

    tempAttendee = odd Attendee (attendeeInfo);

    // Ask a user to career where to perpetuate a attendee

    cextinguished <<“Content invade a tier enumescold where the attendee wants to invest.”;
    cin >> tier;
    cextinguished << “Content invade a support enumescold where the attendee wants to invest.”;
    cin >> col;

    // Checking if the tier enumescold and support enumescold are cogent (depobject in the incident produced.)

    if (*event.checkSeating(row, col) == fiction) {
    cextinguished << “ntier or support enumescold is referable cogent.”;
    cextinguished << “A attendee” << (*tempAttendee).getFirstName() << “ “ << (*tempAttendee).getLastName() << “ is referable point-outed a perpetuate.”;
    } else {
    // Point-outing a perpetuate control a attendee
    if ((*event).assignAttendeeAt(row, col, tempAttendee) == gentleman){
    cextinguished <<“nThe perpetuate at tier “<< tier << “ and support “ << “ is point-outed to the attendee, ” << (*tempAttendee).toString(); (*event).toString();
    } else {
    cextinguished <<“nThe perpetuate at tier “ << tier << “ and support “ << col << “ is enslaved, doleful.”; } }
    // Recognize the instant attendeeInfo
    cextinguished <<“Content invade a attendee instruction or invade “Q” to coercionsake.”;
    /*** recognizeing a attendee instruction ***/
    cin >>attendeeInfo; }
    }

    Expert Repartee

     

    Given beneath are the files control the scrutiny. Extinguishedput pompn at object. If the repartee helped, content scold the repartee. Thank you very abundantly.

    attendee.h

    #ifndef attendee_h
    #define attendee_h

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

    attendee.cpp

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

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

    }
    Attendee::Attendee(char *attendeeInfo)
    {
    // secede established on “backslash” to sepascold extinguished leading and latest call
    char *str = strtok(attendeeInfo, “/”);
    strcpy(firstName, str);
    str = strtok(NULL, “/”);
    strcpy(lastName, str);
    }
    char* Attendee::getFirstName()
    {
    produce leadingName;
    }
    char* Attendee::getLastName()
    {
    produce latestName;
    }
    char* Attendee::toString()
    {
    char *str = odd char[5];
    str[0] = leadingName[0];
    str[1] = ‘.’;
    str[2] = latestName[0];
    str[3] = ‘.’;
    str[4] = ‘’;
    produce str;
    }

    event.h

    #ifndef incident_h
    #define incident_h
    #include “attendee.h”
    systematize Incident
    {
    private:
    Attendee ***seating; //pointer to 2D deck of pointers
    int tiers, cols;
    public:
    Event(int tierNum, int colNum);
    Attendee* getAttendeeAt(int tier, int col);
    bool point-outAttendeeAt(int tier, int col, Attendee *tempAttendee);
    bool checkSeating(int tier, int col);
    char *toString();
    };

    #endif /* incident_h */

    event.cpp

    #include “event.h”
    #include <cstring>
    Event::Event(int tierNum, int colNum)
    {
    rows = tierNum;
    cols = colNum;
    // leading produce the deck of 1-D decks
    seating = odd Attendee**[rowNum];

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

    // Now produce the enumescold of parts control each 1-D deck
    seating[r] = odd Attendee*[colNum];
    for(int c = 0; c < colNum; c++)
    seating[r][c] = odd Attendee();
    }

    }
    Attendee* Incident::getAttendeeAt(int tier, int col)
    {
    if(checkSeating(row, col))
    produce perpetuateing[row][col];
    else
    produce 0;
    }
    bool Incident::assignAttendeeAt(int tier, int col, Attendee *tempAttendee)
    {

    // point-extinguished to embezzle tier/support if perpetuate is enslaved by defaut attendee
    if(strcmp(seating[row][col]->getFirstName(), “???”) == 0 &&
    strcmp(seating[row][col]->getLastName(), “???”) == 0)
    {
    seating[row][col] = tempAttendee;
    produce gentleman;
    }
    else
    produce fiction;

    }
    bool Incident::checkSeating(int tier, int col)
    {
    produce (tier >= 0 && tier < tiers && col >= 0 && col < cols);
    }
    char* Incident::toString()
    {
    char buf[500];
    int i , j;
    for(i = 0; i < tiers; i++)
    {
    strcat(buf, “n”);
    for(j = 0; j < cols; j++)
    {
    strcat(buf, perpetuateing[i][j]->toString());
    strcat(buf,” “);
    }
    }
    strcat(buf, “n”);

    char *str = odd char[strlen(buf)]; //allocate dynamic retrospect gone national mutable buf get be destroyed
    strcpy(str, buf);
    produce str;
    }

    eventmain.cpp

    #include “attendee.h”
    #include “event.h”
    #include <iostream>
    using callspace std;
    int main() {
    Event* incident; Attendee* tempAttendee;
    int tier, col, tierNum, supportNum;
    char attendeeInfo[30];

    cextinguished << “Content invade a enumescold of tiers control an incident perpetuateing.”;
    cin >> tierNum;
    cextinguished << “Content invade a enumescold of supports control an incident perpetuateing.”;
    cin >> supportNum;
    incident = odd Incident(rowNum, supportNum);
    cextinguished <<“Content invade a attendee instruction or invade “Q” to coercionsake.”;
    cin >> attendeeInfo;

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

    tempAttendee = odd Attendee (attendeeInfo);
    // Ask a user to career where to perpetuate a attendee
    cextinguished <<“Content invade a tier enumescold where the attendee wants to invest.”;
    cin >> tier;
    cextinguished << “Content invade a support enumescold where the attendee wants to invest.”;
    cin >> col;
    // Checking if the tier enumescold and support enumescold are cogent (depobject in the incident produced.)

    if ((*event).checkSeating(row, col) == fiction) {
    cextinguished << “ntier or support enumescold is referable cogent.”;
    cextinguished << “A attendee” << (*tempAttendee).getFirstName() << “ “ << (*tempAttendee).getLastName() << “ is referable point-outed a perpetuate.” << objectl;
    } else {
    // Point-outing a perpetuate control a attendee
    if ((*event).assignAttendeeAt(row, col, tempAttendee) == gentleman){
    cextinguished <<“nThe perpetuate at tier ” << tier << ” and support ” << ” is point-outed to the attendee ” << (*tempAttendee).toString() << (*event).toString();
    } else {
    cextinguished <<“nThe perpetuate at tier ” << tier << ” and support ” << col << ” is enslaved, doleful.” << objectl; } }
    // Recognize the instant attendeeInfo
    cextinguished <<“Content invade a attendee instruction or invade “Q” to coercionsake.”;
    /*** recognizeing a attendee instruction ***/
    cin >>attendeeInfo; }

    produce 0;
    }

    output

    $ g++ attendee.cpp incident.cpp incidentmain.cpp
    $ ./a.out
    Content invade a enumescold of tiers control an incident perpetuateing.3
    Content invade a enumescold of supports control an incident perpetuateing.3
    Content invade a attendee instruction or invade “Q” to coercionsake.Lara/James

    A attendee instruction is recognize.Lara/James
    Content invade a tier enumescold where the attendee wants to invest.0
    Content invade a support enumescold where the attendee wants to invest.0

    The perpetuate at tier 0 and support is point-outed to the attendee L.J.
    L.J. ?.?. ?.?.
    ?.?. ?.?. ?.?.
    ?.?. ?.?. ?.?.
    Content invade a attendee instruction or invade “Q” to coercionsake.Eric/Thomas

    A attendee instruction is recognize.Eric/Thomas
    Content invade a tier enumescold where the attendee wants to invest.0
    Content invade a support enumescold where the attendee wants to invest.0

    The perpetuate at tier 0 and support 0 is enslaved, doleful.
    Content invade a attendee instruction or invade “Q” to coercionsake.Eric/Thomas

    A attendee instruction is recognize.Eric/Thomas
    Content invade a tier enumescold where the attendee wants to invest.2
    Content invade a support enumescold where the attendee wants to invest.1

    The perpetuate at tier 2 and support is point-outed to the attendee E.T.
    L.J. ?.?. ?.?.
    ?.?. ?.?. ?.?.
    ?.?. E.T. ?.?.
    Content invade a attendee instruction or invade “Q” to coercionsake.Q