Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

P5.1 Given the following student class interface, a) implement all member functi

ID: 3806107 • Letter: P

Question

P5.1 Given the following student class interface, a) implement all member functions of the class, b) implement all non-member external functions of the class, and c) write a main() function to generate an output similar to the sample output appeared after the class interface. Notice that not all pre- and post-conditions for functions are provided; some are intentionally left out for you to fill in.

class student

{

public:

   student();

   student(string, int, double);

  

   void inputStuRec();

   // prompts the user to enter name (for simplicity, last name only), credits completed and GPA

        // Postcondition: Data mambers of the calling object is filled with values entered by the user

   void outputStuRec();

   // Postcondition: contents of the calling object is displayed in a format shown in the sample output

   void setName(string& str);

   // "Mutator" or "mutator function"

        // Postcondition: data member name of the calling object has been set to str

   void setCredits(int);

   void setGPA(double);

   void setStuRec(string, int, double);

   bool comapreName(student& obj2);

   // Name of the calling object is comapare to that of obj2

        // Postcondition: if calling object > obj2, returns true; otherwise, return false

   bool compareGPA(student& obj2);

   // GPA of the calling object is comapare to that of obj2

        // Postcondition: if calling object > obj2, returns true; otherwise, return false

   void swap(student& obj2);

   // Postcondition: contents of the calling object and obj2 are swapped

private:

   string name;     // Last name only

   int credits;

   double GPA;

};

// **** External functions ****

int fillStuArray(student[], int size);

// prompt the user to enter up to “size” (the capacity of the array) student records

// Postcondition: student array has been filled with n records with values entered by the user, where n <= size; the value of n is returned

void sortStuArrayByName(student[], int n);

// Postcondition: student array has been sorted by student name in alphabetical order

void displayStuReport(student[], int n);

// Postcondition: n student records stored in the student array are displayed

Explanation / Answer

void student::inputStuRec()

{

String name;

int credits;

double GPA;

cout<<"Enter Student Name:"

cin>>name;

cout<<"Enter credits completed:"

cin>>credits;

cout<<"Enter GPA:"

cin>>GPA;

}

void student::outputStuRec()

{

cout<<"The student details are:";

Cout<<"Name:"<<Name;

Cout<<"Credits:"<<Credits;

Cout<<"GPA:"<<GPA;

}

void student::setName(string& str)

{

String Name;

Name= &str;

}

void student::setCredits(int cred)

{

int credits;

credits=cred;

}

   void student::setGPA(double GP)

{

double GPA;

GPA=GP;

}

void student::setStuRec(string Name, int credits, double GPA)

{

String N;

N=Name;

Int c;

c=Credits;

Double G

G=GPA;

}

void main()

{

Student s1;

student s2;

s1.setName("XYZ");

s1.setCredits(24);

s1.setGPA(7);

s1.setStuRec("XYZ",24,7);

s2.setName("ABC");

s2.setCredits(24);

s2.setGPA(8);

s2.setStuRec("ABC",24,8);

}