4.22打卡
#include<iostream> #include <string> using namespace std; class Vehicle { protected: string NO;//编号 public: Vehicle(string n){ NO = n; } virtual int fee()=0;//计算应收费用 }; class Car:public Vehicle { public: Car(string no,int guest,int weight):Vehicle(no) // 不知道为啥要加一个:Vehicle(no),哪个大神可以讲解一下 { m_no=no; m_guest=guest; m_weight=weight; } virtual int fee() { return (m_guest*8+m_weight*2); } private: string m_no; int m_guest,m_weight; }; class Truck:public Vehicle { public: Truck(string no,int weight):Vehicle(no) { m_no=no; m_weight=weight; } virtual int fee() { return (m_weight*5); } private: string m_no; int m_weight; }; class Bus :public Vehicle { public: Bus(string no,int guest):Vehicle(no) { m_no=no; m_guest=guest; } virtual int fee() { return (m_guest*3); } private: string m_no; int m_guest; }; int main() { Car c("",0,0); Truck t("",0); Bus b("",0); int i, repeat, ty, weight, guest; string no; cin>>repeat; for(i=0;i<repeat;i++){ cin>>ty>>no; switch(ty){ case 1: cin>>guest>>weight; c=Car(no, guest, weight); cout<<no<<' '<<c.fee()<<endl; break; case 2: cin>>weight; t=Truck(no, weight); cout<<no<<' '<<t.fee()<<endl; break; case 3: cin>>guest; b=Bus(no, guest); cout<<no<<' '<<b.fee()<<endl; break; } } return 0; }
class Shape { public: Shape(){} virtual ~Shape(){} virtual float area() = 0; }; class Circle:public Shape{ private: int x, y; float radius; public: Circle(int x, int y, float radius) { this->x = x; this->y = y; this->radius = radius; } ~Circle(){} float area(){ return 3.1415926f * radius * radius; } }; class Rectangle:public Shape{ private: int width, height; public: Rectangle(int w, int h){ width = w; height = h; } ~Rectangle(){} float area(){ return width*height; } };
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律