小型人员信息管理系统的设计与实现(控制台版本和MFC版本)

Cynicism

发布日期: 2018-11-05 18:28:08 浏览量: 2073
评分:
star star star star star star star star star_border star_border
*转载请注明来自write-bug.com

摘 要

现实生活中许多小型公司会用职工信息管理系统,通过应用电脑软件来对员工信息进行管理能够提高管理效率,使用Visual C++ 6.0的控制台工程和MFC工程分别实现了对员工信息的录入,更新,查看,以及保存。

关键词:员工管理;职工信息;动态数组;MFC工程

1 需求分析

在日常生活工作中有很多地方需要用到信息管理,小型创业公司等都需要人工管理,这种情况下会有较高的错误率,并且信息易丢失,而采用电子信息进行存储与管理将会避免这个问题,能够大大提高管理信息准确性,提高企业效率。

本系统需要实现对员工信息从文件中录入,并进行相关管理,进行数据更新,计算每个人的月薪,能够进行信息查询,信息存储到单独文件。

2 算法基本原理

2.1 数据读入

从文件中分别读取经理,销售经理,兼职技术人员和兼职推销员的基本信息,使用ifstream类读取文件中的数据。通过判断文件指针是否指向文件尾来判断是否读取员工数据完成。

2.2 数据存储

员工数目是未知的,为了能够更合理的分配内存空间,使用vecotr类建立动态数组存储从文件中读取到的员工信息。

对员工信息处理完成后,存储信息到磁盘使用ofstream类,建立文件流,实现对文件内容写入。

2.3 数据计算

经理的薪资为固定工资8000,销售经理的薪资为5000固定工资加所管辖部门的销售额的0.5%,兼职推销员的薪资为其当月销售额的4%,兼职技术人员的薪资为每小时100元。

3 类设计

3.1 类的概述

本系统用到了员工类,员工类派生出经理类,销售经理类,兼职技术员类,兼职销售员类。
员工类包含基础信息姓名,级别,工资等信息,能够实现信息打印,员工升级,保存信息到文件。

经理类能够实现信息打印,保存信息到文件。

销售经理类,新增部门销售额成员变量,计算工资,保存信息到文件的方法。
兼职推销员类,新增销售额成员变量。

兼职技术员类,新增工作时间类。

3.2 类的接口设计

  1. /*******************************************************************/
  2. /* 类定义 */
  3. /*******************************************************************/
  4. //员工
  5. class Man
  6. {
  7. public:
  8. string name; //姓名
  9. int ID; //编号
  10. int rank; //级别
  11. double salary; //当月薪水
  12. Man(string name); //构造函数
  13. void print(); //输出函数
  14. void SaveInfoToFile();
  15. int UpRankTo(int newRank); //升级函数
  16. };
  17. class Manager: public Man //经理
  18. {
  19. public:
  20. Manager(string name); //构造函数
  21. void print();
  22. void SaveInfoToFile();
  23. };
  24. class Salemanager: public Man //销售经理
  25. {
  26. public:
  27. double salesum; //部门总销售额
  28. Salemanager(string name, double salesum); //构造函数
  29. void print();
  30. void SetNewSalary(double salesum);
  31. void SaveInfoToFile();
  32. };
  33. class Saleman: public Man //兼职推销员
  34. {
  35. public:
  36. double saleroom; //销售额
  37. Saleman(string name, double saleroom); //构造函数
  38. void print();
  39. void SaveInfoToFile();
  40. };
  41. class Technologist: public Man //兼职技术员
  42. {
  43. public:
  44. double workTime; //工作时间
  45. Technologist(string name, double workTime); //构造函数
  46. void print();
  47. void SaveInfoToFile();
  48. };

因为每个类的成员变量都不同,因此print方法都不同,而且由于每个类的信息要单独存放,因此每个类的SaveInfoToFile方法也不同。

