當前位置:編程學習大全網 - 編程語言 - 用C或C++寫個程序 急求

用C或C++寫個程序 急求

我提供兩個源代碼給妳,妳稍微改壹改就可以,都是職工信息系統!

第壹個采用C++的類封裝的思想,第二個是C語言的!

#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>>name;cout<<endl;

cout<<"性別:";cin>>sex;cout<<endl;

cout<<"年月:";cin>>birthday;cout<<endl;

cout<<"特長:";cin>>techang;cout<<endl;

cout<<"血型:";cin>>xuexing;cout<<endl;

cout<<"星座:";cin>>xingzuo;cout<<endl;

cout<<"參加公司時間:";cin>>attend;cout<<endl;

cout<<"進入公司時間:";cin>>getin;cout<<endl;

};

};

class manger:public employee

{

public:

int x;

void input()

{

int x;

cout<<"姓名:";cin>>name;cout<<endl;

cout<<"性別:";cin>>sex;cout<<endl;

cout<<"經理類型(1 總經理,2 銷售經理,3 技術經理):";cin>>x;

switch(x)

{

int y,z;

case 1:

money=10000;break;

case 2:

cout<<"銷售額:";cin>>y;money=4000+y/20;break;

case 3:

cout<<"獎金:";cin>>z;money=6000+z;break;

};

cout<<"年月:";cin>>birthday;cout<<endl;

cout<<"特長:";cin>>techang;cout<<endl;

cout<<"血型:";cin>>xuexing;cout<<endl;

cout<<"星座:";cin>>xingzuo;cout<<endl;

cout<<"參加公司時間:";cin>>attend;cout<<endl;

cout<<"進入公司時間:";cin>>getin;cout<<endl;

};

};

class saleman:public employee

{

public:

int m;

void input()

{

cout<<"姓名:";cin>>name;cout<<endl;

cout<<"性別:";cin>>sex;cout<<endl;

cout<<"年月:";cin>>birthday;cout<<endl;

cout<<"銷售額:";cin>>m;money=m;cout<<endl;

cout<<"特長:";cin>>techang;cout<<endl;

cout<<"血型:";cin>>xuexing;cout<<endl;

cout<<"星座:";cin>>xingzuo;cout<<endl;

cout<<"參加公司時間:";cin>>attend;cout<<endl;

cout<<"進入公司時間:";cin>>getin;cout<<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;

};

};

};

}

=============================================================

程序二:

#include<stdio.h>

#include<stdlib.h>

typedef struct employee

{

int id;

char name[20];

char department[20];

int money;

char position[20];

struct employee *next;

}Employee,*ept;

typedef struct

{

ept head;//頭指針

ept tail;//尾指針

ept current;

ept p,q;

int tot;

}Linkemployee;

int isfound(Linkemployee &l,int id)//判斷是否有重復的職工號

{

int count=0,flag;

l.p=l.head;

while(count++<l.tot)

{

flag=0;

if(l.p->id==id)

flag=1;

else

l.p=l.p->next;

}

if(flag==1)

return 1;

else

return 0;

}

void CreatLink(Linkemployee &l)//構造空鏈表

{

l.head=l.tail=(Employee*)malloc(sizeof(Employee));

l.head=l.tail=NULL;

l.tot=0;

}

void AddInformation(Linkemployee &l)

{

l.current=(Employee*)malloc(sizeof(Employee));

printf("請輸入職工姓名:");

scanf("%s",l.current->name);

printf("請輸入職工號:");

scanf("%d",&l.current->id );

printf("請輸入職工部門:");

scanf("%s",l.current->department);

printf("請輸入職工職位:");

scanf("%s",l.current->position );

printf("請輸入職工工資:");

scanf("%d",&l.current->money );

if(l.head==NULL)

{

l.head=l.tail=l.current;

l.head->next=l.tail;

l.tail->next=NULL;

l.tot++;

printf("職工添加成功!!!\n");

}

else

{

if(!isfound(l,l.current->id))

{

l.tail->next=l.current;

l.current->next=NULL;

l.tail=l.current;

l.tot++;

printf("職工添加成功!!!\n");

}

else

printf("職工號已經存在\n");

}

}

