第三次C++作业

include

using namespace std;
class rectangle{
public:
void shape(int a=0,int b=0);
void area();
private:
int length,wide;
}
//长方形类成员函数的具体实现
void rectangle::shape(int a,int b){
length=a;
wide=b;
}
inline void rectangle::area(){
cout<<"area="<<endl;
cout<<"length*wide"<<endl;
}
int main(){
int c,d;
rectangle myrectangle;
cout<<"Please input two number"<<endl;
cin>>c;
cin>>d;
myrectangle.shape(c,d);
myrectangle.area();
returen 0;
}

include

using namespace std;
class()
{
public:
Complex(float r1,float i1){
real+=r1;
imaginary=0;
}
void add(Complex &c)
{
real+=c.real;
imaginary+=c.imaginary;
}
void show()
{
cout<<real<<(imaginary>0?'+':'-')<<imaginary<<"i"<<endl;
}
private:
float real;
float imaginary;
};
int main()
{
Complex c1(3,5);
Complex c2=4.5;
c2.add(c1);
c2.show();
return 0;
}

posted @ 2018-04-08 23:13  太空鹿  阅读(113)  评论(6编辑  收藏  举报