请为下~~~~~~~~~~~
用类实现把八个同学的名字,学号,性别及五门成绩存入档案,当输入一个合法的学号时,即能查询出该同学的情况.要求:
1,查询的结果为姓名,性别,五门课的总成绩.
2,名字,学号,性别及五门课成绩定义为学生类的私有成员.
(要求在Visual C++上编译,运行)
我曾经尝试用以下方法来实现,但他说必须用for才行,怎么办呢?
#include <iostream>
#include <string>
using namespace std;
class Student
{
int num1,num2,num3,num4,num5,num6,num7,num8;
char sex1,sex2,sex3,sex4,sex5,sex6,sex7,sex8;
string nam1,nam2,nam3,nam4,nam5,nam6,nam7,nam8;
int a1,a2,a3,a4,a5,a6,a7,a8,
b1,b2,b3,b4,b5,b6,b7,b8,
c1,c2,c3,c4,c5,c6,c7,c8,
d1,d2,d3,d4,d5,d6,d7,d8,
e1,e2,e3,e4,e5,e6,e7,e8,
a,b,c,d,e;
};
int main()
{
int num1=1,num2=2,num3=3,num4=4,num5=5,num6=6,num7=7;
int num8=8;
string sex1="m",sex2="m",sex3="m",sex4="m",sex5="f",sex6="m",sex7="f",sex8="f";
string nam1="ax",nam2="gy",nam3="gp",nam4="hrs",nam5="jr",nam6="qyx",nam7="bp",nam8="nr";
int a1=75,b1=83,c1=95,d1=94,e1=89,
a2=93,b2=76,c2=98,d2=86,e2=95,
a3=79,b3=88,c3=93,d3=79,e3=87,
a4=87,b4=89,c4=87,d4=79,e4=100,
a5=30,b5=38,c5=79,d5=46,e5=48,
a6=89,b6=95,c6=93,d6=88,e6=99,
a7=66,b7=76,c7=39,d7=58,e7=79,
a8=85,b8=83,c8=70,d8=50,e8=43,
t,k;
cin>>t;
k=t-1;
switch(k)
{case 0:cout<<num1<<" "<<nam1<<" "<<sex1<<" "<<a1+b1+c1+d1+e1<<endl;break;
case 1:cout<<num2<<" "<<nam2<<" "<<sex2<<" "<<a2+b2+c2+d2+e2<<endl;break;
case 2:cout<<num3<<" "<<nam3<<" "<<sex3<<" "<<a3+b3+c3+d3+e3<<endl;break;
case 3:cout<<num4<<" "<<nam4<<" "<<sex4<<" "<<a4+b4+c4+d4+e4<<endl;break;
case 4:cout<<num5<<" "<<nam5<<" "<<sex5<<" "<<a5+b5+c5+d5+e5<<endl;break;
case 5:cout<<num6<<" "<<nam6<<" "<<sex6<<" "<<a6+b6+c6+d6+e6<<endl;break;
case 6:cout<<num7<<" "<<nam7<<" "<<sex7<<" "<<a7+b7+c7+d7+e7<<endl;break;
case 7:cout<<num8<<" "<<nam8<<" "<<sex8<<" "<<a8+b8+c8+d8+e8<<endl;break;
default:cout<<"error"<<endl;
return 0;
}
}