};
intCat:
:
HowManyCats=0;
voidmain()
{
Cata;
a.GetHowMany();
Catb(a);
b.GetHowMany();
Catc;
c.GetHowMany();
}
P154T
(2) 友元实现学生成绩
#include
#include
classstudent
{
private:
charname[20];
floatEnglish_score;
floatComputerScience_score;
floatsum_score;
public:
student(charc[20],floatE_score,floatCS_score)
{
strcpy(name,c);
English_score=E_score;
ComputerScience_score=CS_score;
}
floatsum()
{
sum_score=English_score+ComputerScience_score;
returnsum_score;
}
friendvoidDescendingOrder(studentp1,studentp2);
};
voidDescendingOrder(studentp1,studentp2)
{
if(p1.sum()>p2.sum())
cout< else
cout<}
voidmain()
{
charc1[20],c2[20];
floatE_score1,CS_score1,E_score2,CS_score2;
cout<<"Pleaseenterastudent'sname:
";
cin>>c1;
cout<<"Pleaseenterthestudent'sEnglishscore:
"< cin>>E_score1;
cout<<"Pleaseenterthestudent's ComputerSciencescore!
"< cin>>CS_score1;
studentm(c1,E_score1,CS_score1);
cout<<"Pleaseenteranotherstudent'sname!
"< cin>>c2;
cout<<"Pleaseenterthestudent'sEnglishscore!
"< cin>>E_score2;
cout<<"Pleaseenterthestudent's ComputerSciencescore!
"< cin>>CS_score2;
studentn(c2,E_score2,CS_score2);
DescendingOrder(m,n);
}
P193T(6)指针数组比较字符串
#include
#include
voidsort_country(char*c[],intn)
{
inti,