Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// COURSE.CC ////////////////////// #include #include #include using namespace std; #include Course.h Course::Course(int c, int g) { code = c; grade = g; } void Course::setCode(int

image text in transcribedimage text in transcribed

// COURSE.CC //////////////////////

#include #include #include using namespace std;

#include "Course.h"

Course::Course(int c, int g) { code = c; grade = g; }

void Course::setCode(int c) { code = c; }

void Course::setGrade(int g) { grade = g; }

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); void setCode(int); void setGrade(int); 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 void getGradeStr(string&); };

#endif

// DEFS.H //////////////////////

#ifndef DEFS_H #define DEFS_H

#define MAX_NUM_STU 256 #define MAX_NUM_COURSES 64

#endif

// MAIN. CC //////////////////////

#include using namespace std; #include

#include "defs.h" #include "Student.h"

int mainMenu(); void printStorage(Student stuArr[MAX_NUM_STU], int);

int main() { Student students[MAX_NUM_STU]; int numStu = 0; int numCourses; int stuId, courseCode, grade; int menuSelection;

while (1) { menuSelection = mainMenu();

if (menuSelection == 0) break;

else if (menuSelection == 1) {

cout > stuId; students[numStu].setId(stuId); numCourses = 0;

while (1) { cout : "; cin >> courseCode; if (courseCode == 0) break; cout > grade;

students[numStu].setCourse(numCourses, courseCode, grade); ++numCourses; } students[numStu].setNumCourses(numCourses); ++numStu; } }

if (numStu > 0) printStorage(students, numStu);

return 0; }

int mainMenu() { int numOptions = 1; int selection = -1;

cout

while (selection numOptions) { cout > selection; }

return selection; }

void printStorage(Student stuArr[MAX_NUM_STU], int numStu) { cout

for (int i=0; i

cout

// STUDENT.CC ///////

#include #include #include using namespace std;

#include "Student.h"

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

for (int i=0; i

void Student::setId(int i) { id = i; }

void Student::setNumCourses(int n) { numCourses = n; }

void Student::setCourse(int index, int code, int grade) { courses[index].setCode(code); courses[index].setGrade(grade); }

void Student::print() { cout

for (int i=0; i

// STUDENT.h ////////////

#ifndef STUDENT_H #define STUDENT_H

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

class Student { public: Student(int=0); void setId(int); void setCourse(int, int, int); void setNumCourses(int); void print();

private: int id; Course courses[MAX_NUM_COURSES]; int numCourses; };

#endif

// MAKEFILE //////////

sas: main.o Student.o Course.o g++ -o sas main.o Student.o Course.o

main.o: main.cc Student.h defs.h g++ -c main.cc

Student.o: Student.cc Student.h Course.h defs.h g++ -c Student.cc

Course.o: Course.cc Course.h g++ -c Course.cc

clean: rm -f *.o sas

// in.txt

1 1023 1405 3 1406 5 1805 -1 2401 8 2402 0 0 1 1024 1405 0 1405 7 1406 10 1805 0 0 1 1032 1405 9 1406 11 1805 4 2402 7 2406 12 2401 6 2404 5 0 0 0

2. Modify the Course class You will be adding new data members to the Course class, and you will be changing its member functions accordingly. You wll also be removing some functions no longer needed because a later part of this assignment will require that you allocated course objects dynamically instead of statically. Modify the course class as follows -add two data members: the term when the course was taken, and the name of the course instructor the term will be represented as an integer, using the Carleton University standard format YYYYTT, o where YYYY is the four-digit year, and TT represents the term, which is 10 for winter, 20 for summer, and 30 for fall; for example, winter 2019 would be represented as 201910 o the course instructor can be represented as a string modify the constructor so that it initializes the new data members from parameters modify the print) function to print out the new data members remove the setGrade) and setCode ) functions, as your code will no longer use them once Course objects are dynamically allocated 3. Modify the Student class You will modify the Student class to work with dynamically allocated Course objects, instead of statically allocated ones, and you will remove some member functions that are no longer needed. Modify the Student class as follows modify the courses data member so that it holds a primitive array of Course pointers instead of Course objects modify the constructor so that it no longer initializes the course array; it still needs to initialize the other data members write a destructor to clean up the dynamically allocated Course objects write the addCourse) function that adds a course to the back (the end) of the array; the function will have the prototype: void addCourse (Course modify the print) function to work with Course pointers instead of objects remove the set Id() , setCourse () , and setNunCourses () functions, as your code will no longer use them 4. Implement the Storage class You will create a new class called Storage. This class will contain all the student information stored in the program. The Storage class will contain the following a collection of students, represented as an array of Student pointers the number of students currently in storage . a constructor - a destructor to clean up the dynamically allocated student objects - an addstu (Student) member function that adds a new student to the back of the array a print member function that prints out all the student information to the screen; the printed information must include all student data, including the student's course information; you must reuse existing functions to do this 5. Modify the main) function You will modify the program so that the main function: doesn't declare an array of students anymore; instead, it will declare a Storage object prompts the user to enter the student id, and dynamically allocates a student object prompts the user to enter the data for the student's courses, including the new data members that you added for instruction #2; for each course, the main ( ) function: dynamically allocates a new Course object with the user entered data o o adds the new course to the student object using existing functions - adds the student to storage using functions implemented in previous steps prints the content of the storage using a member function of that object NOTES The main) function will no longer be manipulating the students or the array directly; it will use the storage object and its member functions instead . The printstorage) global function will no longer be needed and must be removed

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

DB2 9 For Linux UNIX And Windows Advanced Database Administration Certification Certification Study Guide

Authors: Roger E. Sanders, Dwaine R Snow

1st Edition

1583470808, 978-1583470800

More Books

Students also viewed these Databases questions