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
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.
Function | Description |
---|---|
void attendee_init (struct attendee *a, char *info) | Use the strtok function to extract first name and last name from the variable attendee, then assign them to each instance variable of the attendee structure. An example of the input string is: Charlie/Brown |
void attendee_to_string (struct attendee *a) | The attendee_to_string function prints the initial character of the first name, a period, the initial character of the last name, and a period. An example of such string for the attendee Charlie/Brown is: C.B. |
COMPLETED void event_seating_init (int rowNum, int columnNum, struct event_seating *a ) | COMPLETED It instantiates a two-dimensional array of the size "rowNum" by "columnNum" specified by the parameters inside the struct a. Then it initializes each guest element of this array using the default_attendee_init function. So, each guest will have default values for its instance variables |
int assign_attendee_at (int row, int col, struct event_seating *e, struct attendee* a) | The assign_attendee_at function attempts to assign the "a" to the seat at "row" and "col" (specified by the parameters of this function). If the seat has a default attendee, i.e., a attendee with the last name "???" and the first name "???", then we can assign the new attemdee "a" 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 return 0 (false). |
int check_boundaries (int row, int col, struct event_seating *e) | The check_boundaries function 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 return 0 (false). Otherwise it returns 1 (true) |
void event_seating_to_string (struct event_seating *e ) | It prints information of the "seating". It should show the list of attendees assigned to the seating using the attendee_to_string function (it shows initials of each guest) and the following format as illustrated below The current seating -------------------- D.J. ?.?. E.T. ?.?. ?.?. S.W. T.C. A.T. ?.?. |
Code thus far....
#include
struct attendee { char last_name[30]; char first_name[30]; };
struct event_seating{ struct attendee **seating;
// can save the final rowNum and columnNum here from the user input if needed to help with iteration. };
void attendee_int_default(struct attendee *g){ char lname[30] = "???"; char fname[30] = "???"; // copy the above strigns to the structure strcpy(g->last_name, lname); strcpy(g->first_name, fname); }
void event_seating_init(int rowNum, int columnNum, struct event_seating *e){ int row,col; // first create the array of 1-D arrays e->seating = (struct attendee **)malloc(rowNum * sizeof(struct attendee *)); for(row = 0; row < rowNum; row++){ // Now create the number of elements for each 1-D array e->seating[row] = (struct attendee *)malloc(columnNum * sizeof(struct attendee)); for(col = 0; col < columnNum; col++){ // now call the init function on each element attendee_int_default(&e->seating[row][col]); } } };
void guest_init (struct attendee *a, char *info) { // split info based on "backslash" assign to first and last name accordingly
} void attendee_to_string (struct attendee *a ) { // implement } void event_seating_init (int rowNum, int columnNum, struct event_seating *e ) { // implement } int assign_attendee_at (int row, int col, struct event_seating *e, struct attendee* a) { // assign to appropriate row/column if not taken } int check_boundaries (int row, int col, struct event_seating *e) { // implment makig sure row and colum are within the seating array } void event_seating_to_string (struct event_seating *e ) { // format at described in the instructions }
void main() { struct event_seating event_seating; struct attendee temp_attendee; int row, col, rowNum, columnNum; char attendee_info[30]; // Ask a user to enter a number of rows for an event seating printf ("Please enter a number of rows for an event seating."); scanf ("%d", &rowNum); // Ask a user to enter a number of columns for an event seating printf ("Please enter a number of columns for an event seating."); scanf ("%d", &columnNum);
/** **/
// event_seating event_seating_init(rowNum, columnNum, &auditorium_seating); printf("Please enter a attendee information or enter \"Q\" to quit."); /*** reading a attendee's information ***/ scanf ("%s", attendee_info); /* we will read line by line **/ while (1 /* change this condition*/ ){ printf (" An attendee information is read."); // printing information. printf ("%s", attendee_info); // attendee attendee_init (&temp_attendee, attendee_info); // Ask a user to decide where to seat a attendee by asking // for row and column of a seat printf ("Please enter a row number where the attendee wants to sit. "); scanf("%d", &row); printf("Please enter a column number where the attendee wants to sit. "); scanf("%d", &col); // Checking if the row number and column number are valid // (exist in the event that we created.) if (check_boundaries(row, col, &event_seating) == 0) { printf(" row or column number is not valid."); printf("A attendee %s %s is not assigned a seat.", temp_attendee.first_name, temp_attendee.last_name); } else { // Assigning a seat for a attendee if (attendee_guest_at(row, col, &event_seating, &temp_attendee) == 1){ printf(" The seat at row %d and column %d is assigned to the attende ",row, col); attendee_to_string(&temp_attendee); event_seating_to_string(&event_seating); } else { printf(" The seat at row %d and column %d is taken .", row, col); } } // Read the next attende info printf ("Please enter a attendee information or enter \"Q\" to quit."); /*** reading a attendees information ***/ scanf("%s", attendee_info); }
};
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started