Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a program that reads in attendees\' information, and create an event seat

ID: 3882457 • Letter: C

Question

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

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.

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 << " A 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 << " row 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 <<" The seat at row “<< row << “ and column “ << “ is assigned to the attendee, ” << (*tempAttendee).toString(); (*event).toString();
   } else {
     cout <<" The 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; }
}

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 strtok function 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.

Explanation / 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


#ifndef attendee_h
#define attendee_h

class Attendee
{
private:
char lastName[30];
char firstName[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)
{
// split based on "backslash" to separate out first and last name
char *str = strtok(attendeeInfo, "/");
strcpy(firstName, str);
str = strtok(NULL, "/");
strcpy(lastName, str);
}
char* Attendee::getFirstName()
{
return firstName;
}
char* Attendee::getLastName()
{
return lastName;
}
char* Attendee::toString()
{
char *str = new char[5];
str[0] = firstName[0];
str[1] = '.';
str[2] = lastName[0];
str[3] = '.';
str[4] = '';
return str;
}

event.h


#ifndef event_h
#define event_h
#include "attendee.h"
class Event
{
private:
Attendee ***seating; //pointer to 2D array of pointers
int rows, cols;
public:
Event(int rowNum, int colNum);
Attendee* getAttendeeAt(int row, int col);
bool assignAttendeeAt(int row, int col, Attendee *tempAttendee);
bool checkSeating(int row, int col);
char *toString();
};

#endif /* event_h */

event.cpp


#include "event.h"
#include <cstring>
Event::Event(int rowNum, int colNum)
{
rows = rowNum;
cols = colNum;
// first create the array of 1-D arrays
seating = new Attendee**[rowNum];
  
for(int r = 0; r < rowNum; r++){
  
// Now create the number of elements for each 1-D array
seating[r] = new Attendee*[colNum];
for(int c = 0; c < colNum; c++)
seating[r][c] = new Attendee();
}
  
}
Attendee* Event::getAttendeeAt(int row, int col)
{
if(checkSeating(row, col))
return seating[row][col];
else
return 0;
}
bool Event::assignAttendeeAt(int row, int col, Attendee *tempAttendee)
{
  
// assign to appropriate row/column if seat is taken by defaut attendee
if(strcmp(seating[row][col]->getFirstName(), "???") == 0 &&
strcmp(seating[row][col]->getLastName(), "???") == 0)
{
seating[row][col] = tempAttendee;
return true;
}
else
return false;
  
}
bool Event::checkSeating(int row, int col)
{
return (row >= 0 && row < rows && col >= 0 && col < cols);
}
char* Event::toString()
{
char buf[500];
int i , j;
for(i = 0; i < rows; i++)
{
strcat(buf, " ");
for(j = 0; j < cols; j++)
{
strcat(buf, seating[i][j]->toString());
strcat(buf," ");
}
}
strcat(buf, " ");
  
char *str = new char[strlen(buf)]; //allocate dynamic memory since local variable buf will be destroyed
strcpy(str, buf);
return str;
}

eventmain.cpp

#include "attendee.h"
#include "event.h"
#include <iostream>
using namespace std;
int 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 (strcmp(attendeeInfo, "Q") != 0 ){
cout << " A attendee information is read.";
// printing info
cout << attendeeInfo << endl;
  
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 << " row or column number is not valid.";
cout << "A attendee” << (*tempAttendee).getFirstName() << “ “ << (*tempAttendee).getLastName() << “ is not assigned a seat." << endl;
} else {
// Assigning a seat for a attendee
if ((*event).assignAttendeeAt(row, col, tempAttendee) == true){
cout <<" The seat at row " << row << " and column " << " is assigned to the attendee " << (*tempAttendee).toString() << (*event).toString();
} else {
cout <<" The seat at row " << row << " and column " << col << " is taken, sorry." << endl; } }
// Read the next attendeeInfo
cout <<"Please enter a attendee information or enter "Q" to quit.";
/*** reading a attendee information ***/
cin >>attendeeInfo; }
  
return 0;
}

output

$ g++ attendee.cpp event.cpp eventmain.cpp
$ ./a.out
Please enter a number of rows for an event seating.3
Please enter a number of columns for an event seating.3
Please enter a attendee information or enter "Q" to quit.Lara/James

A attendee information is read.Lara/James
Please enter a row number where the attendee wants to sit.0
Please enter a column number where the attendee wants to sit.0

The seat at row 0 and column is assigned to the attendee L.J.
L.J. ?.?. ?.?.
?.?. ?.?. ?.?.
?.?. ?.?. ?.?.
Please enter a attendee information or enter "Q" to quit.Eric/Thomas

A attendee information is read.Eric/Thomas
Please enter a row number where the attendee wants to sit.0
Please enter a column number where the attendee wants to sit.0

The seat at row 0 and column 0 is taken, sorry.
Please enter a attendee information or enter "Q" to quit.Eric/Thomas

A attendee information is read.Eric/Thomas
Please enter a row number where the attendee wants to sit.2
Please enter a column number where the attendee wants to sit.1

The seat at row 2 and column is assigned to the attendee E.T.
L.J. ?.?. ?.?.
?.?. ?.?. ?.?.
?.?. E.T. ?.?.
Please enter a attendee information or enter "Q" to quit.Q

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote