當前位置:首頁 » 編程語言 » 工資管理系統c語言

工資管理系統c語言

發布時間: 2023-05-31 02:54:42

❶ 工資管理系統c語言

代碼還沒有完善好,實在沒時間了,最近太忙。先給你吧

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int addmenu();
int menu();

typedef struct teacher{
char name[32];
char unit[32];
float salary;
float allowance;
float tax;
float total;
struct teacher *next;
}TEACHER; //節點的結構體,包含數據和指針.

TEACHER *head;//頭節點

void init() //初始化頭節點
{
head=(TEACHER *)malloc(sizeof(TEACHER));
head->next=NULL;
}

void add(TEACHER *nod) //添加節點
{

if(head->next==NULL){
head=nod;
}
else
{
nod->next=head->next;
head->next=nod;
}
}

TEACHER *search(char *s) //遍歷整個鏈表並列印數據
{
TEACHER *nod=head;
while(nod->next !=NULL)//!循環到最後一個節點,有問題。。
{
if((!strcmp(nod->name,s)) || (!strcmp(nod->unit,s))){
printf("姓名:%s\n單位:%s\n基本工資:%f\n津貼:%f\n扣稅:%f\n總工資:%f\n",nod->name,nod->unit,nod->salary,nod->allowance,nod->tax,nod->tax);
return nod;
}
nod++;
}
printf("未找到數據\n");
return NULL;
}

void modify(TEACHER *s)
{
char name[16],unit[16];
float salary,allowance,tax,total;
gets(name);
strcpy(s->name,name);

gets(unit);
strcpy(s->unit,unit);

scanf("%f",&salary);
s->salary=salary;
scanf("%f",&allowance);
s->allowance=allowance;
scanf("%f",&tax);
s->tax=tax;
scanf("%f",&total);
s->total=total;

}

void del(char *s)
{
TEACHER *nod=head;
while(nod->next !=NULL)
{
if((!strcmp(nod->next->name,s))||(!strcmp(nod->next->unit,s))){
nod->next=nod->next->next;
nod->next=NULL;
}
}
}

int addmenu()//添加教師信息子菜單
{
TEACHER *node;
char command;
float salary,allowance,tax,total;
system("cls");
printf("****************************\n");
printf("* 添加子菜單 *\n");
printf("****************************\n");
printf("說明:4.返回主菜單 5.添加\n");
printf("請選擇需要使用的功能:");
fflush(stdin);
while((command=getchar())!='4')
{
if(command==4)
break;
printf("添加信息:\n");
node=(TEACHER *)malloc(sizeof(TEACHER));
fflush(stdin);
printf("姓名:");
fflush(stdin);
gets(node->name);
printf("單位:");
fflush(stdin);
gets(node->unit);
printf("基本工資:");
fflush(stdin);
scanf("%f",&salary);
node->salary=salary;
printf("津貼:");
scanf("%f",&allowance);
node->allowance=allowance;
fflush(stdin);
printf("扣稅:");
scanf("%f",&tax);
node->tax=tax;
fflush(stdin);
printf("總工資:");
scanf("%f",&total);
node->total=total;
fflush(stdin);
add(node);
fflush(stdin);
printf("輸入c退出,其他字元繼續\n");
if((command=getchar())=='c')
break;
}
return 0;
}

int save()
{
TEACHER *nod=head;
FILE *fp;
if((fp=fopen("teacher.txt","w+")) == NULL)
{
printf("打開文件異常\n");
return 0;
}
while(nod->next != NULL)
{
if(fwrite(nod,sizeof(TEACHER),1,fp)!=1){
printf("寫入異常\n");
return 0;
}

nod++;
}

fclose(fp);
return 1;

}

int searchmenu()
{
char name[16];
char command;

system("cls");
printf("****************************\n");
printf("* 查詢和修改子菜單 *\n");
printf("****************************\n");
printf("說明:4.返回主菜單 5.通過姓名/查找 6.修改 \n");
fflush(stdin);
printf("請輸出需要實現的操作:");
while((command=getchar()) !='4')
{
switch(command)
{
case '4': break;
case '5':

printf("請輸入需要查找的姓名:");
fflush(stdin);
gets(name);
search(name);
break;

// case '6': modify();break;
}
printf("請輸出需要實現的操作:");
}

return 0;
}

