PLEASE WRITE THE CODE USING THE LANGUAGE OF C++. THANKS :) Design a class of Stu
ID: 3765214 • Letter: P
Question
PLEASE WRITE THE CODE USING THE LANGUAGE OF C++. THANKS :)
Design a class of Student that has the following attributes: Data members: name, Mathematics score and Chemistry score. Function members: A default constructor of no-argument, and another constructor that accepts actual arguments. One get method that returns the name. A compAveScore () function that computes and returns the average score, average score = (Mathematics score + Chemistry score)/2.0 In the main function, test the Student class as follows: Declare an array of three elements. Create three Student objects: a ("Bob", 60,70), ("John", 70, 80) and ("Janet", 80, 90). Assign three objects to the array. Loop through all objects, print out their names and average scores (call compAveScore such as: Bob 65 John 75 Janet 85Explanation / Answer
#include<iostream>
#include<vector>
#include<conio>
#include<string>
using namespace std;
class Student
{
public:
double math, che;
char name[20];
Student()
{
}
Student(char n[20], double m, double c)
{
strcpy(name,n);
math=m;
che=c;
}
void compAveScore()
{
double av=(math+che)/2.0;
cout<<name<<" "<<av<<endl;
}
};
class GradStudent : public Student
{
public:
double phy;
GradStudent()
{
phy=0;
}
GradStudent(char n[20],double p, double m, double c)
{
strcpy(name,n);
phy=p;
math=m;
che=c;
}
void compAveScore()
{
double av=(phy+math+che)/3.0;
cout<<name<<" "<<av<<endl;
}
};
void main()
{
int i;
vector<Student> v1;
vector<GradStudent> v2;
v1.push_back(a("Bob",60,70));
v1.push_back(b("John",70,80));
v2.push_back(c("Janet",77,88,99));
v2.push_back(d("Marie",82,92,99));
for(i=0;i<2;i++)
{
v1[i].compAveScore();
}
for(i=0;i<2;i++)
{
v2[i].compAveScore();
}
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.