Question
// 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
// COURSE.CC //////////////////////
#include
#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
#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 "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
Step 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