标题:编写一个职工信息表,给点意见啊
只看楼主
林夏
Rank: 2
等 级:论坛游民
帖 子:6
专家分:10
注 册:2010-5-23
 问题点数:0 回复次数:5 
编写一个职工信息表,给点意见啊
一  设计题目一
    使用继承的方法,编写最多能输入10个职工的信息表,再根据这个表产生一个职工信息简表,并利用多态性实现信息的输出。
 基本设计要求
    设计要求实现如下功能:
1)    建立职工信息数据,包括职工编号、姓名、性别和年龄。
2)    根据职工信息表,建立只含有姓名和年龄的职工信息简表。
3)    使用继承的方法构造2个类,使用相应的对象数组放置10个职工信息。
4)    编写同名display()成员函数,用来输出数组的内容。
5)    另外编制一个函数printer(),用来根据实际对象输出它们的内容。

最好是用图形界面。
我QQ邮箱:qylinxia@   ,

[ 本帖最后由 林夏 于 2010-6-16 18:57 编辑 ]
搜索更多相关主题的帖子: 职工 意见 编写 
2010-06-15 17:14
林夏
Rank: 2
等 级:论坛游民
帖 子:6
专家分:10
注 册:2010-5-23
得分:0 
a i
2010-06-17 10:21
林夏
Rank: 2
等 级:论坛游民
帖 子:6
专家分:10
注 册:2010-5-23
得分:0 
有人帮帮忙不???
2010-06-17 10:22
说谎的爱人1
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-6-18
得分:0 
我来
2010-06-22 10:11
南国利剑
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:29
帖 子:1165
专家分:3536
注 册:2010-4-12
得分:0 
来看看。把代码贴出来看看

南国利剑
2010-06-22 11:20
林夏
Rank: 2
等 级:论坛游民
帖 子:6
专家分:10
注 册:2010-5-23
得分:0 
#include <iostream>
#include <fstream>  
#include <string>
#define NUM 10
using namespace std;
ofstream fsimtab("SimTale.txt",ios::out);
ofstream fdettab("DetTab.txt",ios::out);
ifstream fdata("xinxi.txt",ios::in);  
class worker  //基类
{
public:
        string num;
        string name;
        char sex;
        int age;
        virtual void display() {}
};
class sworker: public worker //派生类
{
public:
        virtual void display();
};
class dworker: public worker  //派生类
{
public:
        virtual void display();
};