3.3 类的实现

  1. /*******************************************************************/
  2. /* 类函数实现 */
  3. /*******************************************************************/
  4. static int count = 1000; //编号基础值1000
  5. vector <Man*> man; //基础人员
  6. vector <Manager*> mag; //经理
  7. vector <Technologist*> tec; //技术员动态数组
  8. vector <Salemanager*> slmag;//销售经理
  9. vector <Saleman*> sl; //推销员
  10. Man::Man(string name) //基础类构造函数
  11. {
  12. this->name = name;
  13. this->rank = 1;
  14. this->salary = 0;
  15. this->ID = count++;
  16. }
  17. void Man::print()
  18. {
  19. cout << "id: " << this->ID;
  20. cout << " name: " << this->name;
  21. cout << " rank: " << this->rank;
  22. cout << " position: None\t";
  23. cout << " salary: " << this->salary << endl;
  24. }
  25. int Man::UpRankTo(int rank) //升级函数
  26. {
  27. int workTime, saleroom;
  28. if(rank == 1) //经理
  29. {
  30. Manager *m = new Manager(this->name);
  31. mag.push_back(m); //入栈
  32. this->rank = 4;
  33. }
  34. else if(rank == 2) //销售经理
  35. {
  36. Salemanager *s = new Salemanager(this->name, 0);
  37. slmag.push_back(s); //入栈
  38. this->rank = 3;
  39. }
  40. else if(rank == 3) //技术员
  41. {
  42. cout << "输入他的工作时间:" ;
  43. cin >> workTime;
  44. Technologist *t = new Technologist(this->name, workTime);
  45. tec.push_back(t); //入栈
  46. this->rank = 3;
  47. }
  48. else if(rank == 4) //推销员
  49. {
  50. cout << "输入他的销售额:" ;
  51. cin >> saleroom;
  52. Saleman *t = new Saleman(this->name, saleroom);
  53. sl.push_back(t); //入栈
  54. this->rank = 1;
  55. }
  56. else
  57. return 0; //错误
  58. return 1; //成功升级
  59. }
  60. Manager::Manager(string name):Man(name) //经理构造函数
  61. {
  62. this->rank = 4;
  63. this->salary = 8000;
  64. }
  65. void Manager::print()
  66. {
  67. cout << "id: " << this->ID;
  68. cout << " name: " << this->name;
  69. cout << " rank: " << this->rank;
  70. cout << " position: Manager\t";
  71. cout << " salary: " << this->salary << endl;
  72. }
  73. void Manager::SaveInfoToFile() //保存信息到文件
  74. {
  75. ofstream outfile;
  76. outfile.open("aaManager1.txt", ios_base::out | ios::app); //在文件尾插入新内容
  77. outfile << "id: " << this->ID;
  78. outfile << " name: " << this->name;
  79. outfile << " rank: " << this->rank;
  80. outfile << " position: Manager\t";
  81. outfile << " salary: " << this->salary << endl;
  82. outfile.close();
  83. }
  84. Salemanager::Salemanager(string name, double salesum):Man(name) //销售经理构造函数
  85. {
  86. this->rank = 3;
  87. this->salesum = salesum;
  88. this->salary = 5000 + 0.005 * salesum; //固定工资5000,提成0.005
  89. }
  90. void Salemanager::print()
  91. {
  92. cout << "id: " << this->ID;
  93. cout << " name: " << this->name;
  94. cout << " rank: " << this->rank;
  95. cout << " position: Salemanager\t";
  96. cout << " salary: " << this->salary;
  97. cout << " salesum: " << this->salesum << endl;
  98. }
  99. void Salemanager::SetNewSalary(double salesum) //根据部门销售额总和计算薪资
  100. {
  101. this->salesum = salesum;
  102. this->salary = 5000 + 0.005 * salesum; //固定工资5000,提成0.005
  103. }
  104. void Salemanager::SaveInfoToFile() //保存信息到文件
  105. {
  106. ofstream outfile;
  107. outfile.open("aaSalemanager1.txt", ios_base::out | ios::app); //在文件尾插入新内容
  108. outfile << "id: " << this->ID;
  109. outfile << " name: " << this->name;
  110. outfile << " rank: " << this->rank;
  111. outfile << " position: Salemanager\t";
  112. outfile << " salary: " << this->salary;
  113. outfile << " salesum: " << this->salesum << endl;
  114. outfile.close();
  115. }
  116. Technologist::Technologist(string name, double workTime):Man(name)//技术员构造函数
  117. {
  118. this->rank = 3;
  119. this->workTime = workTime;
  120. this->salary = workTime * 100; //每小时100元
  121. }
  122. void Technologist::print()
  123. {
  124. cout << "id: " << this->ID;
  125. cout << " name: " << this->name;
  126. cout << " rank: " << this->rank;
  127. cout << " position: Technologist\t";
  128. cout << " salary: " << this->salary;
  129. cout << " workTime: " << this->workTime << endl;
  130. }
  131. void Technologist::SaveInfoToFile() //保存信息到文件
  132. {
  133. ofstream outfile;
  134. outfile.open("aaTechnologist1.txt", ios_base::out | ios::app); //在文件尾插入新内容
  135. outfile << "id: " << this->ID;
  136. outfile << " name: " << this->name;
  137. outfile << " rank: " << this->rank;
  138. outfile << " position: Technologist\t";
  139. outfile << " salary: " << this->salary;
  140. outfile << " workTime: " << this->workTime << endl;
  141. outfile.close();
  142. }
  143. Saleman::Saleman(string name, double saleroom):Man(name) //推销员构造函数
  144. {
  145. this->saleroom = saleroom;
  146. this->salary = 0.04 * saleroom;
  147. }
  148. void Saleman::print()
  149. {
  150. cout << "id: " << this->ID;
  151. cout << " name: " << this->name;
  152. cout << " rank: " << this->rank;
  153. cout << " position: Saleman\t";
  154. cout << " salary: " << this->salary;
  155. cout << " saleroom: " << this->saleroom << endl;
  156. }
  157. void Saleman::SaveInfoToFile()
  158. {
  159. ofstream outfile;
  160. outfile.open("aaSaleman1.txt", ios_base::out | ios::app); //在文件尾插入新内容
  161. outfile << "id: " << this->ID;
  162. outfile << " name: " << this->name;
  163. outfile << " rank: " << this->rank;
  164. outfile << " position: Saleman\t";
  165. outfile << " salary: " << this->salary;
  166. outfile << " saleroom: " << this->saleroom << endl;
  167. outfile.close();
  168. }

