/*
*copyright(c) 2015,烟台大学计算机学院
*All rights reserved。
*文件名称:第三周(考语文的学生)
*作者:王忠
*完成日期:2015.3.25
*版本号:v1.0
*
*问题描述:输入学生姓名,各科成绩,改变学生姓名,在输出姓名,成绩,平均成绩。
*输入描述:输入学生姓名,各科成绩,改变学生姓名
*程序输出:输出姓名,成绩,平均成绩。
#include<iostream>
#include "stu.h"
using namespace std;
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;
}
#ifndef STU_H_INCLUDED
#define STU_H_INCLUDED
using namespace std;
class Stu
{
private:
string name; //学生姓名
float chinese; //语文成绩
float math; //数学成绩
//接下去写
public :
void setStudent(string a,int b,int c);
void show();
void setName(string p);
string getName();
double average();
};
#endif // STU_H_INCLUDED
#include<iostream>
#include "stu.h"
using namespace std;
void Stu::setStudent(string a,int b,int c)
{
name=a;
chinese=b;
math=c;
}
void Stu::show()
{
cout<<"Name: "<<name<<'\n'<<"Score: "<<chinese<<" "<<math<<endl;
}
void Stu::setName(string p)
{
name=p;
}
string Stu::getName()
{
return name;
}
double Stu::average()
{
double a;
a=(chinese+math)/2;
return a;
}