求C++解答急用

来源:百度知道 编辑:UC知道 时间:2024/05/30 13:37:22
1、 编程:定义一个球类Ball,它的私有数据成员为半径r,在类的构造函数中通过形参给半径r赋初值。类中还有成员函数sizeOfBall计算并返回球体积。在主函数中调用sizeOfBall并打印球体积。
2、 编程:定义一个基类Building,用来存储一座楼房的层数floor,建立派生类House,继承Building,并添加属性:卧室的数量number。在主函数中创建House的对象,做简单测试。
3、 编程:定义一个正方形类Square,有边长length和一个桌子类Table,有高度height,颜色color,再设计一个方桌类SquareTable,它是前两个类的派生出来的。要求输出方桌的高度、面积、颜色。
4、 编程:定义一个点类Point,它的私有数据成员为横坐标x和纵坐标y,用类的构造函数给横坐标x和纵坐标y赋初值。再定义一个线类line,它的私有数据成员为Point类 p1 和p2,除构造函数外,Point类还有成员函数getDistance计算并返回两点间的距离。在主函数中创建两点及由此两点构成的一条线,并打印此线长。
5、 大学里有这样三类人员:学生Student、教师Teacher和在职读书的教师STeacher。学生有属性:姓名name,年级grade。方法:升级promote;教师有属性:姓名,工资wage。方法:加工资promote,带有一个形参,实现加多少工资。在职读书的教师:兼有教师和学生的属性、方法。给出这三类人员的类描述,

#include <cmath>
#include <cstring>
#include <iostream>

1
class Ball
{
private:
double r;
public:
Ball(int x)
{
r=x;
}

double sizeOfBall()
{
return 4*r*r*r*3.14/3;
}
};

2
class Building
{
private:
int floor;
public:
Building(int x)
{
floor = x;
}
};
class House: public Building
{
private:
int housenumber;
public:
House(int x,int y) :Building(x)
{
housenumber=y;
}
};

3
class Table
{
protected:
int height;
unsigned long color;
public:
Table(int h){height=h;}
Table(){}
~Table(){}
void SetColor(unsigned long cl=0)
{
color=cl;
}
};
class Square
{
protected:
int length;
public:
Square(int len){length=len