📄 b_9_1.cpp
字号:
#include "stdafx.h"
#include <iostream>
#include <string>
#include<iomanip>
using namespace std;
const double PI=3.1416;
class shape{
public:
virtual double area()=0;
};
class Circle:public shape {
public:
Circle(double x)
:r(x){ }
double area()
{ return PI*r*r;}
private:
double r;
};
class Triangle:public shape
{
public:
Triangle(double i,double j)
:high(i),width(j){ }
double area()
{ return 0.5*high*width; }
private:
double high,width;
};
class Rectangle:public shape {
public:
Rectangle(double i,double j)
:high(i),width(j){ }
double area()
{ return high*width;}
private:
double high,width;
};
void main()
{
shape *ptr;
Triangle triangle(8,11);
Rectangle rectangle(8,11);
Circle circle(7);
ptr=&circle;
cout<<"圆的面积是:"<<ptr->area()<<endl;
ptr=&rectangle;
cout<<"矩形的面积是:"<<ptr->area()<<endl;
ptr=▵
cout<<"三角形的面积是:"<<ptr->area();
cin.get(); //等待结束,以便调测程序,可以删除
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -