Question
Please help fix my C++ code below, it does not compile. Please fix the necessary so that it would produce the functioning output below. //my
Please help fix my C++ code below, it does not compile. Please fix the necessary so that it would produce the functioning output below.
//my code
#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
//course.cpp:
#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){ units = units; }
void Course:: set_Grade(char grade){ 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; }
//student.h:
#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
//student.cpp:
#include
using namespace std; int Student::NextID = 1001;
Student::Student() : stdName("none"), studentID(NextID) { NextID++; }
Student::Student(std::string stdName) : stdName(stdName), studentID(NextID) { NextID++; }
void Student:: set_Name(std::string stdName){ stdName = stdName; } std::string Student:: get_Name() const{ return stdName; }
int Student:: get_StudentID() const{ return studentID; }
void Student:: add_Courses(std::string stdID, int units, char grade){ courses.push_back(Course(stdID, units, grade)); }
bool Student:: has_Courses() const{ return courses.size() > 0; }
double Student:: get_GPA() const{ if(!has_Courses()) return 0;
int total_Grade_Points = 0, total_Credits = 0;
for(Course c: courses){
total_Grade_Points += c.get_GP(); total_Credits += c.get_Units(); } return (double)total_Grade_Points/total_Credits; }
void Student:: print_Transcript() const{
if(!has_Courses()) cout
cout
//main.cpp:
#include
using namespace std;
int find_Std(vector
cout > choice; if(choice == 1) { cout
students.push_back(Student(stdName)); cout > stdID;
index = find_Std(students, stdID);
if(index == -1) cout > choice;
if(choice == 1) { cout > courseID; cout > units; cout > grade;
students[index].add_Courses(courseID, units, grade); cout
cout
cout
return 0; }
int find_Std(vector
for(size_t i=0;i
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