# 编程题：类---矩形类

/*

*/
#include <iostream>
using namespace std;
class Rectangle
{
public:
Rectangle(int w,int l);
int getArea();
int getPerimeter();
private:
int width;
int length;
};
//将程序需要的其他成份写在下面，只提交begin到end部分的代码
//******************** begin ********************

//********************* end ********************
int main()
{
int width,length;
cin>>width>>length;
Rectangle r(width,length);
cout<<"Area="<<r.getArea()<<endl;
cout<<"Perimeter="<<r.getPerimeter()<<endl;
return 0;
}

Area=矩形的面积

Perimeter=矩形的周长

``2 5``

``````Area=10
Perimeter=14``````

``````#include<stdio.h>
int main()
{
int a,b;
scanf("%d%d",&a,&b);
printf("Area=%d\nPerimeter=%d",a*b,2*(a+b));
return 0;
}``````

``````
#include <iostream>
using namespace std;
class Person
{
private:
string name;
string tel;
public:
void getvalue()
{
}
void display()
{
cout<<"name:"<<name<<endl;
cout<<"tel:"<<tel<<endl;
}

};class Student:public Person
{
private:
string ID;
public:
void getvalue1()
{
cin>>ID;
}
void display1()
{
cout<<"ID:"<<ID<<endl;
}

};
int main()
{
Student stu;
stu.getvalue();
stu.getvalue1();
stu.display();
stu.display1();
return 0;
}
``````