请网友帮忙做简单设计

kangkaibg001 2009-06-15 09:39:58
虽然很简单 但自己还是做不好 渴望网友伸出贵手相助 题目要求如下
1、职工信息
设计要求:(标准vc++6.0调试后能正确运行)
设计要求实现如下功能:
(1)建立职工信息数据、包括职工编号、姓名、性别、工资、出生时间、参加工作时间和年龄(必须计算得到)
(2)根据职工信息。建立只含年龄姓名的职工子女子简表。(可选功能)
(3)使用继承方法构造3个类,(即雇员类--虚机类,教师类和个人类--派生类)使用相应的对象放置10个职工信息。
(4)编写同名display()成员函数,用来输出数组内容。
(5)按不同类别输出教职工信息,比如按系输出教师信息。
(6)要求对“ < <”和“>>”运算符进行重载。考虑到输入职工编号时,也会因为不小心引入空格,而且名字中也需要有空格,所以重载“>>”运算符时需要满足这个要求。
(7)抽取并计算职工的平均年龄。
(8)检索(查找)指定信息。(如按姓名检索、按年龄检索)
(9)参考界面如下:

增加一位教师记录
增加一位工人记录
显示全部职工记录
计算教师平均年龄
计算工人平均年龄
删除一个教师
删除一个工人
按系输出教师信息
按姓名检索所有信息
结束程序运行
...全文
37 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
pathuang68 2009-06-21
  • 打赏
  • 举报
回复
可怜的小朋友,还蛮诚信的!
pathuang68 2009-06-16
  • 打赏
  • 举报
回复
kangkaibg001 2009-06-16
  • 打赏
  • 举报
回复
这是部分代码 希望大家帮忙调试
#include "EmployeeInfo.h"
#include <iostream>

int main(int argc, char *argv[])
{
CManage cm;
int index;
//添加3个雇员

cm.AddEmployee();
cm.AddEmployee();
cm.AddEmployee();

//显示全部员工信息
cm.PrintTable();
cout<<"教师平均年龄为:"<<cm.getAveage(TEACHER);
cout<<"工作平均年年龄为:"<<cm.getAveage(WORKER);

cm.DelEmployee("王鑫");//删除一个名叫王鑫的员工

if ((index = cm.SearchWorker("王鑫")) != -1)
{
cout<<cm.InfoTable[index]
<<"删除成功!\n";
}
else cout<<"没有名叫王鑫的员工!\n";
//按姓名检索所有信息
//结束程序运行

return 0;
}



//=======================================
//File Name:EmployeeInfo.h
//=======================================
#ifndef _EMPLOYEE_INFO_H
#define _EMPLOYEE_INFO_H
#include <iostream>
#include <string>
using namespace std;
//---------------------------------------
enum WORKTYPE{TEACHER = 1,WORKER = 2};
//---------------------------------------
//类声明
class CManage;
class CEmployee;
class CTeacher;
class CWorker;
//---------------------------------------
//日期
struct sDate
{
int year,month,day;
void datedisplay() const;
};
//---------------------------------------
//雇员类
class CEmployee
{
int nID; //职工编号
int nType; //员工类别:教师或者工人
char strName[20]; //姓名
char cSex; //性别
double dWage; //工资
sDate sBirthDay; //出生时间
sDate sAttend; //参加工作时间
int iAge; //年龄
public:
int nAge() const; //计算年龄

//构造函数
//6个参数

CEmployee();
//打印当前员工信息
void virtual display(){};
~CEmployee(){}; //析构函数
friend ostream & operator<<(ostream & o,const CEmployee & e);
friend istream & operator>>(istream & is,CEmployee & e);
friend class CManage;
};
//---------------------------------------
//教师类
class CTeacher:public CEmployee
{
public:
void display(){cout<<(CEmployee)(*this)<<" "<<"教师";}
};

//---------------------------------------
//工人类
class CWorker:virtual public CEmployee
{
public:
void display(){cout<<(CEmployee)(*this)<<" "<<"工人";}
};
//---------------------------------------
//管理类
class CManage
{
int nNumber; //员工数量
public:
CEmployee InfoTable[100];//存储100个员工对象地址
public:
double getAveage(const int i = TEACHER);//计算平均年龄,默认为教师

int SearchWorker(const char * Name); //按姓名搜索
int SearchWorker(int ID); //按年龄搜索

int AddEmployee(); //添加一名员工
int DelEmployee(int i); //删除一名员工
int DelEmployee(const char * name);

void PrintTable(); //打印信息表
void SimpleDisplay(); //打印信息简表

void PrintByAge(); //根据年龄打印
void PrintByPre(); //根据职业打印

CManage();
~CManage(){};
};
//========================================
#endif



