杠杆画出五要素:用vc++编写程序代码!设计一个圆类circle和一个桌子类table要求输出一个圆桌的高度、面积和颜色等数据

来源:百度文库 编辑:高考问答 时间:2024/05/10 03:21:27
设计一个圆类circle和一个桌子类table,另设计一个圆桌类roundtable,它是
从前两个类派生的,要求输出一个圆桌的高度、面积和颜色等数据.

要求用vc++编写

只要能运行通就给分,非常感谢

:)

#include <iostream.h>
#define PI 3.14
class table
{
public:
double heigh;
char *color;
public:
virtual void display()=0;//写成纯虚函数便于重载
};

class circle
{
public:
double radius;//半径
public:
virtual void display()=0;//写成纯虚函数便于重载
};

class roundtable : public table,public circle
{
public:
void iniroundtable(double h,double r,char *c)
{
heigh=h;
radius=r;
color=c;
}
void display()
{
cout<<"the heigh of the round table is "<<heigh<<endl;
cout<<"the color of the round table is "<<color<<endl;
cout<<"the area of the round table is "<<PI*radius*radius<<endl;
}
protected:
double heigh,radius;
char *color;
};

int main()
{
roundtable t1;
t1.iniroundtable(1,2,"red");
t1.display();

return 0;
}
简单点,能用,还想加些什么就很简单了。

#include <iostream.h>
#define PI 3.14
class table
{
public:
double heigh;
char *color;
public:
virtual void display()=0;//写成纯虚函数便于重载
};

class circle
{
public:
double radius;//半径
public:
virtual void display()=0;//写成纯虚函数便于重载
};

class roundtable : public table,public circle
{
public:
void iniroundtable(double h,double r,char *c)
{
heigh=h;
radius=r;
color=c;
}
void display()
{
cout<<"the heigh of the round table is "<<heigh<<endl;
cout<<"the color of the round table is "<<color<<endl;
cout<<"the area of the round table is "<<PI*radius*radius<<endl;
}
protected:
double heigh,radius;
char *color;
};

int main()
{
roundtable t1;
t1.iniroundtable(1,2,"red");
t1.display();

return 0;
}
其实在软件的帮助里有画圆的程序的,你要自己多看一下帮助,对自己很有好处

#include <iostream.h>

#define PI (3.14)

enum TColor{Red,Blue,Black,White};
char *ColorString[] = { "Red", "Blue", "Black", "White"};

class Table
{
public:
char* GetColor()
{
return ColorString[m_color];
}
double GetHeight()
{
return m_height;
}

protected:
TColor m_color;
double m_height;
};

class Circle
{
public:
double GetArea()
{
return PI*m_radius*m_radius;
}
protected:
double m_radius;
};

class RoundTable:public Table,public Circle
{
public:
RoundTable(TColor color,double height,double radius)
{
m_color = color;
m_height = height;
m_radius = radius;
}
void PrintInfo()
{
cout<<"Color = "<<GetColor() << ", Height = "<<GetHeight() <<", Area = "<<GetArea()<<endl;

}
};

int main()
{
RoundTable rt(Red,10.1,5);
rt.PrintInfo();
return 0;
}

楼上定义的两个类你根本就没有使用啊!定义个空类一样能用啊