#include<iostream>
#include<cstring>
using namespace std;
class Stu
{
private:
string name; //学生姓名
float chinese; //语文成绩
float math; //数学成绩
//接下去写
public:
void setStudent(string a,int m,int n);
void show();
void setName(string b);
string getName();
double average();
};
int main()
{
Stu s1,s2;
s1.setStudent("Lin daiyu", 98, 96); //对象置初值
s2.setStudent("Jia baoyu", 90, 88); //对象置初值
s1.show();//打印信息
s2.show();//打印信息
s1.setName("xue baochai");//重新置p1对象的名字
s1.show();
cout<<"s1.Name: "<<s1.getName()<<endl;//打印对象的名字
cout<<"s1.average: "<<s1.average()<<endl;//打印对象的成绩
return 0;
}
void Stu::setStudent(string a,int m,int n)
{
name=a;
chinese=m;
math=n;
}
void Stu::show()
{
cout<<"Name"<<name<<endl;
cout<<"Score"<<chinese<<" "<<math<<endl;
cout<<"average"<<(chinese+math)/2<<" "<<"sum"<<(chinese+math)<<endl;
}
void Stu::setName(string b)
{
name=b;
}
double Stu::average()
{
return (chinese+math)/2;
}
string Stu::getName()
{
return name;
}
第3周项目4考了语文数学的学生
最新推荐文章于 2021-05-24 10:11:00 发布