int menu();
float add(dworker a[], int &n);
float produce(dworker det[], sworker sim[],int &n);
float printer(worker *pt, int &n);
void Read(dworker a[],int &n)
{
        ifstream Re("date.txt",ios::in);
    Re>>n;
        for(int i=0;i<n;i++)
        {
                Re>>a[i].num;
                Re>>a[i].name;
                Re>>a[i].sex;
                Re>>a[i].age;
        }
        Re.close();
}
void Write(dworker a[],int &n)
{
        ofstream Re("date.txt",ios::out);
    Re<<n<<endl;
        for(int i=0;i<n;i++)
        {
                Re<<a[i].num<<endl;
                Re<<a[i].name<<endl;
                Re<<a[i].sex<<endl;
                Re<<a[i].age<<endl;
        }
        Re.close();
}
int main()
{
        sworker simtab[NUM];      
        dworker dettab[NUM];        
        int lastnum=0;
        string input;
        system("title 职工信息管理系统");
Read(dettab,lastnum);
produce(dettab, simtab,lastnum);
        bool exit=false;
        do{
                switch(menu())
                {
                case 1:char ch;
                     system("cls");  
                     

                    do
                    {
                     if (add(dettab,lastnum))
                     {cout<<"\t\t\t增加成功,是否再添加(y/n)?";
                     cin>>ch;}
                    
                     else
                         cout<<"\t\t\t可能数组已满,生成信息简表失败!";
                    
                    }while(ch=='y');
                    break;
                                                                                                                                                                    
                case 2: system("cls");
                        if (produce(dettab,simtab,lastnum))
                        {
                                cout<<"\t\t\t  ------生成信息简表成功------"<<endl;
                                
                        }
                        else
                                cout<<"生成信息简表失败!"<<endl;
                        cout<<"输入任意键返回主菜单:";
                        cin>>input;
                        //cin>>hold;
                        break;
                case 3: system("cls");

                    cout<<"\t\t\t     **********************"<<endl;
                    cout<<"\t\t\t     -----显示原始记录-----"<<endl;
                    cout<<"\t\t\t     **********************"<<endl;
                        if (printer(dettab,lastnum))
                               printer(dettab,lastnum);
                        else
                                cout<<"输入任意返回主菜单!"<<endl;
                        //cin>>hold;
                        cin>>input;
                        break;
                case 4: system("cls");
                        if (printer(simtab,lastnum))
                                cout<<"输入任意返回主菜单!"<<endl;
                        else
                                cout<<"输入任意返回主菜单!"<<endl;
                        cin>>input;
                        break;
                case 5:
                        exit=true;
           Write(dettab,lastnum);
                        break;
                }
        }while(exit==false);
        cout<<"谢谢使用!"<<endl;
        fsimtab.close();
        fdettab.close();
        fdata.close();
        return 0;
}
char f,m;
int menu()   
{
        int a=5;
  do{
        system("cls");  
        cout<<"********************************************************************************"<<endl;
        cout<<"\t\t\t--------职工信息管理系统--------"<<endl;
        cout<<"********************************************************************************"<<endl;
        cout<<"\t\t\t------------菜单选项------------"<<endl;
        cout<<endl;
        cout<<"\t\t***********************************************"<<endl;
        cout<<"\t\t\t*\t1.增加职工记录""         ""*"<<endl;
        cout<<"\t\t\t*\t2.生成信息简表""         ""*"<<endl;
        cout<<"\t\t\t*\t3.显示原始记录""         ""*"<<endl;
        cout<<"\t\t\t*\t4.显示简表记录""         ""*"<<endl;
        cout<<"\t\t\t*\t5.结束程序运行""         ""*"<<endl;
        cout<<"\t\t***********************************************"<<endl;
        cout<<"\t\t-----------------------------------------------"<<endl;
        cout<<"\t\t***********************************************"<<endl;
        cout<<"\t\t\t   请选择菜单(Enter):1-5:";
        cin>>a;
  } while(a<1||a>5);
        return a;
}
void sworker::display ()
{cout<<"      姓名:"<<name <<"\t\t\t年龄:"<<age<<endl;

        ;
fsimtab<<"      姓名: "<<name <<"\t\t\t年龄:"<<age<<endl;
        ;
        //cout<<"姓名:"<<name<<endl;
        //cout<<"年龄:"<<age<<endl;
        //fsimtab<<"姓名:"<<name<<endl;
        //fsimtab<<"年龄:"<<age<<endl;        
        fsimtab<<"\t\t\t********************"<<endl;
}
void dworker::display ()
{
        cout<<"\t\t\t    编号:"<<num<<endl;
        cout<<"\t\t\t    姓名:"<<name<<endl;
        cout<<"\t\t\t    性别:"<<sex<<endl;
        cout<<"\t\t\t    年龄:"<<age<<endl;
        fdettab<<"\t\t\t    编号:"<<num<<endl;
        fdettab<<"\t\t\t    姓名:"<<name<<endl;
        fdettab<<"\t\t\t    性别:"<<sex<<endl;
        fdettab<<"\t\t\t    年龄:"<<age<<endl;
        fdettab<<"*********************"<<endl;
}
float add(dworker a[],int &n)
{
  if (n<10)
  {
        cout<<"\t\t\t您选择的是:1.增加职工记录"<<endl;   
bool c;
        do{  c=true;
                cout<<"\t\t\t输入编号:";
                cin>>a[n].num;
   
        for(int k=0;k<n;k++)
        {         if(a[n].num==a[k].num)
        {    cout<<"\t\t\t输入编号重复!"<<endl;
             c=false;}
        }
        }while(c==false);
bool d;
        do{  d=true;
                cout<<"\t\t\t输入姓名:";
                cin>>a[n].name;   
            
        for(int k=0;k<n;k++)
        {         if(a[n].name==a[k].name)
        {    cout<<"\t\t\t输入姓名重复!"<<endl;
             d=false;}
        }
        }while(d==false);

        cout<<"\t\t\t请输入性别(g为女,m为男):";
        cin>>a[n].sex;
while(a[n].sex!='g'&&a[n].sex!='m')
        {cout<<"\t\t\t性别输入错误";
cout<<"\t\t\t请输入性别(g为女,m为男):";
        cin>>a[n].sex;}
    cout<<"\t\t\t请输入年龄:";
   
bool e;
    do{  e=true;
    cin>>a[n].age;
    if(a[n].age<=16&&a[n].age>=50)
    {cout<<"年龄小于16岁或大于50岁,请检查是否输入正确,重新输入:";
    e=false;}
    }
    while(e==false);
   
//    while(cin>>a[n].age)
//    {
//        if(a[n].age >=16&&a[n].age<=50)
//        {
//            break;
    //    }
    //    cout <<"\t\t\t年龄小于16或大于50,不符合要求,请重新输入."<<endl;
    //}

        n++;
        return 1;
  }
  else
        return 0;

}
float produce(dworker det[], sworker sim[],int &n)
{
        if(n<10)
        {
                for (int i=0;i<=n;i++)
                {
                        sim[i].name=det[i].name;
                        sim[i].age =det[i].age;
                }
                return 1;
        }
        else return 0;
}
float printer(worker *pt, int &n)
{
        for(int i=0;i<n;i++)
        {
                cout<<"********************************************************************************"<<endl;
               
                (pt+i)->display();
        }
        cout<<"********************************************************************************"<<endl;
        return 0;
}


能否修改一下,加上搜索和删除功能。谢谢!!!
2010-06-23 12:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-310340-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.298891 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved