Lab Exercise 6: Class Inheritance (Part I)
发布时间
阅读量:
阅读量
一、实验目的:
掌握继承机制的功能,熟悉三种不同的继承方式,学习派生类的构建方法。
二、实验内容:
1.创建一个Rectangle类,其中包含两个数据成员length和width,以及用于计算长方形面积的成员函数。随后定义Rectangle类的派生类Rectangular,该类新增一个数据成员height,并具备计算长方体体积的成员函数。在主函数中,分别调用这两个类,实现对某一长方形面积及某一长方体体积的计算。
#include<iostream>
using namespace std;
class Rectangle
{
private:
int length;
int width;
public:
int setRectangle(int l,int w);
float area();
};
class Rectangular : public Rectangle
{
private:
int height;
public:
int setHeight(int h);
float volume();
};
全部评论 (0)
还没有任何评论哟~
