Question
Part 1. Primitive Types, Searching, Recursion (35 points). a) Create a class Homework (in a file homework.h and homework.cpp ). Review the lectures and textbook
Part 1. Primitive Types, Searching, Recursion (35 points).
a) Create a class Homework (in a file homework.h and homework.cpp). Review the lectures and textbook to learn about the content of each file.
b) Create a function initializeArray that receives two parameters: an array of integers and the array size. Use a for loop and an if statement to put 1s in the odd positions of the array and 0s in the even positions. Hint: review pointers as parameters.
c) Create a function printArray that receives as parameters an array of integers and the
array size. Use a for statements to print all the elements in the array. Hint: review pointers as parameters.
d) Create a function arraySelectionSort that receives as parameters an array of integers and the array size, and order the array element in ascending order. Implement Selection Sort algorithm. It should be Selection Sort, not Bubble Sort, not Quick Sort, etc. If you do not remember selection sort, this link could be useful: https://goo.gl/hrAdMo
e) Create a recursive function that calculate and returns the factorial of a number. The function receives the number (integer number) as parameter
f) Create a file main_part1.cpp. Copy the following main function in your class,
int main() { int a [10] = {3, 5, 6, 8, 12, 13, 16, 17, 18, 20}; int b [6] = {18, 16, 19, 3 ,14, 6}; int c [5] = {5, 2, 4, 3, 1};
Homework h;
// testing initializeArray h.printArray(a, 10); // print: 3, 5, 6, 8, 12, 13, 16, 17, 18, 20 h.initializeArray(a, 10); h.printArray(a, 10); // print: 0, 1, 0, 1, 0, 1, 0, 1, 0, 1
// testing initializeArray h.printArray(b, 6); // print: 18, 16, 19, 3 ,14, 6 h.arraySelectionSort (b, 6); h.printArray(b, 6); // print: 3, 6, 14, 16, 18, 19
// testing factorial cout Factorial of 5 = h.factorial (5)
c[0] = h.factorial (c[0]); c[1] = h.factorial (c[2]); h.printArray(c, 5); // print: 120, 24, 4, 3, 1
return 0; }
Grading Criteria for the part 1
05 pts: file contains header information and adequate comment to explain every function 05 pts: consistent indentation and spacing 05 pts: 3 files (1 file *.h, 2 files *.cpp) 05 pts: selectionSort
05 pts: printArray 05 pts: initializeArray 05 pts: factorial
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
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.)
After compiling all files, you need to execute it.
Sample Output: (the inputs entered by a user are shown in bold)
Make sure that your program works at least with this scenario.
Please enter a number of rows for a classroom seating.
3
Please enter a number of columns for a classroom seating.
3
1
Please enter a column number where the student wants to sit.
2
The seat at row 1 and column 2 is assigned to the student M-M.
Please enter a student information or enter "Q" to quit.
Mickey/Mouse
A student information is read.
Mickey/Mouse
Please enter a row number where the student wants to sit.
The current seating
--------------------
?-?. ?-?. ?-?. ?-?. ?-?. M-M. ?-?. ?-?. ?-?.
Please enter a student information or enter "Q" to quit.
Daisy/Duck
A student information is read.
Daisy/Duck
Please enter a row number where the student wants to sit.
2
Please enter a column number where the student wants to sit.
0
The seat at row 2 and column 0 is assigned to the student D-D.
The current seating
--------------------
?-?. ?-?. ?-?. ?-?. ?-?. M-M. D-D. ?-?. ?-?.
Please enter a student information or enter "Q" to quit.
Clarabelle/Cow
A student information is read.
Clarabelle/Cow
Please enter a row number where the student wants to sit.
2
Please enter a column number where the student wants to sit.
1
The seat at row 2 and column 1 is assigned to the student C-C.
The current seating
--------------------
?-?. ?-?. ?-?. ?-?. ?-?. M-M. D-D. C-C. ?-?.
Please enter a student information or enter "Q" to quit.
Max/Goof
A student information is read.
Max/Goof
Please enter a row number where the student wants to sit.
0
Please enter a column number where the student wants to sit.
0
The seat at row 0 and column 0 is assigned to the student M-G.
The current seating
--------------------
M-G. ?-?. ?-?. ?-?. ?-?. M-M. D-D. C-C. ?-?.
Please enter a student information or enter "Q" to quit.
Horace/Horsecollar
A student information is read.
Horace/Horsecollar
Please enter a row number where the student wants to sit.
5
Please enter a column number where the student wants to sit.
1
2
Please enter a column number where the student wants to sit.
0
Please enter a column number where the student wants to sit.
0
0
Please enter a column number where the student wants to sit.
2
The seat at row 0 and column 2 is assigned to the student J-C.
row or column number is not valid.
A student Horace Horsecollar is not assigned a seat.
Please enter a student information or enter "Q" to quit.
Sylvester/Shyster
A student information is read.
Sylvester/Shyster
Please enter a row number where the student wants to sit.
The seat at row 2 and column 0 is taken.
Please enter a student information or enter "Q" to quit.
Snow/White
A student information is read.
Snow/White
Please enter a row number where the student wants to sit.
-1
row or column number is not valid
A student Snow White is not assigned a seat.
Please enter a student information or enter "Q" to quit.
Jiminy/Criket
A student information is read.
Jiminy/Criket
Please enter a row number where the student wants to sit.
The current seating
--------------------
M-G. ?-?. J-C. ?-?. ?-?. M-M. D-D. C-C. ?-?.
Please enter a student information or enter "Q" to quit.
Q
Grading Criteria for the part 2
05 pts: Every file contains header information 05 pts: adequate comment to explain every method 05 pts: consistent indentation and spacing 05 pts: it compiles 05 pts: Two constructors of Student are correct 05 pts: Accessor methods for lastName and firstName of Student are correct 05 pts: toString method of Student is correct 05 pts: Constructor, Classroom(int,int) is correct 05 pts: getStudentAt(int,int) method is correct 10 pts: assignStudentAt(int,int,Student) method is correct 05 pts: checkBoundaries(int,int) method is correct 05 pts: toString method is correct
#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 > rowNum;
// Ask a user to enter a number of columns for a classroom seating
cout > columnNum;
// classroom_seating
classroom = new Classroom(rowNum, columnNum); cout
/*** reading a student's information ***/
cin >> studentInfo;
/* we will read line by line **/ while (1 /* change this condition*/ ){
cout
// printing information.
cout
// student
tempStudent = new Student (studentInfo);
a classroom seating.";
enter \"Q\" to quit.";
// Ask a user to decide where to seat a student by asking // for row and column of a seat
cout > row;
cout > 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
(*tempStudent).getLastName()
} else { // Assigning a seat for a student if ((*classroom).assignStudentAt(row, col, tempStudent) == true){
cout
(*classroom).toString(); } else {
cout
} // Read the next studentInfo cout >studentInfo;
} }
Method Student () Description of the Method Constructs a Student object by assigning the default string " ??? " to both instance variables, lastName and firstName. Student (char* studentInfo)Use the strtok function to extract first name and last name, then Constructs a Student object using the string containing student's info. 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 firstName. It should return the instance variable lastName, 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, thern it returns it. An example of such string for the student David Johnson 1S: D-J Method Student () Description of the Method Constructs a Student object by assigning the default string " ??? " to both instance variables, lastName and firstName. Student (char* studentInfo)Use the strtok function to extract first name and last name, then Constructs a Student object using the string containing student's info. 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 firstName. It should return the instance variable lastName, 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, thern it returns it. An example of such string for the student David Johnson 1S: D-JStep 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