『壹』 c語言程序設計,職工管理系統,有些小的要求,好答案加分,謝謝
菜單建議用VC++.Net,裡面logo畫面都不要自己寫,VS.Net在應用程序參數里有這些功能,界面完全不用擔心,VS功能實在太強大了,從設計到發布都有相關工具。建議去裝個Visual Studio 2010
首先整個文件讀入
名稱排序可以轉ASCII碼,人不多就用選擇排序,人多就用快速排序
每個學歷對應一個編號,只要對編號排序,然後替換成中文字就行了。
其實VC++里的ListView控制項很強大
文件可以直接寫,別忘了加分隔符
數據用單向鏈表放內存里
職工信息用結構體變數
刪除信息只要鏈表節點操作
這些在C語言書上介紹指針的章節里都都有
操作許可權用VC++.Net里文件操作功能詳見MSDN Library
完成後保存
操作時經常保存臨時文件以便意外情況時恢復
如果循環次數過多(比如保存)可以採用backgroundworker(多線程)控制項
『貳』 用c語言編寫設計,職工信息管理系統。
我給你個大概提示吧,
首先你要做的是個大體的框架
分三個許可權一是管理員許可權,人事部門許可權以及員工許可權。
1.管理員許可權實現包括員工基本信息增刪改查功能。
2.人事許可權包括員工拓展信息,比如工資,獎金等等數據的維護和更新。
3.員工許可權包括個人信息查詢以及問題反饋。
三個雙向鏈表,節點數據存入以上所有信息。
鏈表操作不多說了吧。。。
文件讀寫問題,這里考慮到如果是一般情況的話直接調用readwrite函數就行了
如果內容過多還是連接資料庫吧。
系統開始的初始化和更新也很重要。
『叄』 c語言程序設計、工資管理系統
#include <stdio.h>
#include <windows.h>
#include <time.h>
#include <string.h>
#define N 100
struct employee
{
int num;
char name[10];
char cheng;
int jiben;
int jiangjin;
int baoxian;
int zafei;
int shiji;
}em[100]; /*定義一個結構體*/
void menu();
void input();
void save(int);
void display();
void del();
void search();
void search_cheng();
void search_name();
void modify(); /*定義各函數*/
void menu() /*菜單函數*/
{
printf("\n");
printf(" 網計091 第7小組\n");
printf("\n");
printf(" ******************職工信息管理****************\n");
printf(" 1.錄入職工信息");
printf(" 2.瀏覽職工信息\n");
printf(" 3.查詢職工信息");
printf(" 4.刪除職工信息\n");
printf(" 5.修改職工信息\n");
printf(" 6.退出\n");
printf(" ********************謝謝使用******************\n");
printf("\n");
printf("\n");
}
void main()
{
int n,flag;
char a;
while(1)
{
do
{
menu(); /*調用菜單函數*/
printf("請選擇你需要操作的步驟(1--6):\n");
scanf("%d",&n);
if(n>=1&&n<=6)
{
flag=1;
break;
}
else
{
flag=0;
printf("您輸入有誤,請重新選擇!");
}
}while(flag==0);
switch(n)
{
case 1:printf(" 輸入職工信息\n");printf("\n");input();break;
case 2:printf(" 瀏覽職工信息\n");printf("\n");system("cls");display();break;
case 3:printf(" 按職工號查詢職工信息\n");printf("\n");system("cls");search();break;
case 4:printf(" 刪除職工信息\n");printf("\n");system("cls");del();break;
case 5:printf(" 修改職工信息\n");printf("\n");system("cls");modify();break;
case 6:goto la;
default :break;
}
}
la:
system("cls");
printf("\n\n\n\n\n 謝謝使用!\n");
}
void input() /*錄入函數*/
{
int i,m;
printf("請輸入需要創建信息的職工人數(1--100):\n");
scanf("%d",&m);
for (i=0;i<m;i++)
{
printf("請輸入職工號: ");
scanf("%d",&em[i].num); //這里的代碼錯,要用數組下標
printf("\n");
printf("請輸入姓名: ");
scanf("%s",em[i].name);//這里的代碼錯,要用數組下標
getchar();
printf("請輸入職稱: ");
scanf("%c",&em[i].cheng);//這里的代碼錯,要用數組下標
printf("請輸入基本工資: ");
scanf("%d",&em[i].jiben);//這里的代碼錯,要用數組下標
printf("請輸入獎金: ");
scanf("%d",&em[i].jiangjin);//這里的代碼錯,要用數組下標
printf("請輸入保險: ");
scanf("%d",&em[i].baoxian);//這里的代碼錯,要用數組下標
printf("請輸入雜費: ");
scanf("%d",&em[i].zafei);//這里的代碼錯,要用數組下標
em[i].shiji=em[i].jiben + em[i].jiangjin - em[i].baoxian - em[i].zafei;//這里的代碼錯,要用數組下標
printf("\n");
}
printf("\n創建完畢!\n");system("cls");
save(m);
}
void save(int m) /*保存文件函數*/
{
int i;
FILE*fp;
if ((fp=fopen("employee_list","wb"))==NULL) /*創建文件並判斷是否能打開*/
{
printf ("cannot open file\n");
exit(0);
}
for (i=0;i<m;i++) /*將內存中職工的信息輸出到磁碟文件中去*/
if (fwrite(&em,sizeof(struct employee),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
int load() /*導入函數*/
{
FILE*fp;
int i=0;
if((fp=fopen("employee_list","rb"))==NULL)
{
printf ("cannot open file\n");
exit(0);
}
else
{
do
{
fread(&em,sizeof(struct employee),1,fp);
i++;
}
while(feof(fp)==0);
}
fclose(fp);
return(i-1);
}
void display() /*瀏覽函數*/
{
int i;
int m=load();
printf("\n職工號\t姓名\t職稱\t基本工資\t獎金\t保險\t雜費\t實際工資 \n");
for(i=0;i<m;i++) /*m為輸入部分的職工人數*/
printf("\n %d\t %s\t %c\t %d\t %d\t %d\t %d\t %d\n",em[i].num,em[i].name,em[i].cheng,em[i].jiben,em[i].jiangjin,em[i].baoxian,em[i].zafei,em[i].shiji); //這里的代碼錯,要用數組下標
printf("按任意鍵繼續\n");
getchar();getchar();system("cls");
}
void del() /*刪除函數*/
{
int m=load();
int i,j,n,t,flag;
char name1[10];
printf("\n 原來的職工信息:\n");
display(); /* 調用瀏覽函數*/
printf("\n");
printf("請輸入要刪除的職工的姓名:\n");
scanf("%s",name1);
for(flag=1,i=0;flag&&i<m;i++)
{
if(strcmp(em[i].name,name1)==0)
{
printf("\n已找到此人,原始記錄為:\n");
printf("\n職工號\t姓名\t職稱\t基本工資\t獎金\t保險\t雜費\t實際工資 \n");
printf("\n%d\t%s\t%c\t%d\t%d\t%d\t%d\t%d\n",em[i].num,em[i].name,em[i].cheng,em[i].jiben,em[i].jiangjin,em[i].baoxian,em[i].zafei,em[i].shiji);
printf("\n確實要刪除此人信息請按1,不刪除請按0\n");
scanf("%d",&n);
if(n==1) /*如果刪除,則其他的信息都往上移一行*/
{
for(j=i;j<m-1;j++)
{
em[j]=em[j+1];
}
flag=0;
}
}
}
if(!flag)
m=m-1;
else
printf("\n對不起,查無此人!\n");
printf("\n 瀏覽刪除後的所有職工信息:\n");
save(m); /*調用保存函數*/
display(); /*調用瀏覽函數*/
printf("\n繼續刪除請按1,不再刪除請按0\n");
scanf("%d",&t);
switch(t)
{
case 1:del();break;
case 0:break;
default :break;
}system("cls");
}
void search()/*查詢函數*/
{
int t,flag;
do
{
printf("\n按姓名查詢請按1 ; 按職稱查詢請按2 ; 進入主函數按3\n");
scanf("%d",&t);
if(t>=1&&t<=3)
{
flag=1;
break;
}
else
{
flag=0;
printf("您輸入有誤,請重新選擇!");
}
}while(flag==0);system("cls");
while(flag==1)
{
switch(t)
{
case 1:printf("按姓名查詢\n");search_name();break;
case 2:printf("按職稱查詢\n");search_cheng();break;
case 3:main();break;
default:break;
}
system("cls");
}
}
void search_name()
{
char name1[10];
int i,t;
int m=load();
printf("請輸入要查找的姓名:\n");
scanf("%s",name1);
for(i=0;i<m;i++)
if(strcmp(name1,em[i].name)==0)
{
printf("\n已找到此人,其記錄為:\n");
printf("\n職工號\t姓名\t職稱\t基本工資\t獎金\t保險\t雜費\t實際工資 \n");
printf("\n%d\t%s\t%c\t%d\t%d\t%d\t%d\t%d\n",em[i].num,em[i].name,em[i].cheng,em[i].jiben,em[i].jiangjin,em[i].baoxian,em[i].zafei,em[i].shiji);
break;
}
if(i==m)
printf("\n對不起,查無此人\n");
printf("\n");
printf("返回查詢函數請按1,繼續查詢職工號請按2\n");
scanf("%d",&t);
switch(t)
{
case 1:search();break;
case 2: break;
default:break;
}
}
void search_cheng()
{
char cheng;
int i,t=0;
int m=load();
system("cls");
printf("請輸入要查找的職稱:\n");
scanf("%c",&cheng); //這里要用地址
for(i=0;i<m;i++)
if(em[i].cheng==cheng)
{
printf("\n已找到,其記錄為:\n");
printf("\n職工號\t姓名\t職稱\t基本工資\t獎金\t保險\t雜費\t實際工資 \n");
printf("\n%d\t%s\t%c\t%d\t%d\t%d\t%d\t%d\n",em[i].num,em[i].name,em[i].cheng,em[i].jiben,em[i].jiangjin,em[i].baoxian,em[i].zafei,em[i].shiji);
}
if(i==m)
printf("\n對不起,查無此人\n");
printf("\n");
printf("返回查詢函數請按1,繼續查詢學歷請按2\n");
scanf("%d",&t);
switch(t)
{
case 1:system("cls");search();break;
case 2:break;
default :break;
}
}
void modify() /*修改函數*/
{
int num;
char name[10];
char cheng;
int jiben;
int jiangjin;
int baoxian;
int zafei;
int shiji;
int b,c,i,n,t,flag;
int m=load(); /*導入文件內的信息*/
printf("\n 原來的職工信息:\n");
display(); /* 調用瀏覽函數*/
printf("\n");
printf("請輸入要修改的職工的姓名:\n");
scanf("%s",name);
for(flag=1,i=0;flag&&i<m;i++)
{
if(strcmp(em[i].name,name)==0)
{
printf("\n已找到此人,原始記錄為:\n");
printf("\n職工號\t姓名\t職稱\t基本\t獎金\t保險\t雜費\t實際工資 \n");
printf("\n%d\t%s\t%c\t%d\t%d\t%d\t%d\t%d\n",em[i].num,em[i].name,em[i].cheng,em[i].jiben,em[i].jiangjin,em[i].baoxian,em[i].zafei,em[i].shiji);
printf("\n確實要修改此人信息請按1 ; 不修改請按0\n");
scanf("%d",&n);
if(n==1)
{
printf("\n需要進行修改的選項\n 1.職工號 2.姓名 3.職稱 4.基本工資 5.獎金 6.保險 7.雜費 8.實際工資\n");
printf("請輸入你想修改的那一項序號:\n");
scanf("%d",&c);
if(c>8||c<1)
printf("\n選擇錯誤,請重新選擇!\n");
}
flag=0;
}
}
if(flag==1)
printf("\n對不起,查無此人!\n");
do
{
switch(c) /*因為當找到第i個職工時,for語句後i自加了1,所以下面的應該把改後的
信息賦值給第i-1個人*/
{
case 1:printf("職工號改為: ");
scanf("%d",&num);
em[i-1].num=num;
break;
case 2:printf("姓名改為: ");
scanf("%s",name);
strcpy(em[i-1].name,name);
break;
case 3:printf("職稱改為: ");
getchar();
scanf("%c",&cheng);
em[i-1].cheng=cheng;
break;
case 4:printf("基本工資改為: ");
scanf("%d",&jiben);
em[i-1].jiben=jiben;
break;
case 5:printf("獎金改為: ");
scanf("%d",&jiangjin); //這里要用地址
em[i-1].jiangjin=jiangjin;
break;
case 6:printf("保險改為: ");
scanf("%d",&baoxian);//這里要用地址
break;
case 7:printf("雜費改為: ");
scanf("%d",&zafei);//這里要用地址
em[i-1].zafei=zafei;
break;
case 8:printf("實際工資改為: ");
scanf("%d",&shiji);
em[i-1].shiji=shiji;
break;
}
printf("\n");
printf("\n是否確定所修改的信息?\n 是 請按1 ; 不,重新修改 請按2: \n");
scanf("%d",&b);
}
while(b==2);
printf("\n瀏覽修改後的所有職工信息:\n");
printf("\n");
save(m);
display();
printf("\n繼續修改請按1,不再修改請按0\n");
scanf("%d",&t);
switch(t)
{
case 1:modify();break;
case 0:break;
default :break;
}system("cls");
}
『肆』 C語言程序設計題:職工工資管理系統
你要的是命令行還是圖形界面?如果是命令行可以考慮下如果是圖形界面的話200分少了點,看看吧.--------------------------------------------既然不是圖形界面,代碼就簡單.不過也有近300行.可能有些地方不怎麼簡潔..你用的時候,把注釋「deletenbsp;thisnbsp;line「那行所在的代碼刪除或修改就OK了.如果看不懂請給我留言,我發一份帶詳細注釋的代碼給你.--------------------------------------------/*Microsoftnbsp;Visualnbsp;C++nbsp;.NET編譯通過bynbsp;做他@07.12.29*/#includenbsp;「stdafx.h「#includenbsp;「iostream「#includenbsp;「string「#includenbsp;「list「#includenbsp;「cassert「usingnbsp;namespacenbsp;std;/*編號、姓名、部門、應付工資、保險、稅金、實付工資。其中實付工資由公式計算得到:實付工資=應付工資nbsp;-nbsp;保險-nbsp;稅金nbsp;*/structnbsp;employee{nbsp;stringnbsp;m_num;//編號nbsp;stringnbsp;m_name;//姓名nbsp;stringnbsp;m_dep;//部門nbsp;doublenbsp;m_salary;//應付工資nbsp;doublenbsp;m_insurance;//保險nbsp;doublenbsp;m_tax;//稅金};/*(1)錄入:輸入職工數據,其中「實付工資」通過計算得到;nbsp;(2)刪除:刪除指定的職工信息(輸入姓名,若找到則刪除該信息)nbsp;(3)nbsp;修改:允許對已經錄入的數據重新進行編輯、修改;nbsp;(4)nbsp;顯示:顯示全體職工數據;nbsp;(5)查詢:nbsp;a.nbsp;輸入職工姓名,顯示該職工的全部數據;nbsp;b.nbsp;輸入某部門值,顯示該部門職工的數據、工資總額、平均工資。nbsp;(6)nbsp;退出程序。*/listamp;lt;employeeamp;gt;nbsp;emps;intnbsp;_tmain(intnbsp;argc,nbsp;_TCHAR*nbsp;argv[]){nbsp;voidnbsp;print(constnbsp;employeenbsp;amp;e);nbsp;voidnbsp;input();nbsp;voidnbsp;del();nbsp;voidnbsp;mod();nbsp;voidnbsp;show_all();nbsp;voidnbsp;show_name();nbsp;voidnbsp;show_dep();nbsp;coutamp;lt;amp;lt;「簡易職工薪水管理程序nbsp;bynbsp;做他<br/>「;//nbsp;deletenbsp;thisnbsp;linenbsp;coutamp;lt;amp;lt;「版權沒有nbsp;請隨意復制或修改任何代碼<br/>「;//deletenbsp;thisnbsp;linenbsp;coutamp;lt;amp;lt;「請選擇操作:1.錄入nbsp;2.刪除nbsp;3.修改nbsp;4.查詢nbsp;5.顯示所有員工nbsp;6.退出nbsp;:「;nbsp;intnbsp;choose=0;nbsp;cinamp;gt;amp;gt;choose;nbsp;assert(!cin.fail());nbsp;whilenbsp;(choose!=6)nbsp;{nbsp;nbsp;ifnbsp;(choose==1)nbsp;input();nbsp;nbsp;ifnbsp;(choose==2)nbsp;del();nbsp;nbsp;ifnbsp;(choose==3)nbsp;mod();nbsp;nbsp;ifnbsp;(choose==4)nbsp;nbsp;nbsp;{nbsp;nbsp;nbsp;intnbsp;choice=0;nbsp;nbsp;nbsp;coutamp;lt;amp;lt;「請選擇操作nbsp;1.按姓名查詢nbsp;2.按部門查詢nbsp;3.退出:「;nbsp;nbsp;nbsp;cinamp;gt;amp;gt;choice;nbsp;nbsp;nbsp;ifnbsp;(choice==1)nbsp;show_name();nbsp;nbsp;nbsp;ifnbsp;(choice==2)nbsp;show_dep();nbsp;nbsp;nbsp;ifnbsp;(choice==3)nbsp;nbsp;nbsp;nbsp;{nbsp;nbsp;nbsp;nbsp;coutamp;lt;amp;lt;「請選擇操作:1.錄入nbsp;2.刪除nbsp;3.修改nbsp;4.查詢nbsp;5.顯示所有員工nbsp;6.退出nbsp;:「;nbsp;nbsp;nbsp;nbsp;cinamp;gt;amp;gt;choose;nbsp;nbsp;nbsp;nbsp;assert(!cin.fail());nbsp;nbsp;nbsp;nbsp;continue;nbsp;nbsp;nbsp;}nbsp;nbsp;}nbsp;nbsp;ifnbsp;(choose==5)nbsp;show_all();nbsp;nbsp;coutamp;lt;amp;lt;「請選擇操作:1.錄入nbsp;2.刪除nbsp;3.修改nbsp;4.查詢nbsp;5.顯示所有員工nbsp;6.退出nbsp;:「;nbsp;nbsp;cinamp;gt;amp;gt;choose;nbsp;nbsp;assert(!cin.fail());nbsp;}nbsp;re
『伍』 急求:職工信息管理系統設置(c語言的程序代碼)
#include<iostream>
#include<fstream>
using namespace std;
struct wkrs
{
char num[10];
char name[10];
char sex[3];
int age;
}wk[10];
struct wkr
{
char name[10];
int age;
}wkshort[10];
void Display();
void Readin();
void Disp();
void SelectWk();
void Delwk();
int MenuSelect();
int num=0,number=10;
void main()
{
for(;;)
{
switch(MenuSelect())
{
case 1:Readin();break;
case 2:Display();break;
case 3:SelectWk();break;
case 4:Delwk();break;
case 5:Disp();break;
case 6:cout<<"退出運行,再見!"<<endl;exit(0);
}
}
}
int MenuSelect()
{
char s[2];int cn;
cout<<"1.輸入數據"<<endl;
cout<<"2.顯示原始數據"<<endl;
cout<<"3.製作簡明數據"<<endl;
cout<<"4.刪除簡明數據"<<endl;
cout<<"5.顯示簡明文件"<<endl;
cout<<"退出運行"<<endl;
cout<<endl<<"左邊數字對應功能選擇,請選1-6:";
for(;;)
{
gets(s);
cn=atoi(s);
if(cn<1||cn>6)
cout<<endl<<"輸入錯誤,重選1-6:";
else
break;
}
return(cn);
}
void Display()
{
int i;
ifstream disp("workers.txt");
//disp>>number;
if(!disp)
{
cout<<"文件打不開"<<endl;
return;
}
cout<<endl<<"序號"<<"\t姓名"<<"\t性別"<<"\t年齡"<<endl;
for(i=0;i<number;i++)
{
disp>>wk[i].num>>wk[i].name>>wk[i].sex>>wk[i].age;
cout<<endl<<wk[i].num<<"\t"<<wk[i].name<<"\t"<<wk[i].sex<<"\t"<<wk[i].age;
}
disp.close();
cout<<endl<<"一共有"<<number<<"個職工的信息"<<endl;
}
void Disp()
{
ifstream disp("wk_saw.txt",ios::binary);
if(!disp)
{
cout<<"文件打不開"<<endl;
return;
}
cout<<endl<<"職工簡明文件內容:"<<endl;
cout<<endl<<"姓名"<<"\t年齡:"<<endl;
disp>>num;
for(int i=0;i<num;i++)
{
disp>>wkshort[i].name>>wkshort[i].age;
cout<<endl<<wkshort[i].name<<"\t"<<wkshort[i].age;
}
disp.close();
cout<<endl<<"一共有"<<num<<"個職工的信息"<<endl;
}
void Readin()
{
char ch[10];int i=0;
cout<<"准備輸入職工信息"<<endl;
for(i=0;i<number;i++)
{
cout<<"序號:";
cin>>wk[i].num;
if(strcmp("0",wk[i].num)==0)
{
number=i;break;
}
cout<<"姓名:";
getchar();
gets(ch);
strcpy(wk[i].name,ch);
cout<<"性別:";
cin>>wk[i].sex;
cout<<"年齡:";
cin>>wk[i].age;
}
if(number==0)
{
cout<<"沒有輸入數據,不改寫文件!"<<endl;
return;
}
cout<<"輸入結束!"<<endl;
ofstream wr("workers.txt");
for(i=0;i<number;i++)
{
wr<<wk[i].num<<" "<<wk[i].name<<" "<<wk[i].sex<<" "<<wk[i].age<<endl;
}
wr.close();
cout<<endl<<"一共寫入"<<number<<"個職工的信息"<<endl;
}
void SelectWk()
{
int i;
ifstream disp("workers.txt");
if(!disp)
{
cout<<"文件打不開"<<endl;
return;
}
//disp>>number;
for(i=0;i<number;i++)
{
cout<<endl<<wk[i].num<<"\t"<<wk[i].name<<"\t"<<wk[i].sex<<"\t"<<wk[i].age;
strcpy(wkshort[i].name,wk[i].name);
wkshort[i].age=wk[i].age;
}
cout<<endl;
disp.close();
ofstream wr("wk_saw.txt");
wr<<number<<endl;
for(i=0;i<number;i++)
{
wr<<wkshort[i].name<<" "<<wkshort[i].age<<endl;
}
wr.close();
Disp();
cout<<endl;
}
void Delwk()
{
int i=0,j,flag=0;char na[10];
Disp();
if(num==0)
{
cout<<endl<<"文件內容為空,退出刪除操作."<<endl;
return;
}
cout<<endl<<"輸入待刪除的職工的姓名(輸入0退出刪除):";
while(strcmp(na,"0")!=0)
{
cout<<endl<<"姓名:";
gets(na);
if(strcmp(na,"0")==0)
{
cout<<endl<<"退出刪除操作."<<endl;
return;
}
for(flag=1,i=0;i<num;i++)
{
if(strcmp(na,wkshort[i].name)==0)
{
for(j=i;j<num;j++)
{
strcpy(wkshort[j].name,wkshort[j+1].name);
wkshort[j].age=wkshort[j+1].age;
}
flag=0;
ofstream wr("wk_saw.txt");
num--;
wr<<num<<endl;
for(i=0;i<num;i++)
{
wr<<wkshort[i].name<<" "<<wkshort[i].age<<endl;
}
wr.close();
}
}
if(!flag)
if(num==0)
{
cout<<"現在已經刪空文件內容,退出刪除操作."<<endl;
return;
}
else
{
cout<<endl<<"刪除後的文件內容:"<<endl;
Disp();
}
else
cout<<endl<<"沒有發現這個職工,重新輸入:"<<endl;
}
}
『陸』 用C語言課程設計—職工工資管理系統(分別用結構體數組和鏈表編寫程序)
#include<stdio.h>
#define NUM 100
void input()
;void search()
;void search_num();
void dele()
;void dele_name();
void dele_num()
;void modi()
;void modi_num();
void output()
;void stat()
;void fun()
;void run();
struct emploee /*職工數據結構*/
{
char no[5];
char name[8];
char sex[3];
int age;
int salar;
}emp[NUM],newemp;
main()
{int x;
printf(" 1. 輸入職工記錄\n");
printf(" 2. 查詢職工記錄\n");
printf(" 3. 修改職工記錄\n");
printf(" 4. 刪除職工記錄\n");
printf(" 5. 列印職工記錄\n");
printf(" 6. 調查工資情況\n");
printf(" 7. 追加職工記錄\n");
printf(" 8. 結束使用\n");
printf(" 0. 退出系統\n");
printf("\n");
printf("*** 歡迎使用職工工資管理系統 ***\n");
printf("請選擇(0-8):\n");
scanf("%d",&x);
switch(x)
{
case 1: input();break;
case 2: search();break;
case 3: modi();break;
case 4: dele();break;
case 5: output();break;
case 6: stat();break;
case 7: run();break;
case 8: fun();break;
default:printf("\n Wrong!");
}
if(x==0)break;
}
}
void input()
{
FILE *fp;
int n,i;
if ((fp=fopen("emp","wb"))==NULL)
{
printf("不能建立emp文件\n");
exit(1);
}
printf("輸入職工人數:");
scanf("%d",&n);
printf("輸入格式:職工號 姓名 性別 年齡 工資<Enter>\n");
for(i=0;i<n;i++) /* 循環獲取n個職工記錄 */
{
printf("第%d個職工:",i+1);
scanf("%s%s%s%d%d",emp[i].no,emp[i].name,emp[i].sex,
&emp[i].age,&emp[i].salar);
}
for(i=0;i<n;i++) /*將n個職工記錄寫入文件*/
fwrite(&emp[i],sizeof(struct emploee),1,fp);
fclose(fp);
}
/*************************統計模塊**********************/
void stat( )
{
FILE *fp;
int n,num;
if((fp=fopen("emp","rb"))==NULL)
{
printf("不能打開emp文件\n");
exit(1);
}
printf("工資數:");
scanf("%d",&num);
printf("記錄號 職工號 姓名 性別 年齡 工資\n");
for(n=0;fread(&emp,sizeof(struct emploee),1,fp);n++)
if(emp[n].salar>=num)
printf("%6d%6s%9s%4s%5d%6d\n",n+1,emp[n].no,emp[n].name,emp[n].sex,
emp[n].age,emp[n].salar);
fclose(fp);
}
/********************刪除模塊*******************/
void dele()
{
int x;
while(1)
{
printf("\n\n\t\t刪除子菜單\n");
printf("\t\t*********\n");
printf("\t\t 1.按職工號刪除記錄\n");
printf("\t\t 0.返回主菜單\n");
printf("\t\t*********\n");
printf("\t 請選擇(0-1):");
scanf("%d",&x);
switch(x)
{case 1:dele_num();break;
default:printf("\nWrong!");
}
if(x==0)break;
}
}
void dele_num()
{
FILE *fp;
int i,j,n;
char num[5];
if((fp=fopen("emp","rb"))==NULL)
{
printf("不能打開emp文件\n");
exit(1);
}
printf("刪除前:\n");
printf("記錄號 職工號 姓名 性別 年齡 工資\n");
for(n=0;fread(&emp[n],sizeof(struct emploee),1,fp);n++)
printf("%6s%6s%9s%4s%5d%6d\n",n+1,emp[n].no,emp[n].name,emp[n].sex,
emp[n].age,emp[n].salar); /*n為emp文件中記錄數*/
printf("要刪除的職工號:");
scanf("%s",num);
for(i=0;(strcmp(emp[i].no,num)!=0&&i<n);i++)
if(i>=n)
{
printf("\t沒有%s職工號的職工\n",num);
exit(2);
}
fclose(fp);
fp=fopen("emp","w+");
if(n==1) /*一個記錄已經刪除了*/
{
fclose(fp);
exit(3);
}
for(j=0;j<i;j++)
fwrite(&emp[j],sizeof(struct emploee),1,fp);
for(j=i+1;j<n;j++)
fwrite(&emp[j],sizeof(struct emploee),1,fp);
printf("刪除後:\n");
fseek(fp,0,SEEK_SET);
printf("記錄號 職工號 姓名 性別 年齡 工資\n");
for(i=0;fread(&emp[i],sizeof(struct emploee),1,fp);i++)
printf("%6s%6s%9s%4s%5d%6d\n",i+1,emp[i].no,emp[i].name,emp[i].sex,
emp[i].age,emp[i].salar);
fclose(fp);
}
/********************修改模塊*******************/
void modi()
{
int x;
while(1)
{
printf("\n\n\t\t修改子菜單\n");
printf("\t\t*********************\n");
printf("\t\t1. 按職工號修改\n");
printf("\t\t0. 返回主菜單\n");
printf("\t\t*********************\n");
printf("\t請選擇(0-1):");
scanf("%d",&x);
switch(x)
{
case 1:modi_num();break;
default:printf("\n輸錯誤!");
}
if(x==0)break;
}
}
void modi_num()
{
FILE *fp;
int i,j;
char num[5];
if((fp=fopen("emp","rb+"))==NULL)
{
printf("不能 打開emp文件\n");
exit(1);
}
printf("要修改的職工號:");
scanf("%s",num);
for(i=0;fread(&emp[i],sizeof(struct emploee),1,fp);i++)
if(!strcmp(emp[i].no,num))break;
if(feof(fp))
{
printf("\t沒有%s職工號的職工\n",num);
exit(2);
}
printf("記錄號 職工號 姓名 性別 年齡 工資\n");
printf("%6d%6s%9s%4s%5d%6d\n",i+1,emp[i].no,emp[i].name,emp[i].sex,
emp[i].age,emp[i].salar);
printf("輸入格式:職工號 姓名 性別 年齡 工資<Enter>\n");
printf("第%d個記錄:",i+1);
scanf("%s%s%s%d%d",newemp.no,newemp.name,newemp.sex,&newemp.age,
&newemp.salar);/*獲取新的職工記錄*/
fseek(fp,-(long)sizeof(struct emploee),SEEK_CUR);
/*文件指針指向該修改的記錄開頭*/
fwrite(&newemp,sizeof(struct emploee),1,fp);/*用newemp覆蓋當前記錄*/
printf(" 修改後:\n");
fseek(fp,0,SEEK_SET);/*顯示修改後的文件數據*/
printf("記錄號 職工號 姓名 性別 年齡 工資\n");
for(i=0;fread(&emp[i],sizeof(struct emploee),1,fp)!=0;i++)
printf("%6d%6s%9s%4s%5d%6d\n",i+1,emp[i].no,emp[i].name,emp[i].sex,
emp[i].age,emp[i].salar);
fclose(fp);
}
/*************************查詢模塊***********************/
void search( )
{
int x;
while(1)
{
printf("\n\n\t\t查子菜單\n");
printf("\t\t********************\n");
printf("\t\t 1.按職工號查詢\n");
printf("\t\t 0.返回主菜單\n");
printf("\t\t********************\n");
printf("\t請選擇(0-1):");
scanf("%d",&x);
switch(x)
{
case 1:search_num();break;
default :printf("\n Wrong!");
}
if(x==0) break;
}
}
void search_num()
{
FILE *fp;
int i;
char num;
if((fp=fopen("emp","rb"))==NULL)
{
printf("不能打開emp文件\n");
exit(1);
}
printf("要查詢的職工號:");
scanf("%s",num);
for(i=0;fread(&emp[i],sizeof(struct emploee),1,fp);i++)
if(!strcmp(emp[i].no,num)) break;
if(feof(fp))
{
printf("\t查無此人\n");
exit(2);
}
printf("記錄號 職工號 姓名 性別 年齡 工資\n");
printf("%6d%6s%9s%4s%5d%6d\n",i+1,emp[i].no,emp[i].name,emp[i].sex,
emp[i].age,emp[i].salar);
fclose(fp);
}
/*******************輸出模塊********************/
void output()
{int i;
FILE *fp;
if((fp=fopen("emp","r"))==NULL)
{printf("不能打開emp文件\n");
exit(0);
}
printf("記錄號 職工號 姓名 性別 年齡 工資\n");
for(i=0;fread(&emp[i],sizeof(struct emploee),1,fp)!=0;i++)
{
printf("%6d%6s%9s%4s%5d%6d\n",i+1,emp[i].no,emp[i].name,emp[i].sex,
emp[i].age,emp[i].salar);
}
fclose(fp);
}
/******************追加模塊*******************/
void run()
{
FILE *fp;
int n,i,j;
if((fp=fopen("emp","ab+"))==NULL)
{printf("不能打開emp文件\n");
exit(0);
}
printf("要追加的職工人數:");
scanf("%d",&n);
for(i=0;i<n;i++)
{ printf("輸入格式:職工號 姓名 性別 年齡 工資<enter>\n");
printf("職工記錄:");
scanf("%s%s%s%d%d",newemp.no,newemp.name,newemp.sex,&newemp.age,
&newemp.salar);
/*獲取一個職工記錄*/
fwrite(&newemp,sizeof(struct emploee),1,fp);
/*將該職工記錄寫入文件*/
}
fclose(fp);
}
/*******************顯示模塊****************/
void fun()
{printf("\t\t******************************************\n");
printf("\t\t* *\n");
printf("\t\t* *\n");
printf("\t\t* 謝 謝 使 用 ! *\n");
printf("\t\t* *\n");
printf("\t\t* *\n");
printf("\t\t******************************************\n");
}
『柒』 用C語言設計職工信息管理系統
#include<iostream>
#include<string>
#include<fstream>
usingnamespacestd;
constn=50;//定義系統可錄入的員工最大數值
stringename[n];
longenum[n];
charesex[n];
inteage[n];
charemarriage[n];
intedepart[n];
inteposition[n];
intedegree[50];
inteworktime[n];
floatepay[n];
classemployee
{
public:
stringemployeename;
longemployeenum;
charemployeesex;
intemployeeage;
charemployeemarriage;
intemployeedepart;
intemployeeposition;
intemployeedegree;
intemployeeworktime;
floatemployeepay;
staticlongemployeemaxnum;
staticfloatemployeebasepay;
voidnewinfo();
voidshowinfo();
voidshowall();
voidshowdepart(intdepart);
voidshowdegree(intdegree);
voidshowage(intmin,intmax);
voidshownum(longnumber);
voidrefreshinfo();
voiddeleteinfo();
floatpay(intemployeegrade);
staticintmaxnum();
};
classdboperate
{
public:
stringemployeename;
longemployeenum;
charemployeesex;
intemployeeage;
charemployeemarriage;
intemployeedepart;
intemployeeposition;
intemployeedegree;
intemployeeworktime;
floatemployeepay;
staticlongemployeemaxnum;
staticfloatemployeebasepay;
voidwritein(intiflag);
voidreadout();
voidrefreshmaxnum(intiflag);//i=1or-1or0
};
longemployee::employeemaxnum=1000;
floatemployee::employeebasepay=1500;
intemployee::maxnum()//返回系統已經存儲的人數
{
intmn=0;
ifstreammyf;
myf.open("employeemaxnum.txt");
myf>>mn;
cout<<mn<<endl;
myf.close();
returnmn;
}
voidemployee::newinfo()//添加新成員函數
{
cout<<"新員工姓名:";
cin>>employee::employeename;
employee::employeenum=employeemaxnum+employee::maxnum()+1;
cout<<"新員工性別(f為女性,m為男性):";
cin>>employee::employeesex;
cout<<"新員工年齡:";
cin>>employee::employeeage;
cout<<"新員工婚姻狀況(y為已婚,n為未婚):";
cin>>employee::employeemarriage;
cout<<"新員工學歷,請輸入相應學歷的序號:"<<endl;
cout<<"[1:初中2:高中3:本科4:碩士5:博士]";
cin>>employee::employeedegree;
while(employee::employeedegree!=1&&employee::employeedegree!=2&&employee::employeedegree!=3&&employee::employeedegree!=4&&employee::employeedegree!=5)
{
cout<<"輸入有誤,請重新輸入:"<<endl;
cout<<"[1:初中2:高中3:本科4:碩士5:博士]";
cin>>employee::employeedegree;
}
cout<<"新員工所在部門,請輸入相應部門的序號:"<<endl;
cout<<"[1:董事會2:市場部3:公關部4:客服中心5:信息中心]";
cin>>employee::employeedepart;
while(employee::employeedepart!=1&&employee::employeedepart!=2&&employee::employeedepart!=3&&employee::employeedepart!=4&&employee::employeedepart!=5)
{
cout<<"輸入有誤,請重新輸入:"<<endl;
cout<<"[1:董事會2:市場部3:公關部4:客服中心5:信息中心]";
cin>>employee::employeedepart;
}
cout<<"新員工職位,請輸入相應職位的序號:"<<endl;
cout<<"[1:臨時職員2:正式職員3:主任4:部門經理5:董事長]";
cin>>employee::employeeposition;
while(employee::employeeposition!=1&&employee::employeeposition!=2&&employee::employeeposition!=3&&employee::employeeposition!=4&&employee::employeeposition!=5)
{
cout<<"輸入有誤,請重新輸入:"<<endl;
cout<<"[1:臨時職員2:正式職員3:主任4:部門經理5:董事長]";
cin>>employee::employeeposition;
}
cout<<"新員工的工作時(不需要輸入單位):";
cin>>employee::employeeworktime;
employee::employeepay=employee::pay(employee::employeeposition);
dboperatedbo;
dbo.readout();
intmaxnum=employee::maxnum();
enum[maxnum]=employee::employeenum;
ename[maxnum]=employee::employeename;
esex[maxnum]=employee::employeesex;
eage[maxnum]=employee::employeeage;
emarriage[maxnum]=employee::employeemarriage;
edegree[maxnum]=employee::employeedegree;
edepart[maxnum]=employee::employeedepart;
eposition[maxnum]=employee::employeeposition;
eworktime[maxnum]=employee::employeeworktime;
epay[maxnum]=employee::employeepay;
dbo.writein(1);
cout<<"添加新成員成功!"<<endl;
return;
}
voidemployee::showinfo()//程序主體數據輸出函數
{
intchoice1,choice2,min,max;
longsearchnum;
employeee;
cout<<"請選擇查詢方式:"<<endl;
cout<<"******************************************"<<endl;
cout<<"*輸出全體職工信息---------------------1"<<endl;
cout<<"*按職工部門輸出-----------------------2"<<endl;
cout<<"*按職工學歷輸出-----------------------3"<<endl;
cout<<"*按職工年齡輸出-----------------------4"<<endl;
cout<<"*按職工編號輸出-----------------------5"<<endl;
cout<<"******************************************"<<endl;
cin>>choice1;
switch(choice1)
{
case1:showall();break;
case2:cout<<"請輸入要查詢職工的部門編號:[1:董事會2:市場部3:公關部4:客服中心5:信息中心]";
cin>>choice2;
e.showdepart(choice2);break;
case3:cout<<"請輸入要查詢職工的學歷編號:[1:初中2:高中3:本科4:碩士5:博士]";
cin>>choice2;
e.showdegree(choice2);break;
case4:cout<<"請輸入要查詢的年齡范圍:";
cout<<"最小值:";
cin>>min;
cout<<"最大值:";
cin>>max;
e.showage(min,max);break;
case5:cout<<"請輸入要查詢的員工號:";
cin>>searchnum;
e.shownum(searchnum);break;
default:cout<<"出錯啦!"<<endl;break;
}
}
voidemployee::showall()//全體員工輸出函數
{inti;<br>longnumber;<br>for(i=0;i<employee::maxnum();i++)<br>{<br>number=enum[i];<br>shownum(number);<br>}
}
voidemployee::showdepart(intdepart)//按員工所在部門輸出函數
{
inti;
switch(depart)
{
case1:cout<<"董事會的成員有:>"<<endl;break;
case2:cout<<"市場部的成員有:>"<<endl;break;
case3:cout<<"公關部的成員有:>"<<endl;break;
case4:cout<<"客服中心成員有:>"<<endl;break;
case5:cout<<"信息中心成員有:>"<<endl;break;
default:cout<<"輸入錯誤!>"<<endl;break;
}
for(i=0;i<employee::maxnum();i++)
{
if(edepart[i]==depart)
{
longnumber=enum[i];
shownum(number);
}elsecontinue;
}
}
voidemployee::showdegree(intdegree)//按員工學歷輸出函數
{
inti;
switch(degree)
{
case1:cout<<"初中學歷的員工有:"<<endl;break;
case2:cout<<"高中學歷的員工有:"<<endl;break;
case3:cout<<"本科學歷的員工有:"<<endl;break;
case4:cout<<"碩士學位的員工有:"<<endl;break;
case5:cout<<"博士學位的員工有:"<<endl;break;
}
for(i=0;i<employee::maxnum();i++)
{
if(edegree[i]==degree)
{
longnumber=enum[i];
shownum(number);
}elsecontinue;
}
}
voidemployee::showage(intmin,intmax)//按員工年齡段輸出函數
{
inti;
for(i=0;i<employee::maxnum();i++)
{
if(eage[i]>=min&&eage[i]<=max)
{
longnumber=enum[i];
shownum(number);
}
elsecontinue;
}
}
voidemployee::shownum(longnumber)//按員工編號輸出函數
{
inti;
for(i=0;i<employee::maxnum();i++)
{
if(enum[i]==number)
{
cout<<"**********************************"<<endl;
cout<<"員工編號>"<<enum[i]<<endl;
cout<<"姓名>"<<ename[i]<<endl;
cout<<"性別>";
if(esex[i]=='f')cout<<"女"<<endl;
elseif(esex[i]=='m')cout<<"男"<<endl;
cout<<"年齡>"<<eage[i]<<"歲"<<endl;
cout<<"婚姻情況>";
if(emarriage[i]=='y')cout<<"已婚"<<endl;
elseif(emarriage[i]=='n')cout<<"未婚"<<endl;
cout<<"學歷>";
switch(edegree[i])
{
case1:cout<<"初中"<<endl;break;
case2:cout<<"高中"<<endl;break;
case3:cout<<"本科"<<endl;break;
case4:cout<<"碩士"<<endl;break;
case5:cout<<"博士"<<endl;break;
}
cout<<"所在部門>";
switch(edepart[i])
{
case1:cout<<"董事會"<<endl;break;
case2:cout<<"市場部"<<endl;break;
case3:cout<<"公關部"<<endl;break;
case4:cout<<"客服中心"<<endl;break;
case5:cout<<"信息中心"<<endl;break;
}
cout<<"所任職務>";
switch(eposition[i])
{
case1:cout<<"臨時成員"<<endl;break;
case2:cout<<"正式員工"<<endl;break;
case3:cout<<"主任"<<endl;break;
case4:cout<<"部門經理"<<endl;break;
case5:cout<<"董事長"<<endl;break;
}
cout<<"工作時長>"<<eworktime[i]<<"小時"<<endl;
cout<<"額定工資>"<<epay[i]<<"元"<<endl;
cout<<"**********************************"<<endl;
}
elsecontinue;
}
}
voidemployee::refreshinfo()//修改員工信息的函數
{
intcnum=1000;
dboperatedbo;
dbo.readout();
voidemployee::shownum(longnumber);
cout<<"請輸入您要修改的員工編號:>";
cin>>cnum;
intmn;
mn=employee::maxnum();
for(inti=0;i<mn;i++)//遍歷數據文件,查找要修改的員工數據
{
if(enum[i]==cnum)
{
employee::shownum(cnum);
cout<<"請輸入該員工的新信息:"<<endl;
cout<<"新員工姓名:";//錄入員工的新的數據,員工號保持不變
cin>>employee::employeename;
ename[i]=employee::employeename;
cout<<"新員工性別:[f為女性,m為男性]:";
cin>>employee::employeesex;
esex[i]=employee::employeesex;
cout<<"新員工年齡:";
cin>>employee::employeeage;
eage[i]=employee::employeeage;
cout<<"新員工婚姻狀況(y為已婚,n為未婚):";
cin>>employee::employeemarriage;
emarriage[i]=employee::employeemarriage;
cout<<"新員工學歷,請輸入相應學歷的序號:"<<endl;
cout<<"[1:初中2:高中3:本科4:碩士5:博士]";
cin>>employee::employeedegree;
while(employee::employeedegree!=1&&employee::employeedegree!=2&&employee::employeedegree!=3&&employee::employeedegree!=4&&employee::employeedegree!=5)
{
cout<<"輸入有誤,請重新輸入:"<<endl;
cout<<"[1:初中2:高中3:本科4:碩士5:博士]";
cin>>employee::employeedegree;
}
edegree[i]=employee::employeedegree;
cout<<"新員工所在部門,請輸入相應部門的序號:"<<endl;
cout<<"[1:董事會2:市場部3:公關部4:客服中心5:信息中心]";
cin>>employee::employeedepart;
while(employee::employeedepart!=1&&employee::employeedepart!=2&&employee::employeedepart!=3&&employee::employeedepart!=4&&employee::employeedepart!=5)
{
cout<<"輸入有誤,請重新輸入:"<<endl;
cout<<"[1:董事會2:市場部3:公關部4:客服中心5:信息中心]";
cin>>employee::employeedepart;
}
edepart[i]=employee::employeedepart;
cout<<"新員工職位,請輸入相應職位的序號:"<<endl;
cout<<"[1:臨時職員2:正式職員3:主任4:部門經理5:董事長]";
cin>>employee::employeeposition;
while(employee::employeeposition!=1&&employee::employeeposition!=2&&employee::employeeposition!=3&&employee::employeeposition!=4&&employee::employeeposition!=5)
{
cout<<"輸入有誤,請重新輸
『捌』 C語言程序——職工信息管理系統
貌似這么大的系統很難有人幫你做,這兒有個學生管理系統,稍加修改就成了~
/*學生成績管理系統*/
/*系統版本號:2006build 400.0201b*/
/*內核:adobo*/
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#define N 32
int total=N; //定義全局變數,學生的總個數total
struct student
{
int xh;
char xm[6];
int yw;
int sx;
int yy;
int jsj;
int zf;
};
struct student stu[N],temp;
char get_key() //得到用戶按鍵值
{
char key;
while (1)
{
if (kbhit())
{
key=getch();
break;
}
}
return key;
}
void wait() //按鍵等待,相當於PAUSE的功能
{
char key;
while (1)
{
if (kbhit())
{
key=getche();
break;
}
}
}
int id_search(int num) //查詢該學號學生的數組編號
{
int i;
for (i=0;i<total;i++)
if (stu[i].xh==num) break;
return i;
}
void show_one(int id) //顯示某學號學生的信息
{
cout<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<"⑴學號:"<<stu[id].xh<<endl;
cout<<"⑵姓名:"<<stu[id].xm<<endl;
cout<<"⑶語文:"<<stu[id].yw<<endl;
cout<<"⑷數學:"<<stu[id].sx<<endl;
cout<<"⑸英語:"<<stu[id].yy<<endl;
cout<<"⑹計算機:"<<stu[id].jsj<<endl;
cout<<"⑺總分:"<<stu[id].zf<<endl;
cout<<"--------------------------------------------------------------"<<endl;
}
void show_all() //顯示所有學生的信息
{
int i;
cout<<"--------------------------------------------------------------"<<endl;
cout<<"學號\t"<<"姓名\t"<<"語文\t"<<"數學\t"<<"英語\t"<<"計算機\t"<<"總分"<<endl;
for (i=0;i<total;i++)
cout<<stu[i].xh<<'\t'<<stu[i].xm<<'\t'<<stu[i].yw<<'\t'<<stu[i].sx<<'\t'<<stu[i].yy<<'\t'<<stu[i].jsj<<'\t'<<stu[i].zf<<endl;
cout<<"--------------------------------------------------------------"<<endl;
}
void cj_input() //輸入學生的成績
{
int i;
cout<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<"※學生成績信息錄入菜單※"<<endl;
cout<<"◎請完整輸入學生個人信息"<<endl;
cout<<"◎學號項鍵入0可結束編輯"<<endl;
cout<<"--------------------------------------------------------------"<<endl;
for (i=0;i<N;i++)
{
cout<<"請輸入第"<<i+1<<"個學生的學號:";
cin>>stu[i].xh;
if (stu[i].xh==0) return; //用戶輸入0時,結束編輯
cout<<"請輸入第"<<i+1<<"個學生的姓名:";
cin>>stu[i].xm;
cout<<"請輸入第"<<i+1<<"個學生的語文成績:";
cin>>stu[i].yw;
cout<<"請輸入第"<<i+1<<"個學生的數學成績:";
cin>>stu[i].sx;
cout<<"請輸入第"<<i+1<<"個學生的英語成績:";
cin>>stu[i].yy;
cout<<"請輸入第"<<i+1<<"個學生的計算機成績:";
cin>>stu[i].jsj;
stu[i].zf=stu[i].yw+stu[i].sx+stu[i].yy+stu[i].jsj;
cout<<"---------------提示:學號項鍵入 0可結束編輯----------------"<<endl;
}
}
void auto_input() //自動輸入學生的成績,為測試方便而設
{
int i;
for (i=0;i<N;i++)
{
stu[i].xh=(i+1);
strcpy(stu[i].xm,"ayc");
stu[i].yw=rand()%100;
stu[i].sx=rand()%100;
stu[i].yy=rand()%100;
stu[i].jsj=rand()%100;
stu[i].zf=stu[i].yw+stu[i].sx+stu[i].yy+stu[i].jsj;
}
}
void cj_modify() //學生成績的修改
{
int num,id;
char choice;
cout<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<"※學生成績信息修改菜單※"<<endl;
cout<<"◎請確認已經錄入學生信息"<<endl;
cout<<"◎學號不存在即會返回菜單"<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<"請輸入待修改的學生的學號:";
cin>>num;
id=id_search(num);
if (id==total)
{
cout<<endl;
cout<<"-〖系統提示〗------------------------"<<endl;
cout<<" 錯誤!無該學號學生信息!"<<endl;
cout<<"-------------------------------------"<<endl;
wait();
return;
}
cout<<"選擇要修改的項目的編號,其它值返回:";
show_one(id);
choice=get_key();
if (choice=='1')
{cout<<"輸入新的學號:";
cin>>stu[id].xh;
}
else if (choice=='2')
{cout<<"輸入新的姓名:";
cin>>stu[id].xm;
}
else if (choice=='3')
{cout<<"輸入新的語文成績:";
cin>>stu[id].yw;
}
else if (choice=='4')
{cout<<"輸入新的數學成績:";
cin>>stu[id].sx;
}
else if (choice=='5')
{cout<<"輸入新的英語成績:";
cin>>stu[id].yy;
}
else if (choice=='6')
{
cout<<"輸入新的計算機成績:";
cin>>stu[id].jsj;
}
stu[id].zf=stu[id].yw+stu[id].sx+stu[id].yy+stu[id].jsj;
if (choice=='1'||choice=='2'||choice=='3'||choice=='4'||choice=='5'||choice=='6')
{
cout<<"-〖系統提示〗------------------------"<<endl;
cout<<" 已成功修改該學生信息!";
cout<<"-------------------------------------"<<endl;
show_one(id);
wait();
}
}
void cj_delete() //學生信息的刪除
{
int num,id,i;
cout<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<"※學生成績信息刪除菜單※"<<endl;
cout<<"◎請確認已經錄入學生信息"<<endl;
cout<<"◎學號不存在即會返回菜單"<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<"請輸入要刪除的學生學號:";
cin>>num;
id=id_search(num);
if (id==total)
{
cout<<endl;
cout<<"-〖系統提示〗------------------------"<<endl;
cout<<" 錯誤!無該學號學生信息!"<<endl;
cout<<"-------------------------------------"<<endl;
wait();
return;
}
show_one(id);
for (i=id;i<total;i++)
stu[i]=stu[i+1];
total=total-1;
cout<<endl;
cout<<" 學 生 成 績 顯 示 菜 單 "<<endl;
show_all();
cout<<endl;
cout<<"-〖系統提示〗------------------------"<<endl;
cout<<" 已成功刪除該學生的信息!"<<endl;
cout<<"-------------------------------------"<<endl;
wait();
}
void func_1() //錄入編輯菜單
{
char choice;
while(1)
{
system("cls");
cout<<" 學 生 成 績 管 理 系 統 "<<endl;
cout<<"=============================================================="<<endl;
cout<<" ⑴錄入成績 "<<endl;
cout<<" ⑵修改成績 "<<endl;
cout<<" ⑶刪除成績 "<<endl;
cout<<" ⑷返回上級 "<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<" 鍵入相應數字項進行功能選擇(1-4) "<<endl;
choice=get_key();
if (choice=='1') cj_input(); //這里為測試方便,自動輸入了成績,注意改回
else if (choice=='2') cj_modify();
else if (choice=='3') cj_delete();
else if (choice=='4') break;
}
}
void show_person() //個人成績查詢
{
int num,id;
cout<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<"※學生成績信息修改菜單※"<<endl;
cout<<"◎請確認已經錄入學生信息"<<endl;
cout<<"◎學號不存在即會返回菜單"<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<"請輸入要查詢的學生學號:";
cin>>num;
id=id_search(num);
if (id==total)
{
cout<<endl;
cout<<"-〖系統提示〗------------------------"<<endl;
cout<<" 錯誤!無該學號學生信息!"<<endl;
cout<<"-------------------------------------"<<endl;
wait();
return;
}
show_one(id);
wait();
}
void cj_pm() //生成名次,即按照總分輸出
{
int i,j;
for (j=0;j<total;j++)
{
for (i=0;i<total-j;i++)
{
if (stu[i].zf<stu[i+1].zf)
{
temp=stu[i];
stu[i]=stu[i+1];
stu[i+1]=temp;
}
}
}
cout<<endl;
cout<<" 學 生 成 績 顯 示 (按 總 分) "<<endl;
show_all();
wait();
}
void cj_xh() //按照學號輸出
{
int i,j;
for (j=0;j<total;j++)
{
for (i=0;i<total-j;i++)
{
if (stu[i].xh>stu[i+1].xh)
{
temp=stu[i];
stu[i]=stu[i+1];
stu[i+1]=temp;
}
}
}
cout<<endl;
cout<<" 學 生 成 績 顯 示 (按 學 號) "<<endl;
show_all();
wait();
}
void cj_bk() //生成補考名單
{
int i;
cout<<" 補 考 名 單 "<<endl;
cout<<"=============================================================="<<endl;
cout<<"學號\t"<<"姓名\t"<<"語文\t"<<"數學\t"<<"英語\t"<<"計算機\t"<<endl;
for (i=0;i<total;i++)
{
if ((stu[i].yw<60)||(stu[i].sx<60)||(stu[i].yy<60)||(stu[i].jsj<60))
{
cout<<stu[i].xh<<'\t'<<stu[i].xm<<'\t';
if(stu[i].yw<60) cout<<"補考\t";
else cout<<'\t';
if(stu[i].sx<60) cout<<"補考\t";
else cout<<'\t';
if(stu[i].yy<60) cout<<"補考\t";
else cout<<'\t';
if(stu[i].jsj<60) cout<<"補考\t"<<endl;
else cout<<endl;
}
}
cout<<"--------------------------------------------------------------"<<endl;
wait();
}
void func_2() //成績查詢統計
{
char choice;
while(1)
{
system("cls");
cout<<" 學 生 成 績 管 理 系 統 "<<endl;
cout<<"=============================================================="<<endl;
cout<<" ⑴個人成績查詢 "<<endl;
cout<<" ⑵班級排名查詢 "<<endl;
cout<<" ⑶生成補考名單 "<<endl;
cout<<" ⑷返回上級 "<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<" 鍵入相應數字項進行功能選擇(1-4) "<<endl;
choice=get_key();
if (choice=='1') show_person();
else if (choice=='2') cj_pm();
else if (choice=='3') cj_bk();
else if (choice=='4') break;
}
}
void func_3() //成績列印與輸出
{
char choice;
while(1)
{
system("cls");
cout<<" 學 生 成 績 管 理 系 統 "<<endl;
cout<<"=============================================================="<<endl;
cout<<" ⑴按學號輸出 "<<endl;
cout<<" ⑵按總分輸出 "<<endl;
cout<<" ⑶返回上級 "<<endl;
cout<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<" 鍵入相應數字項進行功能選擇(1-3) "<<endl;
choice=get_key();
if (choice=='1') cj_xh();
else if (choice=='2') cj_pm();
else if (choice=='3') break;
}
}
int main() //主函數開始
{
char choice;
while(1)
{
system("cls");
cout<<" 學 生 成 績 管 理 系 統 "<<endl;
cout<<"=============================================================="<<endl;
cout<<" ⑴成績錄入與編輯 "<<endl;
cout<<" ⑵成績查詢與統計 "<<endl;
cout<<" ⑶成績列印與輸出 "<<endl;
cout<<" ⑷退出本管理系統 "<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<" 鍵入相應數字項進行功能選擇(1-4) "<<endl;
choice=get_key();
if (choice=='1') func_1();
else if (choice=='2') func_2();
else if (choice=='3') func_3();
else if (choice=='4') break;
}
system("cls"); //版權信息
cout<<"***************[關於本系統]***************"<<endl;
}
『玖』 C語言程序設計:職工工資信息統計管理系統設計
#include "stdafx.h"
#include "iostream"
#include "string"
#include "list"
#include "cassert"
using namespace std;
/*
編號、姓名、部門、應付工資、保險、稅金、實付工資。
其中實付工資由公式計算得到:實付工資=應付工資 - 保險- 稅金
*/
struct employee{
string m_num;//編號
string m_name;//姓名
string m_dep;//部門
double m_salary;//應付工資
double m_insurance;//保險
double m_tax;//稅金
};
/*
(1)錄入:輸入職工數據,其中「實付工資」通過計算得到;
(2)刪除:刪除指定的職工信息(輸入姓名,若找到則刪除該信息)
(3) 修改:允許對已經錄入的數據重新進行編輯、修改;
(4) 顯示:顯示全體職工數據;
(5)查詢:
a. 輸入職工姓名,顯示該職工的全部數據;
b. 輸入某部門值,顯示該部門職工的數據、工資總額、平均工資。
(6) 退出程序。
*/
list<employee> emps;
int _tmain(int argc, _TCHAR* argv[])
{
void print(const employee &e);
void input();
void del();
void mod();
void show_all();
void show_name();
void show_dep();
cout<<"簡易職工薪水管理程序 by 做他\n";// delete this line
cout<<"版權沒有 請隨意復制或修改任何代碼\n";//delete this line
cout<<"請選擇操作:1.錄入 2.刪除 3.修改 4.查詢 5.顯示所有員工 6.退出 :";
int choose=0;
cin>>choose;
assert(!cin.fail());
while (choose!=6)
{
if (choose==1) input();
if (choose==2) del();
if (choose==3) mod();
if (choose==4)
{
int choice=0;
cout<<"請選擇操作 1.按姓名查詢 2.按部門查詢 3.退出:";
cin>>choice;
if (choice==1) show_name();
if (choice==2) show_dep();
if (choice==3)
{
cout<<"請選擇操作:1.錄入 2.刪除 3.修改 4.查詢 5.顯示所有員工 6.退出 :";
cin>>choose;
assert(!cin.fail());
continue;
}
}
if (choose==5) show_all();
cout<<"請選擇操作:1.錄入 2.刪除 3.修改 4.查詢 5.顯示所有員工 6.退出 :";
cin>>choose;
assert(!cin.fail());
}
return 0;
}
void print(const employee &e)
{
cout<<"編號:"<<e.m_num<<endl;
cout<<"姓名:"<<e.m_name<<endl;
cout<<"部門:"<<e.m_dep<<endl;
cout<<"保險:"<<e.m_insurance<<endl;
cout<<"稅金:"<<e.m_tax<<endl;
cout<<"應付工資:"<<e.m_salary<<endl;
cout<<"實付工資:"<<e.m_salary-e.m_insurance-e.m_tax<<endl;
}
void input()
{
string num,name,dep;
double salary,ins,tax;
cout<<"請輸入員工編號:";
cin>>num;
cout<<"請輸入員工姓名:";
cin>>name;
cout<<"請輸入員工部門:";
cin>>dep;
cout<<"請輸入員工保險:";
cin>>ins;
assert(!cin.fail());
cout<<"請輸入員工稅金:";
cin>>tax;
assert(!cin.fail());
cout<<"請輸入員工應付工資:";
cin>>salary;
assert(!cin.fail());
employee temp;
temp.m_dep=dep;
temp.m_insurance=ins;
temp.m_name=name;
temp.m_num=num;
temp.m_salary=salary;
temp.m_tax=tax;
emps.push_back(temp);
cout<<"員工錄入操作完畢.\n";
}
void del()
{
if (emps.size()==0)
{
cout<<"沒有員工記錄.\n";
return;
}
string name;
bool isfind=false;
cout<<"請輸入要刪除的員工姓名:";
cin>>name;
list<employee>::iterator iter;
for (iter=emps.begin();iter!=emps.end();iter++)
{
if (iter->m_name==name)
{
isfind=true;
emps.erase(iter);
cout<<"姓名為\""<<name<<"\"的員工記錄已刪除.\n";
return;
}
}
if (!isfind)
{
cout<<"沒有找到姓名為\""<<name<<"\"的員工.\n";
return;
}
}
void mod()
{
if (emps.size()==0)
{
cout<<"員工記錄為空.\n";
return;
}
bool isfind=false;
string name;
cout<<"請輸入要修改的員工姓名:";
cin>>name;
list<employee>::iterator iter;
for (iter=emps.begin();iter!=emps.end();iter++)
{
if (iter->m_name==name)
{
isfind=true;
cout<<"姓名為\""<<name<<"\"的員工記錄已找到.\n";
break;
}
}
if (isfind)
{
string num,name,dep;
double tax,ins,salary;
print(*iter);
cout<<endl;
cout<<"請輸入新的員工編號:";
cin>>num;
cout<<"請輸入新的員工姓名:";
cin>>name;
cout<<"請輸入新的員工部門:";
cin>>dep;
cout<<"請輸入新的員工保險:";
cin>>ins;
assert(!cin.fail());
cout<<"請輸入新的員工稅金:";
cin>>tax;
assert(!cin.fail());
cout<<"請輸入新的員工工資:";
cin>>salary;
assert(!cin.fail());
iter->m_dep=dep;
iter->m_insurance=ins;
iter->m_name=name;
iter->m_num=num;
iter->m_salary=salary;
iter->m_tax=tax;
cout<<"1 員工記錄被成功修改.\n";
}
else
{
cout<<"沒有找到姓名為\""<<name<<"\"的員工記錄.\n";
}
}
void show_all()
{
if (emps.size()==0)
{
cout<<"員工記錄為空.\n";
return;
}
cout<<"顯示全體員工數據:\n";
cout<<"--------------------\n";
list<employee>::iterator iter;
for(iter=emps.begin();iter!=emps.end();iter++)
{
cout<<endl;
print(*iter);
cout<<endl;
}
cout<<"--------------------\n";
}
void show_name()
{
if (emps.size()==0)
{
cout<<"員工記錄為空.\n";
return;
}
bool isfind=false;
string name;
cout<<"請輸入要查詢的員工姓名:";
cin>>name;
list<employee>::iterator iter;
for(iter=emps.begin();iter!=emps.end();iter++)
{
if (iter->m_name==name)
{
isfind=true;
cout<<"姓名為\""<<name<<"\"的員工記錄已找到.\n";
print(*iter);
break;
}
}
if (!isfind)
{
cout<<"沒有找到姓名為\""<<name<<"\"的員工.\n";
return;
}
}
void show_dep()
{
if (emps.size()==0)
{
cout<<"員工記錄為空.\n";
return;
}
double isfind=0.00;
double total_salary=0.00;
string dep;
cout<<"請輸入要查詢的部門名稱:";
cin>>dep;
cout<<"部門["<<dep<<"]的員工信息:\n";
cout<<"--------------------\n\n";
list<employee>::iterator iter;
for(iter=emps.begin();iter!=emps.end();iter++)
{
if (iter->m_dep==dep)
{
isfind++;
total_salary+=iter->m_salary;
print(*iter);
cout<<endl;
continue;
}
}
cout<<"--------------------\n";
if (isfind==0)
{
cout<<"沒有找到名稱為["<<dep<<"]的部門.\n";
}
else
{
cout<<"部門["<<dep<<"]工資統計:\n";
cout<<"工資總額:"<<total_salary<<endl;
cout<<"平均工資:"<<total_salary/isfind<<endl;
}
}
『拾』 用C語言編寫一個程序,內容為職工工資管理系統的設計與實現
就這樣吧,工資排序就是比較數的大小,這個會吧?既然只有3個人,就這么簡單。如果要查詢,就要先保存,寫保存函數,再寫讀取函數,我就不寫了。最後建議這種用鏈表比較好。
#include<stdio.h>
#include<stdlib.h>
void main()
{
char num[3];
char name[3][9];
char type[3][9];
float money[3];
float sum = 0;
int i;
float average;
printf("請輸入職工的信息,\n:");
for(i = 0;i<3;i++)
{
num[i] = i+1;
printf("請輸入第%d個信息name:\n",i+1);
scanf("%s",name[i]);
printf("請輸入第%d個信息type:\n",i+1);
scanf("%s",type[i]);
printf("請輸入第%d個信息money:\n",i+1);
scanf("%f",&money[i]);
}
for(i = 0;i<3;i++)
{
printf("%d %s %s %f",num[i],name[i],type[i],money[i]);
printf("\n");
}
for(i = 0;i<3;i++)
{
sum+=money[i];
}
average = sum/3;
printf("平均工資是:%f\n",average);
getch();
}