zoukankan      html  css  js  c++  java
  • 矩形类定义【C++】

    Description

    定义一个矩形类,数据成员包括左下角和右上角坐标,定义的成员函数包括必要的构造函数、输入坐标的函数,以及计算并输出矩形面积的函数。要求使用提示中给出的测试函数并不得改动。

    Input

    四个数,分别表示矩形左下角和右上角顶点的坐标,如输入3.7 0.4 6.5 4.9,代表左下角坐标为(3.7, 0.4),右上角坐标为(6.5, 4.9)。

    Output

    输出一共有3行(请参考提示(hint)中的main函数):
    第一行:由输入的坐标确定的矩形对象p1的面积
    第二行:由对象复制得到的矩形对象p2的面积
    第三行:直接初始化得到的矩形对象p3的面积

    Sample Input

    3.7 0.4 6.5 4.9

    Sample Output

    12.612.610
    #include<iostream>
    using namespace std;
    class Rectangle
    {
    public:
    	 Rectangle();
    	Rectangle (const Rectangle&p);
    	Rectangle(double ,double ,double ,double);
    	void input()  
     {  
      cin>>x1>>y1>>x2>>y2;  
     }  
     void output()  
     {  
      cout<<(x2-x1)*(y2-y1)<<endl;  
     }  
    private:
    double x1,x2,y1,y2;
    double s;
    };
    
    Rectangle::Rectangle(const Rectangle&p)
    {x1=p.x1;y1=p.y1;x2=p.x2;y2=p.y2;}
    
    Rectangle::Rectangle(double a,double b,double c,double d)
    {
    	x1=a;
    	y1=b;
    	x2=c;
    	y2=d;
    }
    Rectangle::Rectangle()
     {x1=0;
     y1=0;
     x2=0;
     y2=0;}
    
    int main()
    
    {
    
        Rectangle p1;
    
        p1.input();
    
        p1.output();
    
        Rectangle p2(p1);
    
        p2.output();
    
        Rectangle p3(1,1,6,3);
    
        p3.output();
    
        return 0;
    
    }
    


  • 相关阅读:
    Ubuntu16.04+GTX2070+Driver418.43+CUDA10.1+cuDNN7.6
    N皇后问题
    Linux Bash之通配符
    Linux Bash之正则表达式
    Linux Bash文本操作之grep篇
    Linux Bash文本操作之sed篇其二
    Integer对象两种创建方式的比较
    Class文件版本号
    group by、group_concat()、if()
    字节码命令与Java语言在语义描述能力上的差异
  • 原文地址:https://www.cnblogs.com/oversea201405/p/3767014.html
Copyright © 2011-2022 走看看