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

defined the struct studentType to implement the basic propertiesofastudent.Defin

ID: 3749404 • Letter: D

Question

defined the struct studentType to implement the basic propertiesofastudent.Definetheclass studentTypewiththesame components as the struct studentType, and add member functions to manipulate the data members. (Note that the data members of the class studentType must be private.) Write a program to illustrate how to use the class studentType; refer to c++programming (7th edition chapter 10, problem 1pe in textbook solution. but as simplifed as possible

member functions:

string firstName;
string lastName;
char Grade;
int testScore;
int programmingScore;
double GPA;

Explanation / Answer

PROGRAM:

#include<iostream>

#include<cstdlib>

using namespace std;

struct studentType

{

string firstName;

string lastName;

char courseGrade;

int testScore;

int programmingScore;

double GPA;

};

class Student

{

private:string firstName;

string lastName;

char courseGrade;

int testScore;

int programmingScore;

double GPA;

public: void getData(studentType s) // create method for read data

{

// Read the class memebers

cout<<" Enter First Name: "; cin>>firstName;

cout<<" Enter Last Name: "; cin>>lastName;

cout<<" Test Score: "; cin>>testScore;

cout<<" Programming Score: "; cin>>programmingScore;

//assign class members to structure memebers

s.firstName =firstName;

s.lastName =lastName;

s.testScore =testScore;

s.programmingScore=programmingScore;

}

void calGPA(studentType s) // Create calculate gpa using this method

{

GPA=(double)(testScore+programmingScore)/6.0;

s.GPA=GPA;

if(s.GPA >=4.5) courseGrade='A';

else

if(s.GPA >=3.5&&s.GPA<4.5) courseGrade='B';

else

courseGrade='C';

s.courseGrade=courseGrade;

}

void showStudents(studentType s)

{

// assign class memebers to structure memebers

s.firstName =firstName;

s.lastName=lastName;

s.testScore =testScore;

s.programmingScore =programmingScore;

s.GPA = GPA;

s.courseGrade =courseGrade;

// Display the all the data of student

cout<<" First Name: "<<s.firstName;

cout<<" Last Name: "<<s.lastName;

cout<<" Test Course: "<<s.testScore;

cout<<" Programming Score: "<<s.programmingScore;

cout<<" GPA: "<<s.GPA;

cout<<" Course Grade: "<<s.courseGrade;

}

};

int main()

{

Student s;

struct studentType s1;

s.getData(s1);

s.calGPA(s1) ;

s.showStudents(s1) ;

return 0;

}

-------------------

OUTPUT:


Enter First Name: XXXX

Enter Last Name: YYYY

Test Score: 10

Programming Score: 12

First Name: XXXX
Last Name: YYYY
Test Course: 10
Programming Score: 12
GPA: 3.66667
Course Grade: B