为了账号安全,请及时绑定邮箱和手机立即绑定

求矩形的周长和面积

怎么改这个代码

#include<iostream>

using namespace std;

class juxing 

{

int a,b;

double s,c;

public:

juxing(){};

juxing(int new_a)

{

a=new_a;

b=new_a;

}

juxing(int new_a,int new_b)

{

a=new_a;

b=new_b;

}

juxing(juxing &d)

{

a=d.a;

b=d.b;

}

double gets()

{

s=a*b;

return s;

}

double getc()

{

c=2*a+2*b;

return c;

}

};

int main()

{

juxing A1,A2(2),A3(5,3),A4(A3);

cout<<A1.getc()<<" "<<A1.gets()<<endl;

cout<<A2.getc()<<" "<<A2.gets()<<endl;

cout<<A3.getc()<<" "<<A3.gets()<<endl;

cout<<A4.getc()<<" "<<A4.gets()<<endl;

return 0;

}


正在回答

1 回答

#include<iostream>

#include<stdlib.h>

#include<string>

using namespace std;


class orthogon

{

public:

double length;

double wide;

double perimeter(double a,double b)

{

double L;

L = 2 * (a + b);

return L;

}

double area(double a,double b)

{

double S;

S = a * b;

return S;

}

};

int main(int)

{

orthogon Ort;

cout << "please input the Ort.length:" << endl;

cin >> Ort.length;

cout << "please input the Ort.wide" << endl;

cin >> Ort.wide;

cout << Ort.perimeter(Ort.length, Ort.wide) << endl;

cout << Ort.area(Ort.length, Ort.wide) << endl;

system("pause");

return 0;

}


0 回复 有任何疑惑可以回复我~
#1

嫫媣 提问者

非常感谢!
2017-04-11 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
C++远征之封装篇(上)
  • 参与学习       103381    人
  • 解答问题       732    个

封装--面向对象的基石,本教程力求帮助小伙伴们即学即会

进入课程

求矩形的周长和面积

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号