定义一个表示学生信息的类Student

2024-11-30 23:55:41
推荐回答(2个)
回答1:

#include
using namespace std;
class Student
{
int English;
int Computer;
int Total;
public:
Student(int en, int cp){English=en; Computer=cp; Total=en+cp;}
void Show()
{
cout<<"English:"< cout<<"Computer:"< cout<<"Total:"< }
};

int main()
{
Student S[3]={Student(90,100),Student(95,95),Student(80,85)};
for(int i=0;i<3;++i)
S[i].Show();
return 0;
}

回答2:

#include "stdafx.h"
#include
#include
#include

using namespace std;

class student
{
private:
float english;
float computer;
float total;
public:
int show()
{
cout<<"english:"< return 0;
};
student(float a,float b){
english=a;
computer=b;
total=english+computer;};
~student(){};
};
int _tmain(int argc, _TCHAR* argv[])
{
student S[3]={student(135,125),student(12,156),student(26,125)};

int i;

for(i=0;i<3;i++)
{
S[i].show();
}
return 0;

}

0warning 0error