抽象类小案例
利用案例辅助记忆抽象概念 #生活技巧# #学习技巧# #笔记方法#
/* 编写一个C++程序, 计算程序员( programmer )工资 1 要求能计算出初级程序员( junior_programmer ) 中级程序员 ( mid_programmer )高级程序员( adv_programmer)的工资 2 要求利用抽象类统一界面,方便程序的扩展, 比如:新增, 计算 架构师 (architect ) 的工资 */ #include "iostream" using namespace std; class programmer //接口 { public:virtual void getsal() = 0; }; class junior_programmer : public programmer //初级 { private:char *name;char *job;int sal; public:junior_programmer(char *name, char *job, int sal){this->name = name;this->job = job;this->sal = sal;}virtual void getsal(){cout << name << " " << job << " " << sal << endl;} }; class mid_programmer : public programmer //中级 { private:char *name;char *job;int sal; public:mid_programmer(char *name, char *job, int sal){this->name = name;this->job = job;this->sal = sal;}virtual void getsal(){cout << name << " " << job << " " << sal << endl;} }; class adv_programmer : public programmer // 高级 { private:char *name;char *job;int sal; public:adv_programmer(char *name, char *job, int sal){this->name = name;this->job = job;this->sal = sal;}virtual void getsal(){cout << name << " " << job << " " << sal << endl;} }; class architect : public programmer //新增架构师 { private:char *name;char *job;int sal; public:architect(char *name, char *job, int sal){this->name = name;this->job = job;this->sal = sal;}virtual void getsal(){cout << name << " " << job << " " << sal << endl;} }; void GetSal(programmer *base) {base->getsal(); //产生多态 } void main() {junior_programmerjp("小李", "初级", 4000);mid_programmermp("小王", "初级", 8000);adv_programmerap("小张", "初级", 10000);architectat("老孙", "架构师", 20000);GetSal(&jp);GetSal(&mp);GetSal(&ap);GetSal(&at);system("pause"); }
网址:抽象类小案例 https://www.yuejiaxmz.com/news/view/330970
相关内容
抽象艺术课程设计Javascript基础第六天知识点以及案例:作用域、JS预解析、对象
垃圾分类优秀案例
《整理抽屉》教案
不同种类的手绘油画抽象装饰画 装修网分享装饰画图片
自然、生活与艺术中的抽象.ppt
用心服务,温情陪伴服务对象走出阴霾——残疾人个案案例
日常生活教育案例.docx
【案例】数据挖掘与生活:算法分类和应用
象山县二塘乡=环卫所抽粪=抽粪家政