int menu()
{

char command;
int i,j=10;
system("cls");

printf("****************************\n");
printf("* 工資管理系統 *\n");
printf("****************************\n");
printf("----------------------------\n");
printf("說明:1.添加 2.查詢/修改 3.保存 4.退出\n");
printf("----------------------------\n");
printf("請輸出需要實現的操作:");
while((command=getchar())!='4'){
switch(command)
{
case '1': addmenu(); break;
case '2': searchmenu();break;
case '3': i=save();if(i)printf("保存成功!\n"); while(j--);break;
}
fflush(stdin);
/*子函數退出後再次顯示主界面*/
system("cls");
printf("****************************\n");
printf("* 工資管理系統 *\n");
printf("****************************\n");
printf("----------------------------\n");
printf("說明:1.添加 2.查詢/修改 3.保存 4.退出\n");
printf("----------------------------\n");
printf("請輸出需要實現的操作:");
}
printf("******感謝您使用本系統******\n");
return 0;
}

int main()
{
init();
menu();
return 0;
}

❷ 求C語言 工資管理系統 原代碼

#include <iostream>
#include <string>
#define MaxHEAP 100
using namespace std;
class Elem{
private:
int objectID;
int priority;
string proName;
public:
Elem(int objectID=0,int priority=0){
setID(objectID);
setPri(priority);
setProN(proName);
}
int getID(){
return objectID;
}
int getPri(){
return priority;
}
string getProN(){
return proName;
}
void setID(int id){
objectID=id;
}
void setPri(int pri){
priority=pri;
}
void setProN(string s)
{
proName=s;
}

};
class Heap
{
private:
Elem items[MaxHEAP];
int size;
public :
Heap(){
Elem items[MaxHEAP];
setSize(0);}
void setSize(int sz)
{size=sz;}

int heapIsEmpty(){
return size==0;
}
void heapInsert(Elem newItem)
{if(size<MaxHEAP)
{
items[size]=newItem;
int place=size;
int parent=(place-1)/2;
while((parent>=0)&&(items[parent].getPri()<items[place].getPri()))
{
Elem temp=items[parent];
items[parent]=items[place];
items[place]=temp;
place=parent;
parent=(place-1/2);
}
++size;
}
heapRebuild(0);
}
Elem heapDelete(int ID)
{
Elem rootItem;
if(!heapIsEmpty())
{
for(int i=0;i<size;i++)
if(items[i].getID()==ID)
{rootItem=items[i];
swap(items[i],items[0]);
}
items[0]=items[--size];
heapRebuild(0);
}
else cout<<"\n錯誤:目錄為空"<<endl;
return rootItem;
}
void heapInit(){
setSize(0);
cout<<"空的項目"<<endl;}
void heapView(){
if(size==0){
cout<<"空的項目!"<<endl;
}
else{
cout<<"共有項目數: "<<size<<endl;
for(int ct=0;ct<size;ct++){
cout<<"ID: "<<items[ct].getID()<<" 優先順序: "<<items[ct].getPri()
<<" 工資數目: " <<items[ct].getProN()<<endl;
}
}
}
void search(int ID)
{ int N=0;
for(int i=0;i<size;i++)
if(items[i].getID()==ID)
{N++;
cout<<"ID: "<<items[i].getID()<<" 優先順序: "<<items[i].getPri()
<<" 名稱: " <<items[i].getProN()<<endl; }
if(!N) cout<<"未找到匹配的ID"<<endl;
}

void heapRebuild(int root)
{
int child=2*root+1;
if(child<size)
{
int rightChild=child+1;
if((rightChild<size)&&(items[rightChild].getPri()>=items[child].getPri()))
{child=rightChild;
}
if(items[root].getPri()<=items[child].getPri())
{
Elem temp=items[root];
items[root]=items[child];
items[child]=temp;
heapRebuild(child);
}
}
}
};
class priQueue
{private:
Heap h;
public:
priQueue(){
Heap();
}
int priIsEmpty(){
return h.heapIsEmpty();
}
void priInit(){
h.heapInit();
}
void priInsert(Elem newItem){
h.heapInsert(newItem);
}
Elem priDelete(int ID){
return h.heapDelete(ID);
}
void priView(){h.heapView();
}
void search(int ID)
{
h.search(ID);
}

};