4 基于控制台的应用程序

4.1 主函数设计

主函数又有几个功能,分别实现信息读取,信息存储,信息更新,获取所有信息,菜单操作几个功能。

  1. //信息读取函数
  2. void LoadInfo()
  3. {
  4. ifstream infile;
  5. string name;
  6. int workTime; //技术员工作时间
  7. int saleroom; //推销员月销售额
  8. infile.open("Saleman.txt", ios::in); //打开推销员文件
  9. while(infile >> name) //判断是不是到文件结尾
  10. {
  11. infile >> saleroom;
  12. Saleman *t = new Saleman(name, saleroom);
  13. sl.push_back(t); //入栈
  14. }
  15. infile.close();
  16. infile.open("Technologist.txt", ios::in); //打开技术员文件
  17. while(infile >> name) //判断是不是到文件结尾
  18. {
  19. infile >> workTime;
  20. Technologist *t = new Technologist(name, workTime);
  21. tec.push_back(t); //入栈
  22. }
  23. infile.close();
  24. infile.open("Salemanager.txt", ios::in); //打开销售经理文件
  25. while(infile >> name) //判断是不是到文件结尾
  26. {
  27. Salemanager *t = new Salemanager(name, 0);
  28. slmag.push_back(t); //入栈
  29. }
  30. infile.close();
  31. infile.open("Manager.txt", ios::in); //打开经理文件
  32. while(infile >> name) //判断是不是到文件结尾
  33. {
  34. infile >> saleroom;
  35. Manager *t = new Manager(name);
  36. mag.push_back(t); //入栈
  37. }
  38. infile.close();
  39. }
  40. //信息存储
  41. void Store()
  42. {
  43. for(int i = 0; i < sl.size(); i++) //推销员
  44. sl.at(i)->SaveInfoToFile();
  45. for(int i = 0; i < tec.size(); i++) //技术员
  46. tec.at(i)->SaveInfoToFile();
  47. for(int i = 0; i < slmag.size(); i++) //销售经理
  48. slmag.at(i)->SaveInfoToFile();
  49. for(int i = 0; i < mag.size(); i++) //经理
  50. mag.at(i)->SaveInfoToFile();
  51. }
  52. //信息更新
  53. void UpData()
  54. {
  55. double saleSum = 0;
  56. for(int i = 0; i < sl.size(); i++) //推销员
  57. saleSum += sl.at(i)->saleroom;
  58. for(int i = 0; i < slmag.size(); i++) //销售经理
  59. slmag.at(i)->SetNewSalary(saleSum);
  60. }
  61. //获取所有信息
  62. void GetAllInfo()
  63. {
  64. for(int i = 0; i < sl.size(); i++) //推销员
  65. sl.at(i)->print();
  66. for(int i = 0; i < tec.size(); i++) //技术员
  67. tec.at(i)->print();
  68. for(int i = 0; i < slmag.size(); i++) //销售经理
  69. slmag.at(i)->print();
  70. for(int i = 0; i < mag.size(); i++) //经理
  71. mag.at(i)->print();
  72. }
  73. //菜单操作函数
  74. void menu()
  75. {
  76. int cmd;
  77. static int updataFlag = 0;
  78. static int loadFlag = 0;
  79. cout << "1.Load 2.Updata 3.Dispaly 4.Store 0.Exit\n";
  80. cin >> cmd;
  81. switch(cmd)
  82. {
  83. case 1:
  84. LoadInfo();
  85. loadFlag = 1; //读取数据标志位置1
  86. updataFlag = 0; //清空数据更新标志位
  87. cout << "OK!\n";
  88. break;
  89. case 2:
  90. if(loadFlag == 1) //判断是否已经读取数据
  91. {
  92. UpData();
  93. updataFlag = 1; //数据更新标志位置1
  94. cout << "OK!\n";
  95. }
  96. else
  97. cout << "Please Load First!\n";
  98. break;
  99. case 3:
  100. if(loadFlag == 1) //判断是否已经读取数据
  101. GetAllInfo();
  102. else
  103. cout << "Please Load First!\n";break;
  104. case 4:
  105. if(updataFlag == 1) //判断是否已经更新数据(销售经理薪资)
  106. {
  107. Store();
  108. cout << "OK!\n";
  109. }
  110. else
  111. cout << "Please UpData First!\n";
  112. break;
  113. case 0:
  114. exit(0);
  115. }
  116. }
  117. //主函数
  118. int main()
  119. {
  120. cout << "Author\t:Liyi\nDate\t:20171222\nCopyright (C) 2017 Liyi. All Rights Reserved.\n\n\n";
  121. while(1)
  122. menu();
  123. return 0;
  124. }

