求矩形的周長和面積
怎么改這個代碼
#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;
}
2017-04-10
#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;
}