void showMenu(){
cout<<"------------------------------------------------"<<endl;
cout<<"-----------------*工資管理系統*-----------------"<<endl;
cout<<"------------------------------------------------"<<endl;
cout<<" 1.重置"<<endl;
cout<<" 2.輸入"<<endl;
cout<<" 3.刪除"<<endl;
cout<<" 4.查詢"<<endl;
cout<<" 5.列印"<<endl;
cout<<" 0.退出"<<endl;
cout<<"------------------------------------------------"<<endl;
}
void showTip(){
cout<<"---------------------------------^_^--操作完成!"<<endl;
cout<<"------------------------------------選擇0-5繼續"<<endl;
}
int main(){
string i="-1";
int ID,PRI;
string proName;
Elem in;
priQueue PQ;
PQ.priInit();
system("cls");
showMenu();
cout<<"選擇菜單中的數字以便處理數據!"<<endl;
cin>>i;
system("cls");
while(i!="0")
{ if(i=="1")
{ system("cls");
showMenu();
cout<<"你選擇了1,項目將全部清空:"<<endl;
PQ.priInit();
showTip();
}
else if(i=="2")
{system("cls");
showMenu();
cout<<"你選擇了2,輸入ID,優先順序,工資"<<endl;
cout<<"輸入 ID(數字):"<<endl;
cin>>ID;
cout<<"輸入優先順序(數字):"<<endl;
cin>>PRI;
cout<<"輸入工資數目(數字):"<<endl;
cin>>proName;
in.setID(ID);
in.setPri(PRI);
in.setProN(proName);
PQ.priInsert(in);
showTip();
}
else if(i=="3")
{system("cls");
showMenu();
cout<<"你選擇了3,請選擇你要刪除的ID號"<<endl;
cin>>ID;
PQ.priDelete(ID);
showTip();
}

else if(i=="4")
{system("cls");
showMenu();
cout<<"你選擇了4,輸入要查找的項目ID號"<<endl;
cin>>ID;
PQ.search(ID);
showTip();
}

else if(i=="5")
{system("cls");
showMenu();
cout<<"你選擇了5,整個系統工資情況顯示如下:"<<endl;
PQ.priView();
showTip();
}
else {
system("cls");
showMenu();
cout<<"無效輸入!"<<endl;
}
cin>>i;
system("cls");
}
return 0;
}

❸ 用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語言編寫工資管理系統

程序名稱:工資管理系統
程序說明:該系統在磁碟上儲存了某單位上月全體員工的工資信息,對於每一位職工存儲以下信息:
月份,職工編號,基本工資,津貼,崗貼,補貼,房貼,交通補貼,應發數,房租,儲蓄,
會費,個人所得稅,應扣數,實發數。

❺ C語言程序設計題:職工工資管理系統

你要的是命令行還是圖形界面?
如果是命令行可以考慮下
如果是圖形界面的話200分少了點,看看吧.
--------------------------------------------
既然不是圖形界面,代碼就簡單.不過也有近300行.可能有些地方不怎麼簡潔..
你用的時候,把注釋"delete this line"那行所在的代碼刪除或修改就OK了.
如果看不懂請給我留言,我發一份帶詳細注釋的代碼給你.
--------------------------------------------

/*
Microsoft Visual C++ .NET編譯通過
by 做他@07.12.29
*/

#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語言程序設計、工資管理系統

#include <stdio.h>
#include <malloc.h>
#include <string.h>
typedef struct
{
char num[10];
char name[20];
char date[15];
double pay;
}employee;
typedef struct node
{
employee p;
struct node *pre;
struct node *next;
}node,*linklist;

linklist head,last;

void setData(linklist p)
{
printf("編號:");
scanf("%s",&p->p.num);
printf("姓名:");
scanf("%s",&p->p.name);
printf("入職時間:");
scanf("%s",&p->p.date);
printf("工資:");
scanf("%lf",&p->p.pay);
}

