Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have never coded in C++ in my life. I am attempting to complete this assignment that creates a classroom object and student objects to

I have never coded in C++ in my life. I am attempting to complete this assignment that creates a classroom object and student objects to occupy the classroom. I believe I did set up the header files correctly. For this assignment, I have five files, classroom.cpp, classroom.h, Student.h, Student.cpp, and main_part2.cpp. I included pictures describing what each method should be accomplishing at the bottom to help clear up any confusion. Here is my code:

classroom.cpp

#include "classroom.h" #include #include using namespace std;

Classroom::Classroom(int rowNum, int columnNum){ seating = new Student[rowNum][columnNum]; int row, column; for(int row=0; row = seating.length || col >= seating[0].length) return false; else return true } char* Classroom::toString(){ String result = ""; int i, j; for(i=0; i

classroom.h

#ifndef CLASSROOM_H #define CLASSROOM_H

class Classroom{ private: int seating[][];

public: Classroom(int rowNum, int columnNum); Student* getStudentAt(int row, int col); bool assignStudentAt(int row, int col, Student *tempStudent); bool checkBoundaries(int row, int col); char* toString(); };

#endif //CLASSROOM_H

Student.cpp

#include "student.h" #include #include using namespace std;

Student::Student(){ firstName = "???"; lastName = "???"; } Student::Student(char* studentInfo){ strcpy(firstName, strtok(studentInfo, "/")); strcpy(lastName, strtok(studentInfo, "/")); } char* Student::getLastName(){ return lastName; } char* Student::getFirstName(){ return firstName; } char* Student::toString(){ return(firstName.charAt(0) + "-" + lastName.charAt(0) + "."); }

Student.h

#ifndef STUDENT_H #define STUDENT_H

class Student{ private: char[30] firstName; char[30] lastName;

public: Student(); Student(char* studentInfo); char* getLastName(); char* getFirstName(); char* toString(); };

#endif //STUDENT_H

main_part2.cpp

#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

cin >> rowNum;

//Ask a user to enter a number of columns for a classroom seating

cout

cin >> columnNum;

//classroom_seating

classroom = new Classroom(rowNum, columnNum);

cout

/*** reading a student's information ***/

cin >> studentInfo;

/* we will read line by line **/

while(!studentInfo.equalsIgnoreCase("Q")){

cout

//printing information.

cout

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

cin >> row;

cout

cin >> column;

//Checking if the row number and column number are valid

//(exist in the theatre that we created.)

if (*classroom.checkBoundaries(row,col) == false){

cout

cout

(*tempStudent).getLastName()

}else{

//Assigning a seat for a student

if((*classroom).assignStudentAt(row,col,tempStudent) == true){

cout

col

(*classroom).toString();

}else{

count

col

}

}

//Read the next studentInfo

cout

cin >>studentInfo;

}

}

image text in transcribed

image text in transcribed

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 Student ( Description of the Method Constructs a Student object by assigning the default string" ???" to both instance variables, lastName and firstName. Student Constructs a Student object using the string containing student's info. (char* studentlnfo 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 char* getFirstName( ) It should return the instance variable lastName 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.)

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

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions

Question

6. How do histories influence the process of identity formation?

Answered: 1 week ago