第一次用writer写blog,就发个作业题吧
来源:互联网 发布:匹夫无罪怀璧其罪 知乎 编辑:程序博客网 时间:2024/06/06 02:58
将这一次老师给的题目做出来了,本来老师没有讲STL,但是我在网上搜了点资料,感觉STL用起来很方便
// TestCStudent.cpp : 定义控制台应用程序的入口点。
//
/*-------------------------------------------------------------------
* Purpose:
* 设计一个学生类(CStudent)。要求如下:
* (1)数据成员是:学生的注册号、姓名、数学、外语、计算机课程的成绩
* (2)共有的函数成员是:求三门课程总成绩的函数Sum, 求三门课程平均成绩的函数Average,显示学生数据信息的函数Display,设置学生数据信息的函数SetData。
* (3)通过主函数从键盘对学生对象的数组(全班学生信息)进行输入,而后求出每一个学生的总成绩、平均成绩,并显示全班学生总成绩最高的学生的全部数据信息。
* Time:
* 2010年10月17日 17:8:50
* Author:
* 张彦升
--------------------------------------------------------------------*/
#include "stdafx.h"
#include "cstudent.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cstudent cs;
int StuNum;
string cname;
__int64 rgnum;
unsigned mscore;
unsigned cscore;
unsigned escore;
cout << "班级的总人数为:";
cin >> StuNum;
list
for (int i = 1;i <= StuNum;i++)
{
cout <<"依次输入第"< cin >> cname >> rgnum >> mscore >> cscore >> escore;
cstudent cs(cname,rgnum,mscore,cscore,escore);
student.push_back(cs);
}
list
cstudent First; //第一名,分数最高者
cout << left << setw(12)<< "姓名" << right<< setw(8) << "注册号" << / for (;itr != student.end();itr ++) /*------------------------------------------------------------------- #ifndef _CSTUDENT_H __int64 RegNum; //注册号码
setw(8) << "数学" <
{
cstudent temp = *itr;
temp.DisplayInfo();
cout<
if (First.TotalScore() < temp.TotalScore() )
{
First = temp;
}
}
cout << endl << endl << endl <<"成绩最高者的信息为:"<
setw(8) << "数学" <
cout <
}
* Purpose:
* cstudent.h
* Time:
* 2010年10月17日 17:16:56
* Author:
* 张彦升
--------------------------------------------------------------------*/
#define _CSTUDENT_H
#include
#include
#include
#include
#include
#include
using namespace std;
class cstudent
{
public:
/*cstudent()
{
name = "0";
RegNum = 0;
MathScore = 0;
ComputerScore = 0;
EnglishScore = 0;
}*/
cstudent(string sname = "0",__int64 regnum = 0,unsigned msore = 0,unsigned cscore = 0,unsigned escore = 0):name(sname),RegNum(regnum),MathScore(msore),ComputerScore(cscore),EnglishScore(escore){}
/*得到三门课的总成绩*/
unsigned TotalScore()const
{
//plus
return (MathScore + ComputerScore + EnglishScore);
}
/*得到三门成绩的平均分数*/
unsigned AverageScore()const
{
return (MathScore + ComputerScore + EnglishScore) /3;
}
void DisplayInfo()const
{
//cout << left << setw(12)<< "姓名" << right<< setw(8) << "注册号" << /
// setw(8) << "数学" <
void SetData(string& sname,unsigned long& regnum,unsigned& msore,unsigned& cscore,unsigned& escore)
{
name = sname;
RegNum = regnum;
MathScore = msore;
ComputerScore = cscore;
EnglishScore = escore;
return;
}
private:
string name; //学生的名字
unsigned MathScore; //数学成绩
unsigned ComputerScore; //计算机成绩
unsigned EnglishScore; //英语成绩
};
#endif /* _CSTUDENT_H */