#include <iostream.h>
#include <string.h>
#include <iomanip.h>
class student
{char name[8];
int deg;
char level[7];
friend class process; // 说明友元类
public:
student(char na[],int d)
{ strcpy(name,na);
deg=d;
}
};
class process
{ public:
void trans(student &s)
{int i=s.deg/10;
switch(i)
{case 9:
strcpy(s.level, "优");break;
case 8:
strcpy(s.level,"良");break;
case 7:
strcpy(s.level,"中");break;
case 6:
strcpy(s.level,"及格");break;
default:
strcpy(s.level,"不及格");
}
}
void show(student &s)
{cout<<setw(10)<<s.name<<setw(4)<<s.deg<<setw(8)<<s.level<<endl;}
};
void main()
{ student st[]={student("张三",78),student("李四",92),student("王五
",62),student("孙六",88)};
process p;
cout<<"结 果:"<<"姓名"<<setw(6)<<"成绩"<<setw(8)<<"等级"<<endl;
for(int i=0;i<4;i++)
{ p.trans(st[i]);
p.show(st[i]);}
}
|