展开全部
#include<iostream>
using namespace std;
class CStudent
{
public:
//构造函数
CStudent(string xh,string nm,int s)
{
ID=xh;
Name=nm;
Score=s;
}
//声明本类的友元函数和友元类
friend void Display(CStudent& s);
friend class CTeacher;
private:
string ID,Name;
int Score;
};
void Display(CStudent& s)
{
int sp=20-s.Name.length()/2;
string level,str;
str.append(sp,' ');
cout<<str<<s.Name;
str.assign(40-s.Name.length()-sp,' ');
cout<<str<<" "<<s.Score<<" ";
switch(s.Score/10)
{
case 10:
case 9:
level="优秀";
break;
case 8:
level="良好";
break;
case 7:
level="中等";
break;
case 6:
level="及格";
break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:
level="不及格";
break;
}
str.assign(20-level.length()/2,' ');
cout<<str<<level<<endl;
}
class CTeacher
{
public:
void Modify(CStudent& s)
{
s.Score=60;
}
void Display(CStudent& s)
{
//调用全局的Display函数
::Display(s);
}
};
int main(int argc,char *argv[])
{
int i;
string str;
CStudent stus[4]={ CStudent("160620211","LeBron Jams",75),
CStudent("160620212","Michael Jordan",98),
CStudent("160620213","Chris Bosh",55),
CStudent("160620214","Stephen Curry",80)
};
CTeacher t;
str.assign(18,' ');
cout<<str<<"姓名"<<str<<"成绩"<<str<<"等级"<<endl;
for(i=0;i<4;i++)
{
Display(stus[i]);
}
cout<<endl;
//修改Chris Bosh的成绩
t.Modify(stus[2]);
t.Display(stus[2]);
system("PAUSE");
return 0;
}
using namespace std;
class CStudent
{
public:
//构造函数
CStudent(string xh,string nm,int s)
{
ID=xh;
Name=nm;
Score=s;
}
//声明本类的友元函数和友元类
friend void Display(CStudent& s);
friend class CTeacher;
private:
string ID,Name;
int Score;
};
void Display(CStudent& s)
{
int sp=20-s.Name.length()/2;
string level,str;
str.append(sp,' ');
cout<<str<<s.Name;
str.assign(40-s.Name.length()-sp,' ');
cout<<str<<" "<<s.Score<<" ";
switch(s.Score/10)
{
case 10:
case 9:
level="优秀";
break;
case 8:
level="良好";
break;
case 7:
level="中等";
break;
case 6:
level="及格";
break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:
level="不及格";
break;
}
str.assign(20-level.length()/2,' ');
cout<<str<<level<<endl;
}
class CTeacher
{
public:
void Modify(CStudent& s)
{
s.Score=60;
}
void Display(CStudent& s)
{
//调用全局的Display函数
::Display(s);
}
};
int main(int argc,char *argv[])
{
int i;
string str;
CStudent stus[4]={ CStudent("160620211","LeBron Jams",75),
CStudent("160620212","Michael Jordan",98),
CStudent("160620213","Chris Bosh",55),
CStudent("160620214","Stephen Curry",80)
};
CTeacher t;
str.assign(18,' ');
cout<<str<<"姓名"<<str<<"成绩"<<str<<"等级"<<endl;
for(i=0;i<4;i++)
{
Display(stus[i]);
}
cout<<endl;
//修改Chris Bosh的成绩
t.Modify(stus[2]);
t.Display(stus[2]);
system("PAUSE");
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询