c++程序设计实验辅导及习题解答-实验11(18 页)Good is good, but better carries it
精益求精,善益求善
实 验 十 一任务 1:程序调试
类静态数据的应用
下列程序设计了一个职工类,职工类中包括职工姓名、薪水和所有职工的薪水总和allSalary
薪水总和员是所有职工对象薪水的统计和,它属于类而不属于某个对象,因而设置为 static 数据
程序为:#include "stdafx
h"#include using namespace std;#include class Employee{ private: char name[30]; float salary; static float allSalary; public: Employee(char *n, float s){ strcpy(name, n); salary = s; allSalary = allSalary + salary;}~Employee(void){}static float GetAllSalary(void) { return allSalary; } };float Employee::allSalary = 0;void main(void){Employee e1("张三", 4500);Employee e2("王五", 5200);Employee e3("李四", 2450);float all;all = Employee::GetAllSalary( ); cout