Answered Essay: 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

#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, “n”);
for(j = 0; j < cols; j++)
{
strcat(buf, seating[i][j]->toString());
strcat(buf,” “);
}
}
strcat(buf, “n”);

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 << “nA 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 << “nrow 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 <<“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.” << 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

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.

× How can I help you?