Final answer:
A class 'StudentType' is created with the same elements as the given struct, but with private data members. Public member functions are added to manipulate the data, and a program is provided to demonstrate the class's usage.
Step-by-step explanation:
The requirement is to define a class studentType based on the previously defined struct studentType and to include private member variables along with public member functions for manipulating these variables. Below is a C++ class definition that models a student's basic properties and illustrates how to use it through an example program.
class StudentType {
private:
string firstName;
string lastName;
char courseGrade;
int testScore;
int programmingScore;
double GPA;
public:
// Constructors, accessors, and mutators
void setStudentInfo(string fName, string lName, char grade, int test, int programming, double gpa) {
firstName = fName;
lastName = lName;
courseGrade = grade;
testScore = test;
programmingScore = programming;
GPA = gpa;
}
// Add other necessary member functions here
// Example member function
void printStudentInfo() const {
cout << "Name: " << firstName << " " << lastName << endl;
cout << "Grade: " << courseGrade << endl;
cout << "Test score: " << testScore << endl;
cout << "Programming score: " << programmingScore << endl;
cout << "GPA: " << GPA << endl;
}
};
To use this class, we would instantiate an object of StudentType and use its member functions to set and retrieve student data. For example:
int main() {
StudentType student;
student.setStudentInfo("Paul", "Johnson", 'B', 79, 84, 3.24);
student.printStudentInfo();
return 0;
}
This simple program will output the information about the student, Paul Johnson, with the grade, test score, programming score, and GPA as provided.