#include <string.h>
#include <stdlib.h>
typedef struct work_long
{
int id
char name[33]
char sex
int age
} work_long
typedef struct work_s
{
char name[33]
int age
} work_s
void readin( work_long *wl, int n )
{
int i
for( i=0 i<n i++ )
{
printf( "姓名 序号 性别(F/M) 年龄:" )
scanf( "%s %d %c %d", wl[i].name, &wl[i].id, &wl[i].sex, &wl[i].age )
fflush( stdin )
}
}
void display( work_long *wl, int n )
{
int i
for( i=0 i<n i++ )
printf( "%10s %4d %2c %4d\n", wl[i].name, wl[i].id, wl[i].sex, 吵盯wl[i].age )
}
void select_ws( work_long *wl, work_s *ws, int n )
{
int i
for( i=0 i<n i++ )
{
memcpy( ws[i].name, wl[i].name, sizeof(ws[i].name) )
ws[i].age = wl[i].age
printf( "%10s %4d\n", ws[i].name, ws[i].age )
}
}
void delete_ws( work_s *ws, int n )
{
memset( ws, 0, sizeof(work_s)*n )
printf( "已删除\n" )
}
void menu()
{
printf( "\t-------------------------\n\t1. 输入数据\n\t2. 显示原始数据\n\t3. 制作简明数据\n\t4. 删除简明数据\n\t5. Goodbye\n\t-------------------\n" )
}
int main()
{
#define N 4
int exit_while = 0, ch = 0
work_long wl[N]
work_s ws[N]
memset( wl, 0, sizeof(work_long)*N )
memset( ws, 0, sizeof(work_s)*N )
while( ! exit_while )
{
menu()
printf( "输入选项升埋和: " )
scanf( "%d", &ch )
fflush( stdin )
switch( ch )
{
case 1:
readin( wl, N )
break
case 2:
display( wl, N )
break
case 3:
select_ws( wl, ws, N )
break
case 4:
delete_ws( ws, N )
break
case 5:
exit_while = 1
break
液枝 default:
printf( "错误选项\n" )
exit_while = 1
break
}
ch = 0
}
return 0
}
#include<iostream>#include<vector>
#include<fstream>
#include<conio.h>
using namespace std
void Display()
void Printer()
void ShowMenu()
void brevity()
int Menu_select()
void Dispvemps()
void Dispvemp()
//构造的两个类
class employee
{
//成员变量
public:
char name[10]
char id[9]
public:
//函数
//
char * GetName()
{
return name
}
//
void SetName(char n[])
{
strcpy(name,n)
}
//
char * GetID()
{
return id
}
//
void SetID(char i[])
{
strcpy(id,i)
}
virtual void Display(){
cout<<"\t"<<GetID()<<"\t"<<GetName()<<endl
}
}
class employees:public employee
{
friend class employee
protected:
char sex[4]
int age
public:
//
char * GetSex()
{
return sex
}
//
void SetSex(char s[])
{
strcpy(sex,s)
}
//
int GetAge()
{
return age
}
//
void SetAge(int a)
{
age=a
}
//////////////
void WriteFile()
void ReadFile()
/////////////
//virtual的实现
void Display()
{
cout<<GetID()<<"\t"<<GetName()<<"\t"<<GetSex()<<"\t"<<GetAge()<<endl
}
}
//容器指坦
vector<employee>vemp
vector<employees>vemps
//
void Printer(employee&s)
{
s.Display()
}
//添加新数迅举据
void AddNew()
{
char ch[5]
int age
employees emps
cout<<"注意:当编号为零时,进入主界面,编号不可为a-e:"<<endl
for (int i=0i<3i++){
cout<<"\t编号:"
cin.getline(ch,'\n')
if (ch[0]=='0') break
emps.SetID(ch)
cout<<"\t姓名:"
cin.getline(ch,'\n')
emps.SetName(ch)
cout<<"\t性别:"
cin.getline(ch,'\n')
emps.SetSex(ch)
cout<<"\t年龄:"
cin>>age
emps.SetAge(age)
vemps.push_back(emps)
getchar()
emps.WriteFile()
}
}
//
void employees::WriteFile()
{
ofstream curFile("Workers.txt")
for(int i=0i<3i++)
{
curFile<<id<<'\n'<<name<<'\n'<<sex<<'\n'<<age<<'\n'
}
curFile.close()
}
void employees::ReadFile(){
char line[81]
ifstream inFile("Workers.txt")
inFile.getline (line, 80)
if(inFile.eof()){cout<<"没有记录,请先手动打开文件输入信息"<<endl
}
while(!inFile.eof())
{
cout<<亩逗碧line<<endl
inFile.getline (line, 80)
}
inFile.close ()
}
void brevity()
{
friend class employee
employees emps
int top=vemps.size()
int size=vemp.size()
if (top==0)
{
cout<<"\t没有建立记录,请先建立记录信息。"<<endl
return
}
for(int i=sizei<topi++)
{
vemp.push_back(emps)
strcpy(vemp[i].id,vemps[i].id)
strcpy(vemp[i].name,vemps[i].name)
}
cout<<"信息简表已生成,请继续"<<endl
}
//
void main()
{
ShowMenu()
}
//显示菜单并进行处理
void ShowMenu()
{
char Menu_sel()
void Dispvemps()
void Dispvemp()
void brevity()
for( )
{
switch( Menu_sel()){
case 'a':
AddNew()
break
case 'b':
brevity()
break
case 'c':
Dispvemps()
break
case 'd':
Dispvemp()
break
case 'e':
cout<<"\t欢迎下次继续使用,再见! \n"
return
default :
return
}
}
}
char Menu_sel()
{
char s[4]
char ch
cout<<"\t\t\t*************************\n"
cout<<"\t\t\ta.增加职工信息 \n"
cout<<"\t\t\t \n"
cout<<"\t\t\tb.生成信息简表 \n"
cout<<"\t\t\t \n"
cout<<"\t\t\tc.显示原始记录 \n"
cout<<"\t\t\t \n"
cout<<"\t\t\td.显示简表记录 \n"
cout<<"\t\t\t \n"
cout<<"\t\t\te.结束程序运行 \n"
cout<<"\t\t\t \n"
cout<<"\t\t\t*************************\n"
cout<<"\t选择a-e:"
for( ){
gets(s)
ch=*s
if(ch<'a'|| ch>'e')
cout<<"\n\t输入错误,重选a-e:"
else
break
}
return ch
}
void Dispvemps()
{
void Printer(employee&)
if(vemps.size()==0){
cout<<"\t没有输入信息,请先输入信息。"<<endl
return
}
else {
cout<<"编号\t姓名\t性别\t年龄"<<endl
for(int i=0i<vemps.size()i++)
Printer(vemps[i])
}
}
void Dispvemp()
{
if (vemp.size()==0){
cout<<"\t没有生成新的简表, 请先生成新的简表"<<endl
return
}
else {
cout<<"\t编号"<<"\t姓名"<<endl
for(int i=0i<vemp.size()i++)
Printer(vemp[i])
}
}
#include<iostream>#include<string>
using namespace std
class employee
{
public:
string name
string sex
string techang
string xuexing
string xingzuo
string attend
string getin
string birthday
int static number
int grade
int money
long call
employee(){number++grade=1}
void virtual input(){}
void show()
{
cout<<"姓名:"<<name<<" "
cout<<"性别:"<<sex<<" "
cout<<"年月:"<<birthday<<" "
cout<<"特长:"<<techang<<" "
cout<<"血型:"<<xuexing<<" "
cout<<"星座:"<<xingzuo<<" "
cout<<"参加公司时间:"<<attend<<" "
cout<<"进入公司时间:"<<getin<<" "
cout<<"月薪:"<<money<<" "
cout<<"编号:"<<number<<" "
cout<<"级别:"<<grade<<" "<<endl
}
}
int employee::number=0
class technician:public employee
{
public:
technician(){money=3000}
void input()
{
cout<<"姓名:"cin>>namecout<<endl
cout<<"性别:"cin>>sexcout<<endl
cout<<"年月:"cin>>birthdaycout<<endl
cout<<"特滚雹旁长:"cin>>techangcout<大橡<endl
cout<<"血型:"cin>>xuexingcout<<endl
cout<<"星座:"cin>>xingzuocout<<endl
cout<<"参加公司时间:"cin>>attendcout<<endl
cout<<"进入公司时间:"cin>>getincout<<endl
}
}
class manger:public employee
{
public:
int x
void input()
{
int x
cout<<"姓名:"cin>>namecout<<endl
cout<<"性别:"肆颤cin>>sexcout<<endl
cout<<"经理类型(1 总经理,2 销售经理,3 技术经理):"cin>>x
switch(x)
{
int y,z
case 1:
money=10000break
case 2:
cout<<"销售额:"cin>>ymoney=4000+y/20break
case 3:
cout<<"奖金:"cin>>zmoney=6000+zbreak
}
cout<<"年月:"cin>>birthdaycout<<endl
cout<<"特长:"cin>>techangcout<<endl
cout<<"血型:"cin>>xuexingcout<<endl
cout<<"星座:"cin>>xingzuocout<<endl
cout<<"参加公司时间:"cin>>attendcout<<endl
cout<<"进入公司时间:"cin>>getincout<<endl
}
}
class saleman:public employee
{
public:
int m
void input()
{
cout<<"姓名:"cin>>namecout<<endl
cout<<"性别:"cin>>sexcout<<endl
cout<<"年月:"cin>>birthdaycout<<endl
cout<<"销售额:"cin>>mmoney=mcout<<endl
cout<<"特长:"cin>>techangcout<<endl
cout<<"血型:"cin>>xuexingcout<<endl
cout<<"星座:"cin>>xingzuocout<<endl
cout<<"参加公司时间:"cin>>attendcout<<endl
cout<<"进入公司时间:"cin>>getincout<<endl
}
}
void main()
{
int n
manger a
technician b
saleman c
cout<<"***通信09-3***孙太川***20092258****"<<endl
cout<<"***********************************"<<endl
cout<<"*主菜单 *"<<endl
cout<<"* 1 输入职工信息*"<<endl
cout<<"* 2 查询职工信息*"<<endl
cout<<"* 3 退出系统*"<<endl
cout<<"***********************************"<<endl
while(1)
{
cout<<"选择你所需要的菜单:"
cin>>n
if(n==3)break
switch(n)
{
int w
case 1:
cout<<"选择你所需要输入的职工类型:"<<endl
cout<<"(1 经理,2 技术人员,3 销售人员):"
cin>>w
switch(w)
{
case 1:
a.input()break
case 2:
b.input()break
case 3:
c.input()break
}
case 2:
int u
cout<<"编号:"cin>>u
switch(u)
{
case 1:
a.show()break
case 2:
b.show()break
case 3:
c.show()break
}
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)