⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 f1206.cpp

📁 城里基本原理 佣工 仍然抱佛脚 仍然 脍炙人口 要求 要求 五项原则
💻 CPP
字号:
//=====================================
// f1206.cpp
// Spreading Virtual
//=====================================
#include<iostream>
#include<cmath>
using namespace std;
//-------------------------------------
class Shape{
protected:
  double xCoord, yCoord;
public:
  Shape(double x, double y) : xCoord(x),yCoord(y){}
  virtual double area()const{ return 0.0; }
};//-----------------------------------
class Circle : public Shape{
protected:
  double radius;
public:
  Circle(double x, double y, double r) : Shape(x,y),radius(r){}
  double area()const{ return 3.14 * radius * radius; }
};//-----------------------------------
class Rectangle : public Shape{
protected:
  double x2Coord, y2Coord;
public:
  Rectangle(double x1, double y1, double x2, double y2)
   : Shape(x1,y1), x2Coord(x2), y2Coord(y2){}
  double area()const;
};//-----------------------------------
double Rectangle::area()const{
  return abs((xCoord-x2Coord)*(yCoord-y2Coord));
}//------------------------------------
void fun(const Shape& sp){
  cout<<sp.area()<<"\n";
}//------------------------------------
int main(){
  fun(Circle(2, 5, 4));
  fun(Rectangle(2, 4, 1, 2));
}//====================================

 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -