Question
Please fix my code in C++ below, I cant get it to compile. Please fix it to have a functioning output. #include #ifndef COURSE_H #define
Please fix my code in C++ below, I cant get it to compile. Please fix it to have a functioning output.
#include
class Course { private: std::string stdID; int units; char grade;
public: Course(); Course(std::string stdID, int units, char grade); void set_Units(int units); void set_Grade(char grade); std::string getID() const; int get_Units() const; char get_Grade() const; int get_GP() const; }; #endif
#include
Course::Course(): stdID(""), units(0), grade(' ') {}
Course::Course(std::string stdID, int units, char grade) : stdID(stdID), units(units), grade(grade) { grade = toupper(grade); } void Course:: set_Units(int units){ this->units = units; }
void Course:: set_Grade(char grade){ this->grade = toupper(grade); } std::string Course:: getID() const{ return stdID; }
int Course:: get_Units() const{ return units; }
char Course:: get_Grade() const{ return grade; } int Course:: get_GP() const{ if(grade == 'A') return units * 4; else if(grade == 'B') return units * 3; else if(grade == 'C') return units * 2; else if(grade == 'D') return units; return 0; }
#include
class Student { private: std::string stdName; int studentID; std::vector
public: Student(); Student(std::string stdName); void set_Name(std::string stdName); std::string get_Name() const; int get_StudentID() const; void add_Courses(std::string stdID, int units, char grade); bool has_Courses() const; double get_GPA() const; void print_Transcript() const; }; #endif
#include
using namespace std;
int find_Std(vector
int main() { int choice; vector
students.push_back(Student(stdName)); cout << stdName << " you are registered! Student number is " << students[students.size()-1].get_StudentID() << endl; cout << " "; } else if(choice == 2) { cout << "Enter ID: "; cin >> stdID;
index = find_Std(students, stdID);
if(index == -1) { cout << "Sorry, " << stdID << " is not a valid student ID" << " " <
if(choice == 1) { cout << "Course ID? "; cin >> courseID; cout << "Units? "; cin >> units; cout << "Grade? "; cin >> grade;
students[index].add_Courses(courseID, units, grade); cout << " " << courseID << " added" << endl; cout << " "; } else if(choice == 2) { cout << "Your GPA is " << fixed << setprecision(2) << students[index].get_GPA() << endl; cout << " "; } else if(choice == 3) { students[index].print_Transcript(); cout << " "; } } while(choice != 4); } } } while(choice != 3);
return 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