= =不能上传附件简直无情……
rect头文件
代码贴到这里:
#ifndef RECT_H_
#define RECT_H_
using namespace std;
class Quadrangle
{
public:
string name; //形体的标识
};
typedef Quadrangle * QUADPTR;
class Rect
{
public:
string name; //形体的标识
Rect (int w, int h, string nm);
~Rect ();
void draw() const;
double area() const;
string what() const;
int& Width(); //获取矩形的宽。如果是梯形,还需要一个成员int& Width2()来获取另一条平行边的长度
int& Height();//获取矩形的高
private:
int width, height; //高和宽
};
class Square
{
public:
string name; //形体的标识
Square (int w, string nm);
~Square ();
void draw() const;
double area() const;
string what() const;
int& Width(); //获取矩形的宽。如果是梯形,还需要一个成员int& Width2()来获取另一条平行边的长
private:
int width; //高和宽
};
class Parallelogram
{
public:
string name; //形体的标识
Parallelogram (int, int h, string nm);
~Parallelogram ();
void draw() const;
double area() const;
string what() const;
int& Width(); //获取矩形的宽。如果是梯形,还需要一个成员int& Width2()来获取另一条平行边的长度
int& Height();//获取矩形的高
private:
int width, height; //高和宽
};
class Trapezoid
{
public:
string name; //形体的标识
Trapezoid (int w1,int w2, int h, string nm);
~Trapezoid ();
void draw() const;
double area() const;
string what() const;
int& Width1();
int& Width2();//获取矩形的宽。如果是梯形,还需要一个成员int& Width2()来获取另一条平行边的长度
int& Height();//获取矩形的高
private:
int width1,width2, height; //高和宽
};
class Diamond
{
public:
string name; //形体的标识
Diamond (int w, int height,string nm);
~Diamond ();
void draw() const;
double area() const;
string what() const;
int& Width(); //获取矩形的宽。如果是梯形,还需要一个成员int& Width2()来获取另一条平行边的长度
int& Height();//获取矩形的高
private:
int width, height; //高和宽
};
Rect::Rect (int w = 5, int h = 7, string nm = "Rectangle")
{
width = w;
height = h;
name = nm;
}
Rect::~Rect()
{}
void Rect::draw()const
{
cout << what() <<": width = " << width << ", height = " << height << endl;
}
double Rect::area()const
{
return (width * height);
}
string Rect::what()const
{
return name;
}
int& Rect::Width()
{
return width;
}
int& Rect::Height()
{
return height;
}
Square::Square(int w = 5,string nm = "Square")
{
width = w;
name = nm;
}
Square::~Square(){}
void Square::draw()const
{
cout << what() <<":" << "width = " << width << endl;
}
double Square::area()const
{
return (width * width);
}
string Square::what()const
{
return name;
}
int& Square::Width()
{
return width;
}
Parallelogram::Parallelogram (int w = 5, int h = 7, string nm = "Rectangle")
{
width = w;
height = h;
name = nm;
}
Parallelogram::~Parallelogram()
{}
void Parallelogram::draw()const
{
cout << what() <<": width = " << width << ", height = " << height << endl;
}
double Parallelogram::area()const
{
return (width * height);
}
string Parallelogram::what()const
{
return name;
}
int& Parallelogram::Width()
{
return width;
}
int& Parallelogram::Height()
{
return height;
}
Trapezoid::Trapezoid(int w1 = 5,int w2 = 6,int h = 7,string nm = "Trapezoid")
{
width1 = w1;
width2 = w2;
height = h;
name = nm;
}
Trapezoid::~Trapezoid(){}
void Trapezoid::draw()const
{
cout << what() << ": width1 = " << width1 << ",width2 = " << width2 << ",height = " << height << endl;
}
string Trapezoid::what()const
{
return name;
}
double Trapezoid::area()const
{
return ((width1 + width2) * height / 2);
}
int& Trapezoid::Width1()
{
return width1;
}
int& Trapezoid::Width2()
{
return width2;
}
int& Trapezoid::Height()
{
return height;
}
Diamond::Diamond (int w = 5, int h = 7, string nm = "Diamond")
{
width = w;
height = h;
name = nm;
}
Diamond::~Diamond()
{}
void Diamond::draw()const
{
cout << what() <<": width = " << width << ", height = " << height << endl;
}
double Diamond::area()const
{
return (width * height / 2);
}
string Diamond::what()const
{
return name;
}
int& Diamond::Width()
{
return width;
}
int& Diamond::Height()
{
return height;
}