问题:
Description
给定矩形的长和宽,利用类与对象的知识,编程实现计算矩形的面积和周长。
Input
输入矩形的长和宽分别为5和4
Output
矩形的面积和周长分别为20和18
Sample Input
5 4
Sample Output
20
18
代码:
```cpp
#include <iostream>
using namespace std;
struct student
{
private:
int log;
int weight;
int s,c;
public:
void display()
{
cin>>log>>weight;
s=log*weight;
c=(log+weight)*2;
cout<<s<<endl<<c<<endl;
}
}stu1;
int main()
{
stu1.display();
return 0;
}
如果有任何问题,欢迎在下方评论