C++的问题!!!急求
(1)编写控制台应用程序,初步实现员工信息管理的功能:1)定义一个员工类Employee,员工类中包括私有成员:workNum(工号)、name(姓名)、basicSal...
(1) 编写控制台应用程序,初步实现员工信息管理的功能:
1) 定义一个员工类Employee,员工类中包括私有成员:workNum(工号)、name(姓名)、basicSalary(基本工资)、rewards(奖金)、totalSalary(应发工资)、totalNum(静态成员:总员工人数);
2) 在类中添加公有方法:CalTotalSalary(计算应发工资,基本工资+奖金)、DisplayEmployeeInfo(显示员工当前信息)、DisplayTotalNumber(显示总员工人数)
3) 在类Employee中添加相应的公有属性,WorkNum(工号)、Name(姓名)、BasicSalary(基本工资)、Rewards(奖金)、Salary(应发工资,只读);
4) 类中同时包含函数:Employee(构造函数)、~Employee(析构函数)。其中,构造函数为Employee类的对象赋值并将员工人数加1,以实现对象的初始化,析构函数计算员工人数减1,显示当前人数信息。
5) 创建一个类Employee的对象并调用四个公有方法。
6) 创建一组类Employee的对象并调用相应的方法设置和显示各对象信息。(提示:可以通过创建Arraylist类对象,每创建一个Employee对象,通过Arraylist的add方法将对象加到列表中) 展开
1) 定义一个员工类Employee,员工类中包括私有成员:workNum(工号)、name(姓名)、basicSalary(基本工资)、rewards(奖金)、totalSalary(应发工资)、totalNum(静态成员:总员工人数);
2) 在类中添加公有方法:CalTotalSalary(计算应发工资,基本工资+奖金)、DisplayEmployeeInfo(显示员工当前信息)、DisplayTotalNumber(显示总员工人数)
3) 在类Employee中添加相应的公有属性,WorkNum(工号)、Name(姓名)、BasicSalary(基本工资)、Rewards(奖金)、Salary(应发工资,只读);
4) 类中同时包含函数:Employee(构造函数)、~Employee(析构函数)。其中,构造函数为Employee类的对象赋值并将员工人数加1,以实现对象的初始化,析构函数计算员工人数减1,显示当前人数信息。
5) 创建一个类Employee的对象并调用四个公有方法。
6) 创建一组类Employee的对象并调用相应的方法设置和显示各对象信息。(提示:可以通过创建Arraylist类对象,每创建一个Employee对象,通过Arraylist的add方法将对象加到列表中) 展开
2个回答
展开全部
//懒得调整格式了,你自己整理吧
#include <string>
#include <iostream>
#include <list>
using namespace std;
class Employee
{
public:
Employee(string wN, string name, double bs, double rds);
~Employee();
public:
double CalTotalSalary();
void DisplayEmployeeInfo();
void DisplayTotalNumber();
public:
// 获取对应的属性信息
const string WorkNum() const;
const string Name() const;
const double BasicSalary() const;
const double Rewards() const;
const double Salary() const;
// 设置属性
void WorkNum(string& input);
void Name(string& input);
void BasicSalary(double input);
void Rewards(double input);
void Salary(double input);
private:
string workNum;
string name;
double basicSalary;
double rewards;
double totalSalary;
static int totalNum;
};
int Employee::totalNum = 0;
Employee::Employee(string wN, string Name, double bs, double rds)
:
workNum(wN),
name(Name),
basicSalary(bs),
rewards(rds)
{
++totalNum;
CalTotalSalary();
}
Employee::~Employee()
{
totalNum--;
cout << "Current Employees: " << totalNum << endl;
}
double Employee::CalTotalSalary()
{
totalSalary = basicSalary + rewards;
return totalSalary;
}
void Employee::DisplayEmployeeInfo()
{
cout << name << ":\t" << endl;
cout << "Basic Salary: " << basicSalary << endl;
cout << "Rewards: " << rewards << endl;
cout << "Total Salary: " << totalSalary << endl;
}
void Employee::DisplayTotalNumber()
{
cout << "Total Employees: " << totalNum << endl;
}
// 获取
const string Employee::WorkNum() const
{
return workNum;
}
const string Employee::Name() const
{
return name;
}
const double Employee::BasicSalary() const
{
return basicSalary;
}
const double Employee::Rewards() const
{
return rewards;
}
const double Employee::Salary() const
{
return totalSalary;
}
// 设置
void Employee::WorkNum(string& input)
{
workNum = input;
}
void Employee::Name(string& input)
{
name = input;
}
void Employee::BasicSalary(double input)
{
basicSalary = input;
}
void Employee::Rewards(double input)
{
rewards = input;
}
void Employee::Salary(double input)
{
totalSalary = input;
}
// 类Arraylist
class Arraylist
{
public:
Arraylist(){}
~Arraylist();
void add(Employee*);
private:
list<Employee*>Emps;
};
Arraylist::~Arraylist()
{
list<Employee*>::iterator it = Emps.begin();
while ( it != Emps.end() )
{
Employee* tmp = *(it);
cout << "deleting " << tmp->WorkNum() << ", " << tmp->Name() << endl;
delete tmp, tmp = NULL;
Emps.erase(it++);
}
}
void Arraylist::add(Employee* pEmp)
{
if ( pEmp )
{
Emps.push_back(pEmp);
cout << "adding " << pEmp->WorkNum() << ", " << pEmp->Name() << endl;
pEmp->DisplayTotalNumber();
}
}
int main(int argc, char* argv[])
{
Arraylistemployees;
cout << "---------------------------" << endl;
Employee *pLM = new Employee("00001", "LiMing", 3000.52, 500.0);//创建李明
pLM->DisplayEmployeeInfo();//显示李明员工信息
pLM->Rewards(520.5);//调整奖金
pLM->CalTotalSalary();//重新计算奖金
pLM->DisplayEmployeeInfo();//显示李明员工信息
pLM->DisplayTotalNumber();//显示有多少个员工
employees.add(pLM);//加入队列
cout << "---------------------------" << endl;
pLM = new Employee("00002", "ZhangBo", 2000.0, 500.0);//创建张波
pLM->DisplayEmployeeInfo();//显示张波员工信息
pLM->Rewards(520.5);//调整奖金
pLM->CalTotalSalary();//重新计算奖金
pLM->DisplayEmployeeInfo();//显示张波员工信息
pLM->DisplayTotalNumber();//显示有多少个员工
employees.add(pLM);//加入队列
cout << "---------------------------" << endl;
return 0;
}
#include <string>
#include <iostream>
#include <list>
using namespace std;
class Employee
{
public:
Employee(string wN, string name, double bs, double rds);
~Employee();
public:
double CalTotalSalary();
void DisplayEmployeeInfo();
void DisplayTotalNumber();
public:
// 获取对应的属性信息
const string WorkNum() const;
const string Name() const;
const double BasicSalary() const;
const double Rewards() const;
const double Salary() const;
// 设置属性
void WorkNum(string& input);
void Name(string& input);
void BasicSalary(double input);
void Rewards(double input);
void Salary(double input);
private:
string workNum;
string name;
double basicSalary;
double rewards;
double totalSalary;
static int totalNum;
};
int Employee::totalNum = 0;
Employee::Employee(string wN, string Name, double bs, double rds)
:
workNum(wN),
name(Name),
basicSalary(bs),
rewards(rds)
{
++totalNum;
CalTotalSalary();
}
Employee::~Employee()
{
totalNum--;
cout << "Current Employees: " << totalNum << endl;
}
double Employee::CalTotalSalary()
{
totalSalary = basicSalary + rewards;
return totalSalary;
}
void Employee::DisplayEmployeeInfo()
{
cout << name << ":\t" << endl;
cout << "Basic Salary: " << basicSalary << endl;
cout << "Rewards: " << rewards << endl;
cout << "Total Salary: " << totalSalary << endl;
}
void Employee::DisplayTotalNumber()
{
cout << "Total Employees: " << totalNum << endl;
}
// 获取
const string Employee::WorkNum() const
{
return workNum;
}
const string Employee::Name() const
{
return name;
}
const double Employee::BasicSalary() const
{
return basicSalary;
}
const double Employee::Rewards() const
{
return rewards;
}
const double Employee::Salary() const
{
return totalSalary;
}
// 设置
void Employee::WorkNum(string& input)
{
workNum = input;
}
void Employee::Name(string& input)
{
name = input;
}
void Employee::BasicSalary(double input)
{
basicSalary = input;
}
void Employee::Rewards(double input)
{
rewards = input;
}
void Employee::Salary(double input)
{
totalSalary = input;
}
// 类Arraylist
class Arraylist
{
public:
Arraylist(){}
~Arraylist();
void add(Employee*);
private:
list<Employee*>Emps;
};
Arraylist::~Arraylist()
{
list<Employee*>::iterator it = Emps.begin();
while ( it != Emps.end() )
{
Employee* tmp = *(it);
cout << "deleting " << tmp->WorkNum() << ", " << tmp->Name() << endl;
delete tmp, tmp = NULL;
Emps.erase(it++);
}
}
void Arraylist::add(Employee* pEmp)
{
if ( pEmp )
{
Emps.push_back(pEmp);
cout << "adding " << pEmp->WorkNum() << ", " << pEmp->Name() << endl;
pEmp->DisplayTotalNumber();
}
}
int main(int argc, char* argv[])
{
Arraylistemployees;
cout << "---------------------------" << endl;
Employee *pLM = new Employee("00001", "LiMing", 3000.52, 500.0);//创建李明
pLM->DisplayEmployeeInfo();//显示李明员工信息
pLM->Rewards(520.5);//调整奖金
pLM->CalTotalSalary();//重新计算奖金
pLM->DisplayEmployeeInfo();//显示李明员工信息
pLM->DisplayTotalNumber();//显示有多少个员工
employees.add(pLM);//加入队列
cout << "---------------------------" << endl;
pLM = new Employee("00002", "ZhangBo", 2000.0, 500.0);//创建张波
pLM->DisplayEmployeeInfo();//显示张波员工信息
pLM->Rewards(520.5);//调整奖金
pLM->CalTotalSalary();//重新计算奖金
pLM->DisplayEmployeeInfo();//显示张波员工信息
pLM->DisplayTotalNumber();//显示有多少个员工
employees.add(pLM);//加入队列
cout << "---------------------------" << endl;
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询