In: Computer Science
using c plus plus: THE PROGRAMS SHOULD 3 DIFFERENT PARTS AS MAIN, STUDENTTYPE.H AND STUDENTTYPELMP.CPP. I ALWAYS GRADE MY ANSWERS. THANKS.
Chapter 9 defined the struct studentType to implement the basic properties of a student. Define the class studentType with the same 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.
Struct studentType:
struct studentType { string firstName; string lastName; char courseGrade; int testScore; int programmingScore; double GPA; };
An example of the program is shown below:
Name: Sara Spilner Grade: A Test score: 89 Programming score: 92 GPA: 3.57
Code
STUDENTTYPE.H
#ifndef _STUDENTTYPE_H
#define _STUDENTTYPE_H
#include<string>
#include<iostream>
using namespace std;
class studentType
{
public:
studentType(string,string,char,int,int,double);
void setFirstname(string);
void setLastname(string);
void setCourseGrade(char);
void setTestScore(int);
void setProgramingScore(int);
void setGPA(double);
string getFirstname();
string getLastname();
char getCourseGrade();
int getTestScore();
int getProgramingScore();
double getGPA();
private:
string firstName;
string lastName;
char courseGrade;
int testScore;
int programmingScore;
double GPA;
};
#endif
STUDENTTYPELMP.CPP
#include"STUDENTTYPE.h"
studentType::studentType(string fn,string ln,char cg,int
tScore,int pScore,double gpa)
{
firstName=fn;
lastName=ln;
courseGrade=cg;
testScore=tScore;
programmingScore=pScore;
GPA=gpa;
}
char studentType::getCourseGrade()
{
return courseGrade;
}
string studentType::getFirstname()
{
return firstName;
}
string studentType::getLastname()
{
return lastName;
}
int studentType::getProgramingScore()
{
return programmingScore;
}
int studentType::getTestScore()
{
return testScore;
}
double studentType::getGPA()
{
return GPA;
}
void studentType::setCourseGrade(char cg)
{
courseGrade=cg;
}
void studentType::setFirstname(string fn)
{
firstName=fn;
}
void studentType::setGPA(double gpa)
{
GPA=gpa;
}
void studentType::setLastname(string ln)
{
lastName=ln;
}
void studentType::setTestScore(int tScore)
{
testScore=tScore;
}
void studentType::setProgramingScore(int pScore)
{
programmingScore=pScore;
}
Main.cpp
#include"STUDENTTYPE.h"
int main()
{
studentType st("Sara","Spilner",'A',89,92,3.57);
cout<<"Name:
"<<st.getFirstname()<<"
"<<st.getLastname()<<endl;
cout<<"Grade:
"<<st.getCourseGrade()<<endl;
cout<<"Test score:
"<<st.getTestScore()<<endl;
cout<<"Programming score:
"<<st.getProgramingScore()<<endl;
cout<<"GPA:
"<<st.getGPA()<<endl;
return 1;
}
output
If you have any query regarding the code please ask me in the
comment i am here for help you. Please do not direct thumbs down
just ask if you have any query. And if you like my work then please
appreciates with up vote. Thank You.