C CODE GradStudents are Students but they have the additiona

C++ CODE

GradStudents are Students but they have the additional data member of researchArea.

Your program will loop asking for one of three options (add, print, or quit).

Add user option: You will create (using new) a Student object or a GradStudent object and add its pointer to the vector classMembers.

Print user option: You will print the entire class last, using the appropriate ToStr member function. You should NOT test whether a particular pointer in the class list points to a Student or a GradStudent. The correct ToStr function will be called automatically if you have properly defined functions for ToStr. \\

CODE!!

#include <iostream>
#include <string>
#include <vector>
using namespace std;

class Student {
public:
   Student(string initialName = \"No Name\") {
       name = initialName;
   }

   // Enter definition for a virtual ToStr member function here.

protected:
   string name;
};

class GradStudent : public Student {
public:
   // Enter definition for a paramteriezed contructor function here that sets both data members.

   // Enter definition for a virtual ToStr member function here.

private:
   string researchArea;
};

int main() {
   string usrOption;
   string inpName;
   string inpResearch;
   vector<Student*> classMembers;

   do {
       cout << \"Option: \";
       cin >> usrOption;
       cout << endl;
       if (usrOption == \"print\") {
           // Enter code here to print each member pointed to from classMembers using their respective ToStr member functions.
           }
       }

       else if (usrOption == \"add\") {
           cout << \"Name: \";
           cin >> inpName;
           cout << endl;
           cout << \"If grad student enter a one word research area, else enter \\\"NO\\\": \";
           cin >> inpResearch;
           cout << endl;
           if (inpResearch == \"NO\") {
               // Enter code here to create new objects (using new) for either a Student or a GradStudent
               // and add the pointer to the classMember vector.

           }
       }
   } while (usrOption != \"quit\");
   return 0;
}

Option add Name: Mary If grad student enter a one word research area, else enter \"NO\" MachineLearning Option add Name Bob If grad student enter a one word research area else enter NO NO Option print Mary is a graduate student researching the area of MachineLearning. Bob is an undergraduate student. Option quit

Solution

#include #include #include using namespace std; class Student { protected: int social; string name; public: Student (); // Default constructor Student(int ssn, string StudentName); void setSSN(int); int getSSN(); void setName(string); string getName(); virtual double calcGPA(); }; Student ::Student() { } Student::Student(int ssn, string StudentName) { social = ssn; name = StudentName; return; } void Student::setSSN(int SSN) { social = SSN; return; } int Student::getSSN() { return (social); } void Student::setName(string name2) { name = name2; return; } string Student::getName() { return name; } 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 setCreditHrs(int); void setQualityPts(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::setCreditHrs (int C) { CreditHrs = C; if (C < 0) CreditHrs = 0; return; } void UnderGradStudent::setQualityPts (int Q) { QualityPts = Q; if (Q < 0) QualityPts = 0; return; } int main() { char ans = \'n\', Status; string StudentName; int StudentSSN; int code, CreditHrs, points; Student* a = NULL; do { cout << \"Enter 1 for undergrad.\ Enter 2 for grad.\" << endl << \"-->\"; cin >> code; if (code == 1) { UnderGradStudent* ug; ug = new UnderGradStudent; a = ug; cin.ignore(); cout << \"Enter Student name: \"; getline(cin, StudentName); ug->setName (StudentName); cout << \"Enter Student SSN: \"; cin >> StudentSSN; ug->setSSN(StudentSSN); cout << \"Enter credit hours: \"; cin >> CreditHrs; ug->setCreditHrs(CreditHrs); cout << \"Enter quality points: \"; cin >> points; ug->setQualityPts(points); cout << endl; } else if (code == 2) { GradStudent * gs; gs = new GradStudent; a = gs; cin.ignore(); cout << \"Enter Student name: \"; getline(cin, StudentName); gs->setName(StudentName); cout << \"Enter Student SSN: \"; cin >> StudentSSN; gs->setSSN(StudentSSN); cout << \"Enter Status: \"; cin >> Status; gs->SetStatus(Status); cout << endl; } cout << \"\ Name: \" << a->getName() << \" SSN: \" << a->getSSN() << \" GPA: \" << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << a->calcGPA() << endl; delete a; a = NULL; cout << \"Continue?: \"; cin >> ans; cin.ignore(); cout << endl; } while (toupper(ans) == \'Y\'); return 0; }
C++ CODE GradStudents are Students but they have the additional data member of researchArea. Your program will loop asking for one of three options (add, print,
C++ CODE GradStudents are Students but they have the additional data member of researchArea. Your program will loop asking for one of three options (add, print,

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site