#include<iostream>
using namespace std;
class square
{
    public:
        square(int x1,int y1);  //x1,x2为自定义长宽
        int getchang() {return x;} //用于输出长 
        int getkuan() {return y;} //输出宽 
        int getmianji() {return z;}//输出面积 
    private:
     int x;
     int y;
     int z; 
};

square::square(int x1,int y1) 
{
    x=x1;y=y1;z=(x*y);  //使用输入的自定义值赋值 
}

int main()
{

    int e,f;
    cout<<"请输入自定义长方形的长与宽:";
    cin>>e>>f;
    square a1(e,f);
    cout<<"自定义长,宽为:"<<a1.getchang()<<","<<a1.getkuan()<<endl;
    cout<<"自定义长方形面积为:"<<a1.getmianji()<<endl;

}
View Code

 

 

 

 

 

#include<iostream>
using namespace std;
class Complex
{
    public:
        Complex(double r0,double i0); 
        Complex(double r0);
        Complex(const Complex &c);
        ~Complex(){}
        void add(Complex &c0); 
        void show(){cout<<x<<'+'<<y<<'i'<<endl;}
        
        
    private:
        double x;//实部 
        double y;//虚部 
        
 } ;
 
 Complex::Complex(double r0,double i0)
 {x=r0;y=i0;}
 
 Complex::Complex(double r0)
 {x=r0;y=0;}
 
 void Complex::add(Complex &c0)
 {
     x+=c0.x;y+=c0.y;
 }
 
 int main()
 {
     Complex c1(3,5);
     Complex c2=4.5;
     c1.add(c2);
     c1.show();
     return 0;
 }
View Code

 

posted on 2018-04-07 19:50  ikazuchi  阅读(180)  评论(8)    收藏  举报