c++老师布置的作业 急啊
发布网友
发布时间:2022-05-11 12:31
我来回答
共1个回答
热心网友
时间:2023-10-12 13:20
#include<iostream>
#include<string>
using namespace std;
class student
{
private:
int Number;
string Name;
intMath;
intEnglish;
int Computer;
int CLanguage;
int singletotal;
static intTotal;
static int MaxScore;
static int MinScore;
public:
student();
void Input();
static void Message();
void ComputeTotal();
static void Output(student a);
static void Caculate(student a);
static void Output2();
};
int student::MaxScore=0;
int student::MinScore=10000;
int student::Total=0;
student::student()
{
Math=English=CLanguage=Computer=singletotal=0;
}
void student::ComputeTotal()
{
singletotal+=(Math+English+CLanguage+Computer);
if (singletotal>MaxScore)
{
MaxScore=singletotal;
}
if (singletotal<MinScore)
{
MinScore=singletotal;
}
}
void student::Caculate(student a)
{
Total+=(a.Math+a.English+a.CLanguage+a.Computer);
}
void student::Message()
{
cout<<"请输入学生信息:"<<endl<<"学号"<<" "<<"姓名"<<" "<<"高数"<<" "<<"英语"<<" "<<"C"<<" "<<"计算机"<<endl;
}
void student::Input()
{
cin>>Number>>Name>>Math>>English>>CLanguage>>Computer;
ComputeTotal();
}
void student::Output(student a)
{
cout<<a.Number<<" "<<a.Name<<" "<<a.singletotal<<endl;
}
void student::Output2()
{
cout<<"平均分="<<Total/3<<endl;
cout<<"最高分="<<MaxScore<<endl;
cout<<"最低分="<<MinScore<<endl;
}
int main()
{
student a[3];
student::Message();
for (int i=0;i<3;i++)
{
a[i].Input();
student::Caculate(a[i]);
}
cout<<"学号"<<" "<<"姓名"<<" "<<"总分"<<endl;
for (int j=0;j<3;j++)
{
student::Output(a[j]);
}
student::Output2();
}
VS 2005 编译运行通过。