码迷,mamicode.com
首页 > 其他好文 > 详细

实验三

时间:2018-04-07 12:41:38      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:stream   clu   blog   space   http   names   include   9.png   ace   

#include<iostream>
using namespace std;
class retangle{
    public:
        retangle(double x,double y); 
        double area();
        private:
            double length,width;
};
retangle::retangle(double x, double y)
{
    length=x;
    width=y;
}
double retangle::area()
{
    return length*width;
}
int main()
{
    double length,width;
    cout<<"Please enter the length and the width:";
    cin>>length>>width;
    retangle c(length,width);
    cout << c.area()<<endl;
    return 0;
}

技术分享图片

#include<iostream>
using namespace std;
class complex{
    public:
      complex(double r,double i);
      void add(complex c2);
      void show();
    private:
      double real,imaginary;
         
};
complex::complex(double r,double i)
{
    real= r;
    imaginary=i;
}
void complex::add(complex c2){
    real+=c2.real;
    imaginary+=c2.imaginary;
}
void complex::show(){
    cout<<real<<"+"<<imaginary<<"i"<<endl;
}
int main()
{
    complex c1(3.0,5.0);
    complex c2(4.5,0);
    c1.add(c2);
    c1.show();
    return 0;
}

技术分享图片

实验三

标签:stream   clu   blog   space   http   names   include   9.png   ace   

原文地址:https://www.cnblogs.com/Nicholastwo/p/8732778.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!