主函数中循环执行menu函数,通过用户输入的操作指令实现相应的功能。

4.2 运行结果及分析

能够正确读取文件信息,并做出相应的运算之后在进行文件信息写入。

要注意的是先读取数据才能显示数据,先对数据更新才能进行数据保存。

文件处理之前的文件内容,程序读取这些文件的内容信息。

信息处理完之后存储的结果信息。

5 基于MFC的应用程序

MFC的图形界面程序设计可在上述类设计的基础上进行改造,MFC的图形界面程序与DOS界面程序的主要不同点是:MFC图形界面程序与DOS界面程序的输入输出方式不同,DOS界面程序采用字符交互式实现数据输入输出,主要通过cin,cout等I/O流实现,而MFC的图形程序界面采用标准Windows窗口和控件实现输入输出,因此必须在MFC类的框架下加入上面所设计的矩阵和方程组类,并通过图形界面的输入输出改造来完成。

5.1 图形界面设计

首先在VC中建立MFC AppWizard(exe)工程,名称为DD,并在向导的Step1中选择Dialog based,即建立基于对话框的应用程序,如图所示。

将对话框资源中的默认对话框利用工具箱改造成如图所示界面。

5.2 程序代码设计

为了能够将对话框界面上的控件能够与代码联系起来,需要为Edit Box控件和Radio控件建立Member Variables,按Ctrl+w键进入MFC ClassWizard界面,选择Member Variables选项卡,可显示成员变量设置界面,如图所示。

