C++ 1. 实现学生类,包含成员函数,姓名,学号,数学成绩,英语成绩,语文成绩。 用成员函数Set_data为其赋值,用Average函数计算每位同学的成绩平均值,用display函数显示每位同学的
1.实现学生类,包含成员函数,姓名,学号,数学成绩,英语成绩,语文成绩。 用成员函数Set_data为其赋值,用Average函数计算每位同学的成绩平均值,用display函数显示每位同学的成绩和平均值。
·
#include<iostream>
#include<string>
using namespace std;
class Student
{
public:
void Set_data()
{
cout << "please input the name num and the score of each class:" << endl;
cout << endl;
cin >> name >> num >> chin >> math >> eng;
}
int Average()
{
average = (math + eng + chin) / 3;
return average;
}
void display() {
cout << "姓名:" << name << endl << "各科成绩" << "chinese:" << " " << chin << "math:" << math << "english:" << eng << endl;
cout << "average:" << average << endl;
}
private:
string name;
double num;
double chin;
double math;
double eng;
double average;
};
Student stu1,stu2;
int main()
{
stu1.Set_data();
stu1.Average();
stu1.display();
cout << "please input the next student's information " << endl;
stu2.Set_data();
stu2.Average();
stu2.display();
return 0;
}
更多推荐
所有评论(0)