C++语言制作员工信息录入和显示表1/2

C++语言制作员工信息录入和显示表

1.运行程序,输入参数,结果如下。

输入一个员工的信息,工号为10086,姓名为peter,性别为男,工龄为2,部门为行政科,输出结果如下。
在这里插入图片描述

2.部分源代码

#include<iostream>
using namespace std;
enum depmt{produce,sale,admin,elses};
struct Person
	{
		int num;
		char name[8];
		bool sex;
		int workage;
		depmt depmts;
	};
void main ()
{
    Person per1,per2;
	cout<<"输入信息:"<<endl;
	cout<<"   工号:";
	cin>>per1.num;
	cout<<"   姓名:";
	cin>>per1.name;
	cout<<"   性别:(1:男;0:女)";
	int t;
	cin>>t;
	per1.sex=(t!=0?true:false);
	cout<<"   工龄:";
	cin>>per1.workage;
	cout<<"   部门(0:生产科;1:销售科;2:行政科;3:其他;):";
	cin>>t;
	per1.depmts=(t==0?produce:(t==1?sale:(t==2?admin:elses)));
	per2=per1;
	******
		(per2.depmts==sale?"销售科":\
		(per2.depmts==admin?"行政科":"其他")))<<endl;
}
#include<iostream> #include<string> #include<fstream> #include <vector> #include <functional> #include <algorithm> #include<string> using namespace std; class Employee{ protected: int number; string name; public: Employee(){} Employee(int num,string nam); void setname(string n); void setnumber(int n); string getname(void); int getnumber(void); virtual void display(void); friend bool less_number(const Employee & m1, const Employee & m2); }; class EmployeeDetial:public Employee{ protected: string sex; int age; public: EmployeeDetial(){} EmployeeDetial(int num,string nam,string se,int ag); void setsex (string s); void setage(int a); string getsex(void); int getage(void); void display(void); friend bool less_age(const EmployeeDetial & m1, const EmployeeDetial & m2); }; void Employee::setname(string n){ name=n; } void Employee::setnumber(int n){ number=n; } string Employee::getname(void){ return name; } int Employee::getnumber(void){ return number; } void Employee::display(void){ // cout<<"E.display"<<endl; cout<<number<<" "<<name<<endl; } void EmployeeDetial::setsex(string s){ sex=s; } void EmployeeDetial::setage(int a){ age=a; } string EmployeeDetial::getsex(void){ return sex; } int EmployeeDetial::getage(void){ return age; } void EmployeeDetial::display(void){ // cout<<"ED.display"<<endl; cout<<number<<" "<<name<<" "<<sex <<" "<<age<<" "<<endl; } EmployeeDetial::EmployeeDetial(int num,string nam,string se,int ag){ number=num; name=nam; sex=se; age=ag; } Employee::Employee(int num,string nam){ number=num; name=nam; } bool less_number(const Employee & m1, const Employee & m2) { return m1.number<m2.number; } bool less_age(const EmployeeDetial & m1, const EmployeeDetial & m2) { return m1.age<m2.age; } using namespace std; static int counter=0; vector<EmployeeDetial> vED; vector<Employee> vE; void load_f_ED(){ int num,age; string name,sex; ifstream fin("EmployeeDetial.txt"); if(!fin){ cout<<"open file error!"<<endl; exit(1); } while(fin>>num>>name>>sex>>age){ // fin>>num>>name>>sex>>age; vED.push_back(EmployeeDetial(num,name,sex,age)); counter++; } fin.close(); } bool load_f_E(){ int num; string name; ifstream fin("Employee.txt"); if(!fin)return false; while(fin>>num>>name){ // fin>>num>>name>>sex>>age; vE.push_back(Employee(num,name)); } fin.close(); return true; } void display_E(){ for(int i=0;i<counter;i++)vE.at(i).display(); } void display_ED(){ for(int i=0;i<counter;i++){ vED.at(i).display(); } } void E_fout(){ ofstream fout("Employee.txt"); for(int i=0;i<counter;i++){ fout<<vE.at(i).getnumber()<<" "<<vE.at(i).getname()<<"\n"; } fout.close(); } void ED_fout(){ ofstream fout("EmployeeDetial.txt"); for(int i=0;i<counter;i++){ fout<<vED.at(i).getnumber()<<" "<<vED.at(i).getname()<<" "<< vED.at(i).getsex()<<" "<<vED.at(i).getage()<<"\n"; } fout.close(); } void E_ED(){ for(int i=0;i<counter;i++)vE.push_back(Employee(vED.at(i).getnumber(),vED.at(i).getname())); } void add(){ int num,age; string name,sex; cout<<"input the number:"<<endl; cin>>num; cout<<"input the name:"<<endl; cin>>name; cout<<"input the sex:"<<endl; cin>>sex; cout<<"input the age:"<<endl; cin>>age; vED.push_back(EmployeeDetial(num,name,sex,age)); vE.push_back(Employee(num,name)); counter++; cout<<"add success!"<<endl; } void delet(){ int a; cout<<"input the number which you want to delete:"<<endl; cin>>a; for(int i=0;i<counter;i++){ if(vED.at(i).getnumber()==a){ for(int n=i;n<counter-1;n++){ vED.at(n)=vED.at(n+1); vE.at(n)=vE.at(n+1); } } } counter--; } void screen(){ cout<<"1. 增加职工记录"<<endl; cout<<"2. 删除职工记录"<<endl; cout<<"3. 生成信息简"<<endl; cout<<"4. 显示原始记录"<<endl; cout<<"5. 显示记录"<<endl; cout<<"6. 原始记录排序"<<endl; cout<<"7. 简记录排序"<<endl; cout<<"8. 结束程序运行"<<endl; } int dd(){ int a; screen(); cin>>a; return a; } void ED_sort_age(){ sort(vED.begin(), vED.end(), less_age); } void ED_sort_number(){ sort(vED.begin(), vED.end(), less_number); } void E_sort_number(){ sort(vE.begin(), vE.end(), less_number); } int main(){ int a=dd(); while(a!=8){ load_f_ED(); if(!load_f_E())E_ED(); switch(a){ case 1: add();break; case 2:delet();break; case 3: E_fout();cout<<"success!"<<endl;break; case 4: display_ED();break; case 5:display_E();break; case 6:cout<<"1.按number排序"<<endl; cout<<"2.按age排序"<<endl; cin>>a; if(1==a){ED_sort_number();display_ED();break;} if(2==a){ED_sort_age();display_ED();break;} case 7:E_sort_number();display_E();break; default:cout<<"what are you doing?"<<endl;;break; } ED_fout(); E_fout(); vED.clear(); vE.clear(); counter=0; a=dd(); } return 0; }
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Material_Adam_Young

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值