//==============================================
//File Name: EmployeeInfo.cpp
//==============================================
#include "EmployeeInfo.h"
#include <iostream>
#include <string>
#include <ctime>
#include <iomanip>
using namespace std;
//----------------------------------------------
//重载时间输出
void sDate::datedisplay() const
{
cout<<setw(4)<<setfill('0')<<year<<'-'<<setw(2)<<month<<'-'
<<setw(2)<<day<<setfill(' ')<<' ';
}
//----------------------------------------------
//雇员成员函数的实现
CEmployee::CEmployee()
{//构造函数
iAge = nAge(); //求年龄
}
//----------------------------------------------
int CEmployee::nAge() const
{
time_t now = time(0);
struct tm * timenow = localtime(&now);
return timenow->tm_year + 1900 - sBirthDay.year;
}
//----------------------------------------------
ostream & operator<<(ostream & o,const CEmployee & e)
{//包括职工编号、姓名、性别、工资、出生时间、参加工作时间和年龄
o <<left
<<setw(6)<<e.nID<<' '
<<setw(8)<<e.strName<<' '
<<setw(4)<<(e.cSex == 'M'?"男":"女")<<' '
<<setw(4)<<(e.nAge())<<' '
<<setw(6)<<e.dWage<<' '
<<right;
(e.sBirthDay).datedisplay();
(e.sAttend).datedisplay();
return o;
}
//----------------------------------------------
istream & operator>>(istream & is,CEmployee & e)
{
cout<<"请输入雇员类型:\n";
is>>e.nType;
cout<<"请输雇员编号:\n";
is>>e.nID;
fflush(stdin);
is.clear();
cout<<"请输入雇员姓名,换行结束(可以包括空格):\n";
is>>e.strName;
fflush(stdin);
is.clear();
cout<<"请输入雇员性别(M:男,F:女):\n";
is>>e.cSex;
cout<<"请输入雇员工资:\n";
is>>e.dWage;
fflush(stdin);
is.clear();
cout<<"请输入雇员出生年月日格式为:2007 02 04:\n";
is >>e.sBirthDay.year
>>e.sBirthDay.month
>>e.sBirthDay.day;
fflush(stdin);
is.clear();
cout<<"请输入雇员来校年月日格式为:2007 02 04:\n";
fflush(stdin);
is.clear();
is >>e.sAttend.year
>>e.sAttend.month
>>e.sAttend.day;
e.iAge = e.nAge();

return is;
}
//---------------------------------------
//管理类
double CManage::getAveage(const int i)
{//计算平均年龄
double sum = 0;
for (int i = 0;i < nNumber;i++)
{
if(InfoTable[i].nType == i)
sum += InfoTable[i].dWage;
}
return sum / (double)nNumber;
}
//---------------------------------------
int CManage::SearchWorker(const char * Name)
{//按姓名搜索
for (int i = 0;i < nNumber;i++)
{
if(strcmp(Name,InfoTable[i].strName) == 0)
return i;
}
return -1;
}
//---------------------------------------
int CManage::SearchWorker(int Age)
{//按年龄搜索
for (int i = 0;i < nNumber;i++)
{
if(InfoTable[i].iAge == Age)
return i;
}
return -1;
}
//---------------------------------------
int CManage::AddEmployee()
{//添加一名员工
cin>>InfoTable[nNumber];
nNumber++;
return 1;
}
//---------------------------------------
int CManage::DelEmployee(int i) //删除一名员工
{
if (i < 0 || i >= nNumber) return 0;
for (int index = i;index < nNumber;index--)
{
InfoTable[index] = InfoTable[index + 1];
}
nNumber--;
return 1;
}
//---------------------------------------
int CManage::DelEmployee(const char * name) //删除一名员工
{
int i = SearchWorker(name);
if (i < 0 || i >= nNumber) return 0;
for (int index = i;index < nNumber;index--)
{
InfoTable[index] = InfoTable[index + 1];
}
nNumber--;
return 1;
}
//---------------------------------------
void CManage::PrintTable()
{
cout<<"编号 姓名\n";
for(int i = 0;i < nNumber;i++)
{
cout<<InfoTable[i]<<endl;
}
cout<<endl;
}
//----------------------------------------
void CManage::SimpleDisplay()
{//打印信息简表
cout<<"编号 姓名\n";
for(int i = 0;i < nNumber;i++)
{
cout<<InfoTable[i]<<endl;
}
cout<<endl;
}
//----------------------------------------
void CManage::PrintByAge()
{//打印信息简表
int a[8] = {0};
for (int i = 0;i < nNumber;i++)
{
a[InfoTable[i].iAge / 10]++;
}
for (int i = 0;i < 8;i++)
{
cout<<i<<"~"<<10*i - 1<<"年龄段人数为:"
<<a[i]<<endl;
}
}
//----------------------------------------
void CManage::PrintByPre()
{
cout<<"编号 姓名\n";
for(int i = 0;i < nNumber;i++)
{
if (InfoTable[i].nType == TEACHER)
cout<<InfoTable[i]<<endl;
}
cout<<endl;
for(int i = 0;i < nNumber;i++)
{
if (InfoTable[i].nType == WORKER)
cout<<InfoTable[i]<<endl;
}
cout<<endl;
}
//---------------------------------------
CManage::CManage()
{
nNumber = 0;
}
//========================================
邮箱kangkaibg001@yahoo.cn
xiejhzwrgcky 2009-06-16
  • 打赏
  • 举报
回复
不错,顶。
antss 2009-06-16
  • 打赏
  • 举报
回复
不管使用不使用,能编写出来就好了.

能编才是结果.我觉得你的老师还是挺好的.不会出点不着边际的东西.

好好听老师的话.做个用功努力的孩子.

将来好好做一番事业出来.
gleen 2009-06-15
  • 打赏
  • 举报
回复
课程设计 没有使用性啊
adventurelw 2009-06-15
  • 打赏
  • 举报
回复
其实还是有点参考价值,至少能够分别入门以及什么都不知道。
tkminigame 2009-06-15
  • 打赏
  • 举报
回复
告诉你的老师,这种东西做出来没任何实用性,也没任何学习和参考的价值!
yel_hb 2009-06-15
  • 打赏
  • 举报
回复
又是课程设计~=_=!
觉得自己看书做比较好~要不行下源码改吧~网上多的是~

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