实验五:派生类和继承(二)(2)

发布时间:2021-06-06

金山学院C++课程实验报告

本题的代码如下:

#include<iostream.h>

const double pai=3.14;

class Shape

{public:double area()const{return 0.0;}

void display(){};

};

class twoDimShape:virtual public Shape

{};

class threeDimShape:virtual public Shape

{};

//三角形类

class Triangle:public twoDimShape

{public:Triangle(double myg,double myd){gao=myg;di=myd;}

double area ()const {return (di*gao)/2;}

void display(){cout<<"Area of Square is";}

private:double gao,di;

};

//正方形类

class Square:public twoDimShape

{public:Square(double myb){bianchang =myb;}

double area ()const {return bianchang*bianchang;}

void display(){cout<<"Area of Square is";}

private:double bianchang;

};

//正方体

class Squarer:public threeDimShape

{public:Squarer(double myb){bianchang =myb;}

double area ()const {return bianchang*bianchang*bianchang;}

void display(){cout<<"Superficial area of Cone is";}

private:double bianchang;

};

//球

class Ball:public threeDimShape

{public:Ball(double myr){r =myr;}

double area ()const {return (4*pai*r*r*r)/3;}

void display(){cout<<"Superficial area of Ball is";}

private:double r;

};

int main()

{ double a,b,c,d,e;

cout<<"请输入三角形的高和底"<<endl;

cin>>a>>b;

Triangle t(a,b);

double area;

area=t.area();

实验五:派生类和继承(二)(2).doc 将本文的Word文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219