为了能够使按钮做出相应的响应,需要为按钮添加事件响应函数。

如图所示,清除按钮事件响应函数是OnButtonClear(),确定按键响应函数是OnBUTTONqueding();

下面是编写代码的重要阶段,可以借鉴在设计基于DOS界面的控制台应用程序的代码,并将其作必要的改写,具体改写内容如下。

  1. HCURSOR CDDDlg::OnQueryDragIcon()
  2. {
  3. return (HCURSOR) m_hIcon;
  4. }
  5. void CDDDlg::OnRadioLoad()
  6. {
  7. // TODO: Add your control notification handler code here
  8. m_radio = 1;
  9. }
  10. void CDDDlg::OnRADIOxianshi()
  11. {
  12. // TODO: Add your control notification handler code here
  13. m_radio = 3;
  14. }
  15. void CDDDlg::OnRadioUpdata()
  16. {
  17. // TODO: Add your control notification handler code here
  18. m_radio = 2;
  19. }
  20. void CDDDlg::OnRadioStore()
  21. {
  22. // TODO: Add your control notification handler code here
  23. m_radio = 4;
  24. }
  25. void CDDDlg::OnBUTTONqueding()
  26. {
  27. // TODO: Add your control notification handler code here
  28. static int updataFlag = 0;
  29. static int loadFlag = 0;
  30. switch(m_radio)
  31. {
  32. case 1:
  33. LoadInfo();
  34. loadFlag = 1; //读取数据标志位置1
  35. updataFlag = 0; //清空数据更新标志位
  36. MessageBox(_T("Load OK!"));
  37. break;
  38. case 2:
  39. if(loadFlag == 1) //判断是否已经读取数据
  40. {
  41. UpData();
  42. updataFlag = 1; //数据更新标志位置1
  43. MessageBox(_T("Updata OK!"));
  44. }
  45. else
  46. MessageBox(_T("Please Load First!!"));
  47. break;
  48. case 3:
  49. if(loadFlag == 1) //判断是否已经读取数据
  50. {
  51. UpdateData(true);
  52. m_edit = GetAllInfo().c_str();
  53. UpdateData(false);
  54. }
  55. else
  56. MessageBox(_T("Please Load First!!"));break;
  57. case 4:
  58. if(updataFlag == 1) //判断是否已经更新数据(销售经理薪资)
  59. {
  60. Store();
  61. MessageBox(_T("Store OK!"));
  62. }
  63. else
  64. MessageBox(_T("Please UpData First!!"));
  65. break;
  66. case 0:
  67. exit(0);
  68. }
  69. }
  70. void CDDDlg::OnButtonClear() //清除按钮
  71. {
  72. // TODO: Add your control notification handler code here
  73. UpdateData(true);
  74. m_edit = "";
  75. UpdateData(false);
  76. }
  77. void LoadInfo()
  78. {
  79. ifstream infile;
  80. ifstream infile2;
  81. ifstream infile3;
  82. ifstream infile4;
  83. string name;
  84. int workTime; //技术员工作时间
  85. int saleroom; //推销员月销售额
  86. infile.open("Saleman.txt", ios::in); //打开推销员文件
  87. while(infile >> name) //判断是不是到文件结尾
  88. {
  89. infile >> saleroom;
  90. Saleman *t = new Saleman(name, saleroom);
  91. sl.push_back(t); //入栈
  92. }
  93. infile.close();
  94. infile2.open("Technologist.txt", ios::in); //打开技术员文件
  95. while(infile2 >> name) //判断是不是到文件结尾
  96. {
  97. infile2 >> workTime;
  98. Technologist *t = new Technologist(name, workTime);
  99. tec.push_back(t); //入栈
  100. }
  101. infile2.close();
  102. infile3.open("Salemanager.txt", ios::in); //打开销售经理文件
  103. while(infile3 >> name) //判断是不是到文件结尾
  104. {
  105. Salemanager *t = new Salemanager(name, 0);
  106. slmag.push_back(t); //入栈
  107. }
  108. infile3.close();
  109. infile4.open("Manager.txt", ios::in); //打开经理文件
  110. while(infile4 >> name) //判断是不是到文件结尾
  111. {
  112. infile4 >> saleroom;
  113. Manager *t = new Manager(name);
  114. mag.push_back(t); //入栈
  115. }
  116. infile4.close();
  117. }
  118. //信息存储
  119. void Store()
  120. {
  121. int i;
  122. for(i = 0; i < sl.size(); i++) //推销员
  123. sl.at(i)->SaveInfoToFile();
  124. for(i = 0; i < tec.size(); i++) //技术员
  125. tec.at(i)->SaveInfoToFile();
  126. for(i = 0; i < slmag.size(); i++) //销售经理
  127. slmag.at(i)->SaveInfoToFile();
  128. for(i = 0; i < mag.size(); i++) //经理
  129. mag.at(i)->SaveInfoToFile();
  130. }
  131. //信息更新
  132. void UpData()
  133. {
  134. int i;
  135. double saleSum = 0;
  136. for(i = 0; i < sl.size(); i++) //推销员
  137. saleSum += sl.at(i)->saleroom;
  138. for(i = 0; i < slmag.size(); i++) //销售经理
  139. slmag.at(i)->SetNewSalary(saleSum);
  140. }
  141. string GetAllInfo()
  142. {
  143. int i;
  144. string re;
  145. for(i = 0; i < sl.size(); i++) //推销员
  146. re += sl.at(i)->print();
  147. for(i = 0; i < tec.size(); i++) //技术员
  148. re += tec.at(i)->print();
  149. for(i = 0; i < slmag.size(); i++) //销售经理
  150. re += slmag.at(i)->print();
  151. for(i = 0; i < mag.size(); i++) //经理
  152. re += mag.at(i)->print();
  153. return re;
  154. }
  155. // employee.h //类定义文件
  156. //
  157. #ifndef _EMPLOYEE_H
  158. #define _EMPLOYEE_H
  159. #include <iostream>
  160. #include <string>
  161. #include <sstream> //字符串流
  162. #include <fstream> //文件操作
  163. #include <vector> //动态数组
  164. using namespace std;
  165. string itos(int i) // 将int 转换成string
  166. {
  167. stringstream s;
  168. s << i;
  169. return s.str();
  170. }
  171. /*******************************************************************/
  172. /* 类定义 */
  173. /*******************************************************************/
  174. class Man //员工
  175. {
  176. public:
  177. string name; //姓名
  178. int ID; //编号
  179. int rank; //级别
  180. double salary; //当月薪水
  181. Man(string name); //构造函数
  182. string print(); //输出函数
  183. void SaveInfoToFile();
  184. int UpRankTo(int newRank); //升级函数
  185. };
  186. class Manager: public Man //经理
  187. {
  188. public:
  189. Manager(string name); //构造函数
  190. string print();
  191. void SaveInfoToFile();
  192. };
  193. class Salemanager: public Man //销售经理
  194. {
  195. public:
  196. double salesum; //部门总销售额
  197. Salemanager(string name, double salesum); //构造函数
  198. string print();
  199. void SetNewSalary(double salesum);
  200. void SaveInfoToFile();
  201. };
  202. class Saleman: public Man //兼职推销员
  203. {
  204. public:
  205. double saleroom; //销售额
  206. Saleman(string name, double saleroom); //构造函数
  207. string print();
  208. void SaveInfoToFile();
  209. };
  210. class Technologist: public Man //兼职技术员
  211. {
  212. public:
  213. double workTime; //工作时间
  214. Technologist(string name, double workTime); //构造函数
  215. string print();
  216. void SaveInfoToFile();
  217. };
  218. /*******************************************************************/
  219. /* 类函数实现 */
  220. /*******************************************************************/
  221. static int count = 1000; //编号基础值1000
  222. vector <Man*> man; //基础人员
  223. vector <Manager*> mag; //经理
  224. vector <Technologist*> tec; //技术员动态数组
  225. vector <Salemanager*> slmag;//销售经理
  226. vector <Saleman*> sl; //推销员
  227. Man::Man(string name) //基础类构造函数
  228. {
  229. this->name = name;
  230. this->rank = 1;
  231. this->salary = 0;
  232. this->ID = count++;
  233. }
  234. string Man::print()
  235. {
  236. string re;
  237. re = "id: " + itos(this->ID) + " name: " + this->name +
  238. " rank: " + itos(this->rank) + " position: None\t" +
  239. " salary: " + itos(this->salary) + "\r\n";
  240. return re;
  241. }
  242. int Man::UpRankTo(int rank) //升级函数
  243. {
  244. int workTime, saleroom;
  245. if(rank == 1) //经理
  246. {
  247. Manager *m = new Manager(this->name);
  248. mag.push_back(m); //入栈
  249. this->rank = 4;
  250. }
  251. else if(rank == 2) //销售经理
  252. {
  253. Salemanager *s = new Salemanager(this->name, 0);
  254. slmag.push_back(s); //入栈
  255. this->rank = 3;
  256. }
  257. else if(rank == 3) //技术员
  258. {
  259. cout << "输入他的工作时间:" ;
  260. cin >> workTime;
  261. Technologist *t = new Technologist(this->name, workTime);
  262. tec.push_back(t); //入栈
  263. this->rank = 3;
  264. }
  265. else if(rank == 4) //推销员
  266. {
  267. cout << "输入他的销售额:" ;
  268. cin >> saleroom;
  269. Saleman *t = new Saleman(this->name, saleroom);
  270. sl.push_back(t); //入栈
  271. this->rank = 1;
  272. }
  273. else
  274. return 0; //错误
  275. return 1; //成功升级
  276. }
  277. Manager::Manager(string name):Man(name) //经理构造函数
  278. {
  279. this->rank = 4;
  280. this->salary = 8000;
  281. }
  282. string Manager::print()
  283. {
  284. string re;
  285. re = "id: " + itos(this->ID) + " name: " + this->name +
  286. " rank: " + itos(this->rank) + " position: Manager\t" +
  287. " salary: " + itos(this->salary) + "\r\n";
  288. return re;
  289. }
  290. void Manager::SaveInfoToFile() //保存信息到文件
  291. {
  292. ofstream outfile;
  293. outfile.open("aaManager1.txt", ios_base::out | ios::app); //在文件尾插入新内容
  294. outfile << "id: " << this->ID;
  295. outfile << " name: " << this->name;
  296. outfile << " rank: " << this->rank;
  297. outfile << " position: Manager\t";
  298. outfile << " salary: " << this->salary << endl;
  299. outfile.close();
  300. }
  301. Salemanager::Salemanager(string name, double salesum):Man(name) //销售经理构造函数
  302. {
  303. this->rank = 3;
  304. this->salesum = salesum;
  305. this->salary = 5000 + 0.005 * salesum; //固定工资5000,提成0.005
  306. }
  307. string Salemanager::print()
  308. {
  309. string re;
  310. re = "id: " + itos(this->ID) + " name: " + this->name +
  311. " rank: " + itos(this->rank) + " position: Salemanager\t" +
  312. " salary: " + itos(this->salary) + " salesum: " + itos(this->salesum) + "\r\n";
  313. return re;
  314. }
  315. void Salemanager::SetNewSalary(double salesum) //根据部门销售额总和计算薪资
  316. {
  317. this->salesum = salesum;
  318. this->salary = 5000 + 0.005 * salesum; //固定工资5000,提成0.005
  319. }
  320. void Salemanager::SaveInfoToFile() //保存信息到文件
  321. {
  322. ofstream outfile;
  323. outfile.open("aaSalemanager1.txt", ios_base::out | ios::app); //在文件尾插入新内容
  324. outfile << "id: " << this->ID;
  325. outfile << " name: " << this->name;
  326. outfile << " rank: " << this->rank;
  327. outfile << " position: Salemanager\t";
  328. outfile << " salary: " << this->salary;
  329. outfile << " salesum: " << this->salesum << endl;
  330. outfile.close();
  331. }
  332. Technologist::Technologist(string name, double workTime):Man(name)//技术员构造函数
  333. {
  334. this->rank = 3;
  335. this->workTime = workTime;
  336. this->salary = workTime * 100; //每小时100元
  337. }
  338. string Technologist::print()
  339. {
  340. string re;
  341. re = "id: " + itos(this->ID) + " name: " + this->name +
  342. " rank: " + itos(this->rank) + " position: Technologist\t" +
  343. " salary: " + itos(this->salary) + " workTime: " + itos(this->workTime) + "\r\n";
  344. return re;
  345. }
  346. void Technologist::SaveInfoToFile() //保存信息到文件
  347. {
  348. ofstream outfile;
  349. outfile.open("aaTechnologist1.txt", ios_base::out | ios::app); //在文件尾插入新内容
  350. outfile << "id: " << this->ID;
  351. outfile << " name: " << this->name;
  352. outfile << " rank: " << this->rank;
  353. outfile << " position: Technologist\t";
  354. outfile << " salary: " << this->salary;
  355. outfile << " workTime: " << this->workTime << endl;
  356. outfile.close();
  357. }
  358. Saleman::Saleman(string name, double saleroom):Man(name) //推销员构造函数
  359. {
  360. this->saleroom = saleroom;
  361. this->salary = 0.04 * saleroom;
  362. }
  363. string Saleman::print()
  364. {
  365. string re;
  366. re = "id: " + itos(this->ID) + " name: " + this->name +
  367. " rank: " + itos(this->rank) + " position: Saleman\t" +
  368. " salary: " + itos(this->salary) + " saleroom: " + itos(this->saleroom) + "\r\n";
  369. return re;
  370. }
  371. void Saleman::SaveInfoToFile()
  372. {
  373. ofstream outfile;
  374. outfile.open("aaSaleman1.txt", ios_base::out | ios::app); //在文件尾插入新内容
  375. outfile << "id: " << this->ID;
  376. outfile << " name: " << this->name;
  377. outfile << " rank: " << this->rank;
  378. outfile << " position: Saleman\t";
  379. outfile << " salary: " << this->salary;
  380. outfile << " saleroom: " << this->saleroom << endl;
  381. outfile.close();
  382. }
  383. #endif