void Insert(linklist p)
{
setData(p);
p->next=last;
last->pre->next=p;
p->pre=last->pre;
last->pre=p;
}
void Add()
{
char ch;
do
{
linklist p=(linklist)malloc(sizeof(node));
system("cls");
Insert(p);
printf("是否繼續?");
scanf(" %c",&ch);
}while(ch=='y'||ch=='Y');
}

linklist Qur(int method)
{
char ch[20];
linklist p=head->next;
if(method==0)
{
printf("選擇查詢方式:(1 姓名、2 年月)");
scanf("%d",&method);
}
if(method==1)
{
printf("輸入姓名:");
scanf("%s",ch);
while(p!=last)
{
if(strcmp(ch,p->p.name)==0) break;
p=p->next;
}
}
else if(method==2)
{
printf("輸入年月:");
scanf("%s",ch);
while(p!=last)
{
if(strcmp(ch,p->p.date)==0) break;
p=p->next;
}
}
if(p==last) {printf("未找到\n");system("pause");}
return p;
}

void Del()
{
linklist p=Qur(1);
if(p==last) return;
p->pre->next=p->next;
p->next->pre=p->pre;
free(p);
printf("刪除成功\n");
system("pause");
}

void Modify()
{
linklist p=Qur(1);
if(p==last) return ;
setData(p);
}
void printTitle()
{
printf("編號\t名稱\t入職日期\t工資\n");
}

void show(linklist p)
{
printf("%s\t%s\t%s\t%.2lf\n",p->p.num,p->p.name,p->p.date,p->p.pay);
}
void Sort()
{
linklist p,q;
for (p=head->next;p!=last;p=p->next)
{
for (q=p->next;q!=last;q=q->next)
{
if(p->p.pay<q->p.pay)
{
employee temp=p->p;
p->p=q->p;
q->p=temp;
}
}
}
printf("完成\n");
system("pause");
}

void Tongji()
{
linklist p=head->next;
Sort();
printTitle();
while(p!=last)
{
show(p);
p=p->next;
}
system("pause");
}

void Wrong()
{
printf("輸入錯誤!\n");
system("pause");
}
void menu(void)
{
system("cls");
printf("********工資管理系統*******\n");
printf("* *\n");
printf("* 1:添加 *\n");
printf("* 2:刪除 *\n");
printf("* 3:查詢 *\n");
printf("* 4:修改 *\n");
printf("* 5:統計 *\n");
printf("* 6:排序 *\n");
printf("* 0:退出 *\n");
printf("* *\n");
printf("*******************************\n");
}

int select()
{
int choose;
scanf("%d",&choose);
switch(choose)
{
case 1:Add();break;
case 2:Del();break;
case 3:
{
linklist p=Qur(0);
if(p!=last) {show(p);system("pause");}break;
}
case 4:Modify();break;
case 5:Tongji();break;
case 6:Sort();break;
case 0:break;
default:Wrong();break;
}
return choose;
}
void destroy()
{
linklist p=head->next;
while(p!=last)
{
head->next=p->next;
free(p);
p=head->next;
}
free(head);
free(last);
}
int main(void)
{
head=(linklist)malloc(sizeof(node));
last=(linklist)malloc(sizeof(node));
head->next=last;
last->next=NULL;
last->pre=head;
head->pre=NULL;
do
{
menu();
} while (select()!=0);
destroy();
return 0;
}

熱點內容
內置存儲卡可以拆嗎 發布:2025-05-18 04:16:35 瀏覽:335
編譯原理課時設置 發布:2025-05-18 04:13:28 瀏覽:378
linux中進入ip地址伺服器 發布:2025-05-18 04:11:21 瀏覽:612
java用什麼軟體寫 發布:2025-05-18 03:56:19 瀏覽:32
linux配置vim編譯c 發布:2025-05-18 03:55:07 瀏覽:107
砸百鬼腳本 發布:2025-05-18 03:53:34 瀏覽:943
安卓手機如何拍視頻和蘋果一樣 發布:2025-05-18 03:40:47 瀏覽:739
為什麼安卓手機連不上蘋果7熱點 發布:2025-05-18 03:40:13 瀏覽:803
網卡訪問 發布:2025-05-18 03:35:04 瀏覽:511
接收和發送伺服器地址 發布:2025-05-18 03:33:48 瀏覽:371