Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello there. I need help with these questions ( 1 to 6). The code I posted below the question is from Assignment #1/base code. Please

Hello there. I need help with these questions ( 1 to 6). The code I posted below the question is from Assignment #1/base code. Please answer from 1 to 6 and please answer in C++.

image text in transcribedimage text in transcribedimage text in transcribed

Course.cc

#include #include #include using namespace std;

#include "Course.h"

Course::Course(int c, int t, int g, string i) { code = c; grade = g; term = t; instructor = i; }

void Course::print() { string str;

cout

}

void Course::getGradeStr(string& gradeStr) { string gradeStrings[] = { "WDN", "F", "D-", "D", "D+", "C-", "C", "C+", "B-", "B", "B+", "A-", "A", "A+" };

if ( grade >= -1 && grade

-------------------------------------------------------------------------------------

Course.h

#ifndef COURSE_H #define COURSE_H

class Course { public: Course(int=0, int=0, int=0, string=""); void print();

private: int code; // course code, for example 2404 for COMP2404 int grade; // numeric grade from 0 (F) to 12 (A+), with -1 for WDN int term; string instructor; void getGradeStr(string&); };

#endif ---------------------------------------------------------------------------------------------------------

Student.cc

#include #include #include using namespace std;

#include "Student.h"

Student::Student(int i) { id = i; numCourses = 0; }

Student::~Student() { for (int i=0; i

void Student::addCourse(Course* tmpCourse) { courses[numCourses] = tmpCourse; ++numCourses; }

void Student::print() { cout

for (int i=0; iprint(); } ---------------------------------------------------------------------------------------

Student.h

#ifndef STUDENT_H #define STUDENT_H

#include "defs.h" #include "Course.h" #include "List.h"

class Student { public: Student(int=0); ~Student(); void addCourse(Course*); void print();

private: int id; List& list1; int numCourses; };

#endif -------------------------------------------------------------------------------------------------

Storage.cc

#include #include #include using namespace std;

#include "Storage.h"

Storage::Storage(int n) { numStudents = 0;

}

Storage::~Storage() {

} void Storage::addStu(Student* pt) { // if number of students equals maximum capacity, print max storage if(numStudents == MAX_SIZE_ARRAY){ cout

for(int i = 0; i = numStudents){ ptr[i] = pt; numStudents++; } } } } void Storage::print() {

// prints out storage for (int i=0; iprint(); } ----------------------------------------------------------------------------

Storage.h

#ifndef STORAGE_H #define STORAGE_H #define MAX_SIZE_ARRAY 128

#include "Course.h" #include "Student.h"

class Storage { public: Storage(int n); ~Storage(); void addStu(Student* pt); void print();

private: Student *ptr[MAX_SIZE_ARRAY]; int numStudents; };

#endif ----------------------------------------------------------------------------------

Makefile

OPT = -Wall

A2: Student.o Course.o Storage.o defs.h List.o View.o Control.o g++ $(OPT) -o A2 Student.o Course.o Storage.o defs.h List.o View.o Control.o

Student.o: Student.cc Student.h Course.h List.h defs.h g++ $(OPT) -c Student.cc

Course.o: Course.cc Course.h g++ $(OPT) -c Course.cc

List.o: List.cc List.h Control.h g++ $(OPT) -c List.cc

View.o: View.cc View.h Control.h Student.h Course.h g++ $(OPT) -c View.cc

Control.o: Control.cc Control.h View.h g++ $(OPT) -c Control.cc

clean: rm -f *.o t01

Instructions 1. Draw a UML diagram: using a drawing package of your choice, draw a UML class diagram for your code from Assignment #1 or for the base code. Remember, functions are not classes, so main) is not a class! Now add a Control class that will be responsible for all control flow, and a view class to deal with all user I/O. Think about what functions will be required in each class. You must keep adding to your diagram as you modify the code in each of the steps below. Your UML diagram should reflect the design of the entire program for this assignment. 2. Implement the Control class You will create a new Control class that implements the control flow from the main) function. The Control class will contain: .a data member for the storage object that used to be declared in main() .a data member for a new view object that will be responsible for user I/O a launch) member function that implements the program control flow and does the following: use the view object to display the main menu and read the user's selection, until the user chooses to exit o o if required by the user use the view object to read in all the student and course information, create a new dynamically allocated Student object, containing the corresponding dynamically allocated course objects - add the new student to storage using existing functions o use the view object to print the content of the storage to the screen at the end of the program The control class will perform all user VO using the view class. It will not interact with the user directly. You will change the main) function so that its only responsibility is to declare a Control object and call its 1aunch function. 3. Implement the View class contain .a member function for displaying the main menu and reading the user's selection a member function for reading the student id .a member function for reading all the information from the user about one course .a member function for printing out the storage; this function will take a Storage object as parameter by reference, and it will use delegation, as seen in Tutorial #3, to ask the storage class to print to the screen Except for printing the storage at the end of the program, only the view class will interact with the user. You must change the program so that user I/O goes through this class. After the Control and view classes are correctly implemented, your code should have no global functions other than main() 4. Modify the Course class You will modify the Course class to add a new member function that compares two courses. The new member function will have the prototype bool lessThan (Course*), and it will compare the given parameter with the Course object on which the function is called. The lesser of two courses is the one with the lower course code. If two courses have the same course code, the lesser course is the one with the lesser term. This function requires the new course class data member called term from Assignment #1 5. Implement the List clas:s You will create a new List class that holds a singly linked list of Course pointers. You will implement the linked list as we saw in class, with no dummy nodes. The List class will contain the following: . a data member for the head of the list .a data member for the tail of the list a constructor . a destructor to clean up the dynamically allocated memory . a member function with the prototyne void add (Course) that adds a new course to the list with the lower course code. If two courses have the same course code, the lesser course is the one with the lesser term. This function requires the new course class data member called term from Assignment # 5. Implement the List class You will create a new List class that holds a singly linked list of course pointers. You will implement the linked list as we saw in class, with no dummy nodes. The List class will contain the following: . a data member for the head of the list .a data member for the tail of the list a constructor a destructor to clean up the dynamically allocated memory . a member function with the prototype void add (Course) that adds a new course to the list the new course will be added in its correct position in the list, in ascending (increasing) order by course, using the Course class's lessThan) function you will need to implement a Node class, as we saw in class . a print ) member function that prints the courses to the screen after all data is printed, indicate which course is at the head and which course is at the tail Change the student class to use a new List object instead of the course array. It will no longer need to track the number of courses. There should be zero impact on existing classes because of this change. 6. Test the program You will modify the in.txt file so that it provides sufficient datafill for a minimum of 15 students, each with at least 5 courses. The ordering in the file of each student's courses must be such that the program is thoroughly tested. Check that the student and course information is correct when the storage is printed out. Make sure that all dynamically allocated memory is explicitly deallocated when it is no longer used. Use valgrind to check for memory leaks Instructions 1. Draw a UML diagram: using a drawing package of your choice, draw a UML class diagram for your code from Assignment #1 or for the base code. Remember, functions are not classes, so main) is not a class! Now add a Control class that will be responsible for all control flow, and a view class to deal with all user I/O. Think about what functions will be required in each class. You must keep adding to your diagram as you modify the code in each of the steps below. Your UML diagram should reflect the design of the entire program for this assignment. 2. Implement the Control class You will create a new Control class that implements the control flow from the main) function. The Control class will contain: .a data member for the storage object that used to be declared in main() .a data member for a new view object that will be responsible for user I/O a launch) member function that implements the program control flow and does the following: use the view object to display the main menu and read the user's selection, until the user chooses to exit o o if required by the user use the view object to read in all the student and course information, create a new dynamically allocated Student object, containing the corresponding dynamically allocated course objects - add the new student to storage using existing functions o use the view object to print the content of the storage to the screen at the end of the program The control class will perform all user VO using the view class. It will not interact with the user directly. You will change the main) function so that its only responsibility is to declare a Control object and call its 1aunch function. 3. Implement the View class contain .a member function for displaying the main menu and reading the user's selection a member function for reading the student id .a member function for reading all the information from the user about one course .a member function for printing out the storage; this function will take a Storage object as parameter by reference, and it will use delegation, as seen in Tutorial #3, to ask the storage class to print to the screen Except for printing the storage at the end of the program, only the view class will interact with the user. You must change the program so that user I/O goes through this class. After the Control and view classes are correctly implemented, your code should have no global functions other than main() 4. Modify the Course class You will modify the Course class to add a new member function that compares two courses. The new member function will have the prototype bool lessThan (Course*), and it will compare the given parameter with the Course object on which the function is called. The lesser of two courses is the one with the lower course code. If two courses have the same course code, the lesser course is the one with the lesser term. This function requires the new course class data member called term from Assignment #1 5. Implement the List clas:s You will create a new List class that holds a singly linked list of Course pointers. You will implement the linked list as we saw in class, with no dummy nodes. The List class will contain the following: . a data member for the head of the list .a data member for the tail of the list a constructor . a destructor to clean up the dynamically allocated memory . a member function with the prototyne void add (Course) that adds a new course to the list with the lower course code. If two courses have the same course code, the lesser course is the one with the lesser term. This function requires the new course class data member called term from Assignment # 5. Implement the List class You will create a new List class that holds a singly linked list of course pointers. You will implement the linked list as we saw in class, with no dummy nodes. The List class will contain the following: . a data member for the head of the list .a data member for the tail of the list a constructor a destructor to clean up the dynamically allocated memory . a member function with the prototype void add (Course) that adds a new course to the list the new course will be added in its correct position in the list, in ascending (increasing) order by course, using the Course class's lessThan) function you will need to implement a Node class, as we saw in class . a print ) member function that prints the courses to the screen after all data is printed, indicate which course is at the head and which course is at the tail Change the student class to use a new List object instead of the course array. It will no longer need to track the number of courses. There should be zero impact on existing classes because of this change. 6. Test the program You will modify the in.txt file so that it provides sufficient datafill for a minimum of 15 students, each with at least 5 courses. The ordering in the file of each student's courses must be such that the program is thoroughly tested. Check that the student and course information is correct when the storage is printed out. Make sure that all dynamically allocated memory is explicitly deallocated when it is no longer used. Use valgrind to check for memory leaks

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions

Question

pls help me out thanks

Answered: 1 week ago