Code:
#include <iostream>
#include <string>
using namespace std;
class courseTranscript
{
private:
string dept;
string courseNum;
string courseTitle;
int courseCredit;
char grade;
public:
void setDept(string d);
string getDept(void);
void setCourseNum(string n);
string getCourseNum(void);
void setCourseTitle(string t);
string getCourseTitle(void);
void setCourseCredit(int c);
int getCourseCredit(void);
void setGrade(char g);
char getGrade(void);
};
class student
{
private:
string firstName;
string lastName;
int studentID;
string ssn;
string dob;
string major;
courseTranscript transcripts[50];
int numCourseTaken;
public:
student();
student(string fn, string ln, int id, string ssn);
void setFirstName(string fn);
string getFirstName(void);
void setLastName(string ln);
string getLastName(void);
void setStudentID(int id);
int getStudentID(void);
void setSSN(string ssn);
string getSSN(void);
void setDOB(string dob);
string getDOB(void);
void setMajor(string m);
string getMajor(void);
void setNumCourseTaken(int nct);
int getNumCourseTaken(void);
void AddToTranscripts(string d, string n, string t, int c, char g);
void printTranscript(void);
void printCourses(void);
double getGPA();
courseTranscript getTranscript(int index);
};
class athlete : public student
{
private:
string sports;
public:
athlete();
athlete(string fn, string ln, int id, string ssn, string s);
void setSports(string s);
string getSports(void);
void printTranscript(void);
};
int main(void)
{
student newstudent;
student anotherstudent("John", "Smith", 1234, "123-45-6789");
athlete stu3("Jim", "Smith", 3456, "345-67-8901", "Basketball");
newstudent.setFirstName("Jane");
newstudent.setLastName("Smith");
newstudent.setSSN("234-56-7890");
newstudent.setStudentID(2345);
newstudent.setDOB("01/01/1980");
newstudent.setMajor("Computer Science");
newstudent.AddToTranscripts("ITS", "2591", "C++ Programming I", 4, 'A');
newstudent.AddToTranscripts("ITS", "1040", "System Analysis and Designs", 3, 'B');
newstudent.AddToTranscripts("ITS", "1110", "Programming Logic, Designs, and Development", 3, 'A');
stu3.AddToTranscripts("ITS", "2591", "C++ Programming I", 4, 'A');
stu3.AddToTranscripts("ITS", "1040", "System Analysis and Designs", 3, 'B');
newstudent.printTranscript();
anotherstudent.printTranscript();
stu3.printTranscript();
return 0;
}
// couseTranscript functions
void courseTranscript::setDept(string d)
{
dept = d;
}
string courseTranscript::getDept(void)
{
return dept;
}
void courseTranscript::setCourseNum(string n)
{
courseNum = n;
}
string courseTranscript::getCourseNum(void)
{
return courseNum;
}
void courseTranscript::setCourseTitle(string t)
{
courseTitle = t;
}
string courseTranscript::getCourseTitle(void)
{
return courseTitle;
}
void courseTranscript::setCourseCredit(int c)
{
courseCredit = c;
}
int courseTranscript::getCourseCredit(void)
{
return courseCredit;
}
void courseTranscript::setGrade(char g)
{
grade = g;
}
char courseTranscript::getGrade(void)
{
return grade;
}
// Student functions
student::student()
{
firstName = "Jon";
lastName = "Doe";
studentID = 0000;
ssn = "0000-00-0000";
dob = "00/00/0000";
major = "Undefined";
numCourseTaken = 0;
}
student::student(string fn, string ln, int id, string ssn)
{
firstName = fn;
lastName = ln;
studentID = id;
ssn = ssn;
}
void student::setFirstName(string fn)
{
firstName = fn;
}
string student::getFirstName(void) {
return firstName;
}
void student::setLastName(string ln)
{
lastName = ln;
}
string student::getLastName(void)
{
return lastName;
}
void student::setStudentID(int id)
{
studentID = id;
}
int student::getStudentID(void)
{
return studentID;
}
void student::setSSN(string ssn)
{
ssn = ssn;
}
string student::getSSN(void)
{
return ssn;
}
void student::setDOB(string dob)
{
dob = dob;
}
string student::getDOB(void)
{
return dob;
}
void student::setMajor(string m)
{
major = m;
}
string student::getMajor(void)
{
return major;
}
void student::setNumCourseTaken(int nct)
{
numCourseTaken = nct;
}
int student::getNumCourseTaken(void)
{
return numCourseTaken;
}
void student::AddToTranscripts(string d, string n, string t, int c, char g)
{
transcripts[numCourseTaken].setDept(d);
transcripts[numCourseTaken].setCourseNum(n);
transcripts[numCourseTaken].setCourseTitle(t);
transcripts[numCourseTaken].setCourseCredit(c);
transcripts[numCourseTaken].setGrade(g);
numCourseTaken++;
}
void student::printTranscript()
{
cout << "Name : " << getFirstName() << " " << getLastName() << endl;
cout << "SSN : " << getSSN() << endl;
cout << "DOB : " << getDOB() << endl;
cout << "Major : " << getMajor() << endl;
cout << "Number of courses taken : " << getNumCourseTaken() << endl << endl;
printCourses();
}
double student::getGPA()
{
double gpa;
double grade;
double totalpoints = 0;
double totalcredits = 0;
for (int i = 0; i < numCourseTaken; i++)
{
switch (transcripts[numCourseTaken].getGrade())
{
case 'A':
case 'a': grade = 4.0;
break;
case 'B':
case 'b': grade = 3.0;
break;
case 'C':
case 'c': grade = 2.0;
break;
case 'D':
case 'd': grade = 1.0;
break;
default: grade = 0.0;
}
totalcredits = totalcredits + transcripts[numCourseTaken].getCourseCredit();
totalpoints = totalpoints + (grade * transcripts[numCourseTaken].getCourseCredit());
}
gpa = totalpoints / (totalcredits * numCourseTaken);
return gpa;
}
void student::printCourses(void)
{
for (int i = 0; i < numCourseTaken; i++)
{
cout << "Dept: " << transcripts[numCourseTaken].getDept() << endl;
cout << "Course Num: " << transcripts[numCourseTaken].getCourseNum() << endl;
cout << "Course Title: " << transcripts[numCourseTaken].getCourseTitle() << endl;
cout << "Course Credit: " << transcripts[numCourseTaken].getCourseCredit() << endl;
cout << "Grade: " << transcripts[numCourseTaken].getGrade() << endl;
cout << "GPA: " << getGPA();
}
}
courseTranscript student::getTranscript(int index)
{
return transcripts[index];
}
// Athlete functions
void athlete::setSports(string s)
{
sports = s;
}
string athlete::getSports(void)
{
return sports;
}
athlete::athlete()
{
sports = "Sports Undefined";
}
athlete::athlete(string fn, string ln, int id, string ssn, string s) : student(fn, ln, id, ssn)
{
sports = s;
getTranscript(getNumCourseTaken()).setDept("WFS");
getTranscript(getNumCourseTaken()).setCourseNum("1050");
getTranscript(getNumCourseTaken()).setCourseTitle("Coed Team Sports and Activities");
getTranscript(getNumCourseTaken()).setCourseCredit(1);
getTranscript(getNumCourseTaken()).setGrade('A');
}
void athlete::printTranscript()
{
cout << "Name : " << getFirstName() << " " << getLastName() << endl;
cout << "SSN : " << getSSN() << endl;
cout << "DOB : " << getDOB() << endl;
cout << "Major : " << getMajor() << endl;
cout << "Number of courses taken : " << getNumCourseTaken() << endl;
cout << "STUDENT ATHLETE" << endl << endl;
printCourses();
}