5.3 运行结果及分析

需要先读取数据才能进行后续操作。

需要先更新数据才能保存数据。

结 论

MFC程序与DOS界面程序编写的最大不同是程序员需要将编程精力放在图形界面设计、图形界面输入输出以及界面元素和代码对应转换等问题上,而这些问题在DOS界面程序中是不存在的,因此,初学MFC的编程者会对此感到困难,然而,当你编写出一个基于Windows界面的程序时,所获得的满足程度远远大于简单的DOS界面程序,况且基于Windows的图形界面的程序设计已成为主流,作为程序员而言,是非学会不可的。

本次课程设计作为编写Windows程序的初步尝试,能够实现程序的主要功能,可以说是取得了成功,然而好的程序绝不仅仅是只有功能性这一个指标,本此编写的MFC程序虽然能实现所需功能,但从面向对象程序设计理念和图形界面设计要求来说,尚存在不足,主要包括以下几个方面:

  • 图形界面太过于简陋,没有良好的使用体验

  • MFC程序中没有很好的使用其特有的数据类型,没有把MFC的性能发挥好

  • DOS界面程序中对各个类的方法的工作效率没有做到很好的优化

上传的附件 cloud_download 小型人员信息管理系统的设计与实现.7z ( 801.14kb, 41次下载 )
error_outline 下载需要9点积分

发送私信

白色衣服的背影

5
文章数
4
评论数
eject