Expand|Select|Wrap|Line Numbers
- #include <iostream>
- #include <iomanip>
- #include <string>
- using namespace std;
- const int SIZE = 80;
- class Student
- {
- protected:
- int social;
- string name;
- char *NamePtr;
- public:
- Student (int = 999999999 , char [] = "unassigned");
- void setSSN(long);
- long getSSN();
- void setName(char[]);
- char* getName();
- virtual double calcGPA();
- };
- Student::Student(int ssn, string studentname)
- {
- social = ssn;
- strcpy (name, studentname);
- }
- void Student::setSSN(int SSN)
- {
- social = SSN;
- return;
- }
- long Student::getSSN()
- {
- return (social);
- }
- void Student::setName(char name2)
- {
- strcpy (name, name2);
- return;
- }
- char* Student::getName()
- {
- NamePtr = name;
- return (NamePtr);
- }
- double Student::calcGPA()
- {
- cout << "Student calcGPA" << endl;
- return (0);
- }
- class GradStudent : public Student
- {
- private:
- char status;
- public:
- GradStudent (char = 'A');
- virtual double calcGPA();
- void SetStatus(char);
- };
- GradStudent::GradStudent(char grade)
- {
- status = grade;
- }
- double GradStudent::calcGPA()
- {
- double GPA = 0.0;
- if (status == 'A' || status == 'a')
- GPA = 4.0;
- cout << "GradStudent calcGPA";
- return (GPA);
- }
- void GradStudent::SetStatus (char stat)
- {
- status = stat;
- return;
- }
- class UnderGradStudent : public Student
- {
- private:
- double CreditHrs;
- double QualityPts;
- public:
- UnderGradStudent ( double = 0, double = 0);
- virtual double calcGPA ();
- void setCredits(int);
- void setQuality(int);
- };
- UnderGradStudent::UnderGradStudent(double Hours, double Points)
- {
- CreditHrs = Hours;
- QualityPts = Points;
- if (Hours < 0)
- CreditHrs = 0;
- if (Points < 0)
- QualityPts = 0;
- }
- double UnderGradStudent::calcGPA ()
- {
- double GPA = 0.0;
- if (CreditHrs > 0)
- GPA = QualityPts / CreditHrs;
- cout << "UnderGraduateStudent calcGPA";
- return (GPA);
- }
- void UnderGradStudent::setCredits (int C)
- {
- CreditHrs = C;
- if (C < 0)
- CreditHrs = 0;
- return;
- }
- void UnderGradStudent::setQuality (int Q)
- {
- QualityPts = Q;
- if (Q < 0)
- QualityPts = 0;
- return;
- }
- int main()
- {
- char ans = 'n';
- char grade;
- string StudentName;
- double StudentSSN;
- int choice, points, credits, continue;
- Student* a = NULL;
- do
- {
- cout << "Enter 1 for undergrad.\nEnter 2 for grad" << endl << "-->";
- cin >> choice;
- if (choice == 1)
- {
- a = new UnderGradStudent;
- cin.ignore();
- cout << "Please enter student name: ";
- cin.getline(StudentName, SIZE);
- a->setName(StudentName);
- }
- else if (choice == 2)
- {
- a = new GradStudent;
- cin.ignore();
- cout << "Please enter student name: ";
- cin.getline(StudentName, SIZE);
- a->setName(StudentName);
- }
- else continue;
- cout << "\nName: " << a->getName() << " SSN: " << a->getSSN() << " GPA: "
- << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << a->calcGPA() << endl;
- delete a;
- a = NULL;
- cout << "Continue?: ";
- cin >> continue;
- cin.ignore();
- cout << endl;
- }while (toupper(ans) == 'Y');
- cout << "Press ENTER to quit.";
- cin.ignore( 1000, '\n' );
- return 0;
- }