-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRectangle.h
61 lines (48 loc) · 1.59 KB
/
Rectangle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef RECTANGLE_H_INCLUDED
#define RECTANGLE_H_INCLUDED
#include <iostream>
#include "Shape.h"
using namespace std;
class Rectangle1:public Shape
{
public:
Rectangle1(float l=0, float w=0); //声明构造函数
void setL(float); //设定长
void setW(float); //设定宽
float getL() const ; //取长的值
float getW() const ;
virtual float perimeter() const; //对虚函数进行再定义
virtual float area() const; //对虚函数进行再定义
virtual void shapeName() const //对虚函数进行再定义
{
cout<<"Rectangle";
}
virtual void shapeSet() const //虚函数用于输出图形参数说明
{
cout<<"please input the rectangle's long and wide( parameter separated by space ):";
}
friend ostream &operator<< (ostream &, const Rectangle1 &);//运算符重载
protected:
float longs;
float wide;
};
Rectangle1::Rectangle1(float l, float w):longs(l),wide(w){} //采用构造函数表定义
void Rectangle1::setL(float l)
{
longs = l;
}
void Rectangle1::setW(float w)
{
wide = w;
}
float Rectangle1::getL() const {return longs;}
float Rectangle1::getW() const {return wide;}
float Rectangle1::perimeter() const {return 2*(longs+wide);}
float Rectangle1::area() const {return longs*wide;}
ostream &operator<< (ostream &output, Rectangle1 &re)
{
output<<"its area is "<<re.area()<<endl
<<"its perimeter is "<<re.perimeter();
return output;
}
#endif // RECTANGLE_H_INCLUDED