This is catalogue
Test_one
class::Student
#include<iostream>
using namespace std;
class Student{
public:
string num;
int score;
void max(Student * stu);
};
void Student::max(Student * stu){
int max=stu[0].score;
string number;
for(int i=1;i<5;i++){
if(stu[i].score>max){
max=stu[i].score;
number=stu[i].num;
}
}
cout<<"成绩最高是:"<<max<<endl<<"学号是:"<<number<<endl;
}
int main(){
Student student[5];
for(int i = 0; i < 5 ; i++){
cin >> student[ i ].num >> student[ i ].score;
}
Student *stu2 = student;
stu2->max(student);
return 0;
}
Test_second
class::Cat
#include <iostream>
using namespace std;
class cat{
public:
cat(int age):age (age){
numofcats++;}
static int getnumofcats(){return numofcats;}
~cat(){numofcats--;}
private:
static int numofcats;
int age;
};
int cat::numofcats=0;
int main()
{
cat a=15;
cat b=23;
cout<<"当前猫的总数为: "<<cat::getnumofcats()<<endl;
return 0;
}
Test_three
class::JX
#include <iostream>
using namespace std;
class JX{
private:
int length,width;
public:
void setJX( int l , int w ){
length = l , width = w;
}
friend int get_area( JX clas );
};
int get_area( JX clas ){
return clas.length * clas.width;
}
int main(){
cout << "请输入矩形的长和宽:\n";
JX jx;
int l,w;
cin >> l >> w ;
jx.setJX( l , w );
cout << "矩形的面积是: " << get_area( jx ) << endl;
return 0;
}