📄 fig6_1.cpp
字号:
//fig6_1.cpp
//类Employee的层次结构的测试程序
#include <iostream.h>
#include <assert.h>
#include <iomanip.h>
#include "employ2.h"
#include "boss1.h"
#include "commis1.h"
#include "piece1.h"
#include "hourly1.h"
main()
{
//设置输出格式
cout<<setiosflags(ios:: showpoint)<<setprecision(2);
Employee *ptr; //基类指针
Boss b("John", "Smith", 800.00);
ptr=&b; //指向派生类对象的基类指针
ptr->print(); //动态连编
cout<<"earned $"<<ptr->earnings(); //动态连编
b.print(); //静态连编
cout<<"earned $"<<b.earnings(); //静态连编
CommissionWorker c("Sue", "Jones", 200.0, 3.0, 150);
ptr=&c; //基类指针指向派生类对象
ptr->print(); //动态连编
cout<<"earned $"<<ptr->earnings(); //动态连编
c.print(); //静态连编
cout<<"earned $"<<c.earnings(); //静态连编
PieceWorker p("Bob", "Lewis", 2.5, 200);
ptr=&p; //基类指针指向派生类对象
ptr->print(); //动态连编
cout<<"earned $"<<ptr->earnings(); //动态连编
p.print(); //静态连编
cout<<"earned $"<<p.earnings(); //静态连编
HourlyWorker h("Karen", "Price", 13.75, 40);
ptr=&h; //基类指针指向派生类对象
ptr->print(); //动态连编
cout<<"earned $"<<ptr->earnings(); //动态连编
h.print(); //静态连编
cout<<"earned $"<<h.earnings(); //静态连编
cout<<endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -