using namespace std; void Max(int a,int b) { int max; if(a>=b) max=a; else max=b; cout<<\}
void Max(double x,double y,double z) { double max; if(x>=y) max=x; else max=y; if(max void Max(char n1[50],char n2[50]) { char max3[50]; if(strcmp(n1,n2)>0) strcpy(max3,n1); else strcpy(max3,n2); cout<<\} int main() { double x,y,z; int a,b; char n1[50],n2[50]; cin>>a>>b; cin>>x>>y>>z; cin>>n1>>n2; Max(a,b); Max(x,y,z); Max(n1,n2); return 0; } 6:长方形类与对象的定义 Time/Memory Limit:1000 MS/32768 K Submitted: 57 Accepted: 54 Problem Description 定义一个类area,它有两个整形的私有数据代表长方形的长和宽,有三个成员函数init、print、areas,init用来给长方形初始化,print用来输出长方形的面积,areas用来计算长方形的面积,要求将类定义完整,并通过main函数定义相应的长方形对象,输出对象的面积。 Input 输入数据有多组,每组占一行,每行中有两个数,用空格分隔。 Output 对于每组输入数据,输出一行 Sample Input 5 2 6 4 7 5 8 2 Sample Output 10 24 35 16 #include private: int l,w; public: void init(int l1,int w1) { l=l1; w=w1; } int SS() { int s; s=l*w; return s; } void print(); }; void Area::print() { cout< int main() { Area a; int l2,w2; while(cin>>l2>>w2) { a.init(l2,w2); a.print(); } return 0; } 7:圆的面积 Time/Memory Limit:1000 MS/32768 K Submitted: 100 Accepted: 48 Problem Description 设计一个Circle类,可以求圆的面积。 Input 输入数据有多组,每组占一行,每行包括一个实数r,表示圆的半径。 Output 输出圆的面积。 其中PI=3.14。 Sample Input 1 Sample Output 3.14 #include private: double r; public: void init(double r1) { r=r1; } double SS() { double s; s=r*r*3.14; return s; } void print(); }; void Circle::print() { cout< int main() { Circle x; double r2; while(cin>>r2) { x.init(r2); x.print(); } return 0; } 8:输出类对象 Time/Memory Limit:1000 MS/32768 K Submitted: 59 Accepted: 47 Problem Description 定义一个类Student,用成员变量name、no、age描述一个学生的姓名、学号和年龄的信息。现从键盘获取三个不同学生的信息。按输入的顺序将它们存入相应的对象中,并显示它们(一行一条记录)。 Input 数据之间用空格分割,每行输入一个记录。共3条记录。 Output 数据之间用一个空格分割,每行输出一个记录。共3条记录。 Sample Input zhangsan 1 21 lishi 2 19 wangwu 3 21 Sample Output zhangsan 1 21 lishi 2 19 wangwu 3 21 #include private: char name[20]; int no,age; public: void init(char n1[20],int no1,int age1) { strcpy(name,n1); no=no1; age=age1; } void print() { cout< int main()