# 喜刷刷4——shape类—4（完成RsubC类）

167人阅读 评论(0)

#include<iostream>
#define PI 3.14
using namespace std;
class Shape
{
public:
Shape();
Shape(int c);
int getcolor();
double area();
protected:
int color;
};
Shape::Shape()
{
color=0;
}
Shape::Shape(int c)
{
color=c;
}
int Shape::getcolor()
{
return color;
}
double Shape::area()
{
return 10000;
}

class Rectangle:public Shape
{
public:
Rectangle(int c,double w,double h);
double getwidth();
double getheight();
double area();
double price();
protected:
double height;
double width;
};
Rectangle::Rectangle(int c,double w,double h):Shape(c)
{
width=w;
height=h;
}
double Rectangle::getwidth()
{
return width;
}
double Rectangle::getheight()
{
return height;
}
double Rectangle::area()
{
return height*width;
}
double Rectangle::price()
{
return height*width*color;
}

class Circle:public Shape
{
public:
Circle(int c,double r);
double area();
double price();
protected:
};

Circle::Circle(int c,double r):Shape(c)
{
}
{
}

double Circle::area()
{
}
double Circle::price()
{
}

int main()

{

RsubC rc=RsubC(1,2,3,1,1);
cout<<"RsubC area:"<<rc.area()<<endl;
return 0;

}

#include<iostream>
#define PI 3.14
using namespace std;
class Shape
{
public:
Shape();
Shape(int c);
int getcolor();
double area();
protected:
int color;
};
Shape::Shape()
{
color=0;
}
Shape::Shape(int c)
{
color=c;
}
int Shape::getcolor()
{
return color;
}
double Shape::area()
{
return 10000;
}
class Rectangle:public Shape
{
public:
Rectangle(int c,double w,double h);
double getwidth();
double getheight();
double area();
double price();
protected:
double height;
double width;
};
Rectangle::Rectangle(int c,double w,double h):Shape(c)
{
width=w;
height=h;
}
double Rectangle::getwidth()
{
return width;
}
double Rectangle::getheight()
{
return height;
}
double Rectangle::area()
{
return height*width;
}
double Rectangle::price()
{
return height*width*color;
}

class Circle:public Shape
{
public:
Circle(int c,double r);
double area();
double price();
protected:
};

Circle::Circle(int c,double r):Shape(c)
{
}
{
}

double Circle::area()
{
}
double Circle::price()
{
}
class RsubC:public Shape
{
public:
RsubC(int c,double w,double h,double r,bool s);
double area();
private:
Rectangle rectangle;
Circle circle;
bool sign;
};
RsubC::RsubC(int c,double w,double h,double r,bool s):Shape(c),rectangle(c,w,h),circle(c,r),sign(s){}
double RsubC::area()
{
if(sign==0)
return rectangle.area()+circle.area();
else
return rectangle.area()-circle.area();
}
int main()
{
RsubC rc=RsubC(1,2,3,1,1);
cout<<"RsubC area:"<<rc.area()<<endl;
return 0;

}


0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：67434次
• 积分：2771
• 等级：
• 排名：第12994名
• 原创：209篇
• 转载：6篇
• 译文：0篇
• 评论：78条
评论排行
最新评论