void SearchInformation(Linkemployee &l)

{

if(l.tot>0)

{

int findnumber,count=0;

l.p=l.head;

printf("輸入要要查找的職工號:");

scanf("%d",&findnumber);

while(count++<l.tot)

{

if(findnumber==l.p->id)

{

printf("職工信息找到!\n");

printf("姓名 職工號 職工部門 職工工資 職工職位\n");

printf("%s%6d%8s%8d%8s\n",l.p->name,l.p->id,l.p->department,l.p->money,l.p->position);

}

else

printf("無輸入職工號的信息\n");

l.p=l.p->next;

}

}

else

printf("沒有任何信息\n");

}

void DisplayInformation(Linkemployee &l)

{

if(l.tot>0)

{

int count=0;

l.p=l.head;

printf("姓名 職工號 職工部門 職工工資 職工職位\n");

while(count++<l.tot)

{

printf("%s%8d%8s%8d%8s\n",l.p->name,l.p->id,l.p->department,l.p->money,l.p->position);

l.p=l.p->next;

}

}

else

printf("沒有任何信息\n");

}

void DeleteInformation(Linkemployee &l)

{

int findid, count=0;

int flag;

int selection;

l.p=l.head;

l.q=l.p;//記錄刪除節點的前壹個節點

if(l.tot>0)

{

printf("輸入要刪除的職工號:");

scanf("%d",&findid);

while(count++<l.tot)

{

flag=0;

if(findid==l.p->id)

{

flag=1;

}

else

{

l.q=l.p;//記錄刪除節點的前壹個節點

l.p=l.p->next;

}

}

if(flag==1)

{

printf("職工信息找到!\n");

printf("姓名 職工號 職工部門 職工工資 職工職位\n");

printf("%s%6d%6s%6d%6s\n",l.p->name,l.p->id,l.p->department,l.p->money,l.p->position);

printf("確認刪除嗎?1刪除,2退出\n");

scanf("%d",&selection);

if(selection==1)

{

if(l.p==l.tail )

{

l.q->next=NULL;

l.tail=l.q;

free(l.p);

}

else if(l.p==l.head)

{

l.q=l.p;

l.p=l.p->next;

l.head=l.p;

free(l.q);

}

else

{

l.q->next=l.p->next;

free(l.p);

}

l.tot--;

}

else

printf("自動退出\n");

}

else

printf("無輸入職工號信息\n");

}

else

printf("沒有任何信息\n");

}

void main()

{

int selection;

Linkemployee l;

CreatLink(l);

printf("----------------------------------------------\n歡迎進入公司職工信息管理程序");

printf("\n----------------------------------------------\n");

printf("請選擇您的操作:\n1. 增加職工信息\n2. 查找職工信息\n3. 顯示所有職工信息\n4. 刪除職工信息\n5. 退出\n");

while(scanf("%d",&selection)&&selection!=5)

{

switch(selection)

{

case 1:AddInformation(l);break;

case 2:SearchInformation(l);break;

case 3:DisplayInformation(l);break;

case 4:DeleteInformation(l);break;

}

printf("----------------------------------------------\n歡迎進入公司職工信息管理程序");

printf("\n----------------------------------------------\n");

printf("請選擇您的操作:\n1. 增加職工信息\n2. 查找職工信息\n3. 顯示所有職工信息\n4. 刪除職工信息\n5. 退出\n");

}

}

  • 上一篇:操作系統怎樣 控制 硬件 詳細?0?3
  • 下一篇:我要買PSP,請有PSP或懂PSP達人進拿分
  • copyright 2024編程學習大全網