Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4. Part 2 Structs and Arrays (65 points). In this assignment, we will be making a program that reads in students information and create a

4. Part 2 Structs and Arrays (65 points). In this assignment, we will be making a program that reads in students information and create a classroom seating arrangement with a number of rows and columns specified by a user. Then it will attempt to assign each student to a seat in a classroom. Use the file main_part2.cpp (attached at the end of this document). Include all the following requested code in new *.cpp and *.h files, as needed.

Step 1. First, you need to create a class Student. Create student.cpp and student.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 of the Method Student ( ) Constructs a Student object by assigning the default string " ??? " to both instance variables, lastName and firstName. Student (char* studentInfo) Constructs a Student object using the string containing student's info. Use the strtok function to extract first name and last name, then assign them to each instance variable of the Student class. An example of the input string is: David/Johnson char* getLastName ( ) It should return the instance variable lastName. char* getFirstName ( ) It should return the instance variable firstName. char* toString ( ) It should constructor a string containing the initial character of the first name, a period, the initial character of the last name, and a period, then it returns it. An example of such string for the student David Johnson is: D-J. Step 2. You will be creating a class called Classroom. Create classroom.cpp and classroom.h files. The class ClassroomSeating will contain a 2-dimensional array called "seating" of Student objects at its instance variable. The class Classroom must include the following constructor and methods. (If your class does not contain any of the following methods, points will be deducted.) Method Description of the Method Classroom (int rowNum, int columnNum) It instantiates a two-dimensional array of the size "rowNum" by "columnNum" specified by the parameters. Then it initializes each student element of this array using the constructor of the class Student without any parameter. So, each student will have default values for its instance variables. Student* getStudentAt (int row, int col) It returns a student at the indexes row and col (specified by the parameters of this method) of the array "seating". bool assignStudentAt (int row, int col, Student *tempStudent) The method attempts to assign the "tempStudent" to the seat at "row" and "col" (specified by the parameters of this method). If the seat has a default student, i.e., a student with the last name "???" and the first name "???", then we can assign the new student "tempStudent" 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 student and returns false. bool checkBoundaries (int row, int col) The 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 students assigned to the seating using the toString method of the class Student (it shows initials of each student) and the following format: The current seating -------------------- D-J. ?.?. E-T. ?-?. ?-?. S-W. T-C. A-T. ?-?. Please see the sample output listed below. After compiling all files, you need to execute it.

#include student.h #include classroom.h

void main() { Classroom* classroom; Student* tempStudent; int row, col, rowNum, columnNum; char studentInfo[30]; // Ask a user to enter a number of rows for a classroom seating cout << "Please enter a number of rows for a classroom seating."; cin >> rowNum; // Ask a user to enter a number of columns for a classroom seating cout << "Please enter a number of columns for a classroom seating."; cin >> columnNum; // classroom_seating classroom = new Classroom(rowNum, columnNum); cout <<"Please enter a student information or enter \"Q\" to quit."; /*** reading a student's information ***/ cin >> studentInfo; /* we will read line by line **/ while (1 /* change this condition*/ ){ cout << " A student information is read."; // printing information. cout << studentInfo; // student tempStudent = new Student (studentInfo); // Ask a user to decide where to seat a student by asking // for row and column of a seat cout <<"Please enter a row number where the student wants to sit."; cin >> row; cout << "Please enter a column number where the student wants to sit."; cin >> col; // Checking if the row number and column number are valid // (exist in the theatre that we created.) if (*classroom.checkBoundaries(row, col) == false) { cout << " row or column number is not valid."; cout << "A student << (*tempStudent).getFirstName() << << (*tempStudent).getLastName() << is not assigned a seat."; } else { // Assigning a seat for a student if ((*classroom).assignStudentAt(row, col, tempStudent) == true){ cout <<" The seat at row << row << and column << is assigned to the student, << (*tempStudent).toString(); (*classroom).toString(); } else { cout <<" The seat at row << row << and column << col << is taken."; } } // Read the next studentInfo cout <<"Please enter a student information or enter \"Q\" to quit."; /*** reading a student's information ***/ cin >>studentInfo; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

More Books

Students also viewed these Databases questions