c語言報告小型公司工資管理系統的簡單介紹

本文目錄一覽:

求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(sizeMaxHEAP)

{

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;isize;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”共有項目數: “sizeendl;

for(int ct=0;ctsize;ct++){

cout”ID: “items[ct].getID()” 優先順序: “items[ct].getPri()

” 工資數目: ” items[ct].getProN()endl;

}

}

}

void search(int ID)

{ int N=0;

for(int i=0;isize;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(childsize)

{

int rightChild=child+1;

if((rightChildsize)(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;

cini;

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;

cinID;

cout”輸入優先順序(數字):”endl;

cinPRI;

cout”輸入工資數目(數字):”endl;

cinproName;

in.setID(ID);

in.setPri(PRI);

in.setProN(proName);

PQ.priInsert(in);

showTip();

}

else if(i==”3″)

{system(“cls”);

showMenu();

cout”你選擇了3,請選擇你要刪除的ID號”endl;

cinID;

PQ.priDelete(ID);

showTip();

}

else if(i==”4″)

{system(“cls”);

showMenu();

cout”你選擇了4,輸入要查找的項目ID號”endl;

cinID;

PQ.search(ID);

showTip();

}

else if(i==”5″)

{system(“cls”);

showMenu();

cout”你選擇了5,整個系統工資情況顯示如下:”endl;

PQ.priView();

showTip();

}

else {

system(“cls”);

showMenu();

cout”無效輸入!”endl;

}

cini;

system(“cls”);

}

return 0;

}

C語言課程設計 某企業職工工資管理系統

我這裡有一份我當年坐課程設計的程序,你可以改改

# include iostream

# include fstream

# include string

# include iomanip

# include stdlib.h

using namespace std;

struct worker_inf

{

int month; //月份

int code; //工人編號

string name; //姓名

float get[4]; //基本工資,津貼,房帖,交通補貼

float pay[4]; //房租,儲蓄,交通費,會費

float tax; //個人所得稅

float theory_num; //應發書

float reduce_num; //應扣數

float practice_num; //實發數

worker_inf *next;

};

/////////////////////////////////////////////////////////////////

class worker //定義職工類

{

private:

worker_inf *head;

void print(worker_inf *); //輸出一條指定職工的工資記錄,並返回該記錄的指針

worker_inf *find(int); //查找條例條件的記錄,並返回該記錄的指針

public:

worker(){head=NULL;}

worker_inf *get_head(){return head;}

int listcount(); //統計當前鏈表的記錄總數,並返回一個整數

void additem(int month,int code,string name,float get[4],float pay[4]); //添加一條工資記錄表尾

void removeitem(int); //刪除一條指定職工的工資記錄

int menu(); //修改某職工工資的菜單

void changemonth(); //修改月份

void changeitem(int); //修改職工的工資信息

void list(); //輸出當月全體職工的工資信息

void search(int); //輸出指定編號職工的工資信息

float tax_num(); //計算職工個人所得稅

float theorynumber(); //計算應發工資

float reducenumber(); //計算應扣工資

float practicenumber(); //計算實發工資

};

//////////////////////////////////////////////////////////////////

int worker::listcount() //統計當前鏈表數,並返回一個整數

{

if(!head)return 0;

worker_inf *p=head;

int n=0;

while(p)

{n++;p=p-next;}

return n;

}

//////////////////////////////////////////////////////////////////

void worker::additem(int month,int code,string name,float get[4],float pay[4]) //添加一條工資記錄到表尾

{

if(!head)

{

head=new worker_inf;

for(int i=0;i4;i++)

{

head-get[i]=get[i];

head-pay[i]=pay[i];

}

head-code=code;

head-month=month;

head-name=name;

head-next=NULL;

return;

}

worker_inf *t=head;

while(t t-code!=code)

t=t-next;

if(t)

{

cout”操作失敗:編號為”code”的記錄已經存在!”endl;

return;

}

worker_inf *p=head;

while(p-next)p=p-next;

worker_inf *p1=new worker_inf;

p1-code=code;

for(int i=0;i4;i++)

{

p1-get[i]=get[i];

p1-pay[i]=pay[i];

}

p1-code=code;

p1-month=month;

p1-name=name;

p1-next=NULL;

p-next=p1;

return;

}

////////////////////////////////////////////////////////////////////

void worker::removeitem(int code) //刪除一條指定職工的工資記錄

{

worker_inf *t=find(code);

if(!t)return;

worker_inf *p=head;//如果要刪除的記錄位於表頭

if(head==t)

{

head=head-next;

delete p;

cout”成功刪除編號為”code”的記錄!”endlendl;

return;

}

while(p-next!=t)p=p-next;

worker_inf *p1=p-next;

p-next=p1-next;

delete p1;

cout”成功刪除編號為”code”的記錄!”endlendl;

return;

}

////////////////////////////////////////////////////////////////

int worker::menu() //修改某一職工信息的菜單

{

int select=-1;

cout”\t\t\t\t\t\t**************修改菜單**************”endlendl;

cout”1.基本工資”endlendl;

cout”2.津貼”endlendl;

cout”3.房帖”endlendl;

cout”4.交通補貼”endlendl;

cout”5.房租”endlendl;

cout”6.儲蓄”endlendl;

cout”7.交通費”endlendl;

cout”8.會費”endlendl;

cout”0.退出修改系統”endlendl;

cout”[請選擇(輸入相應數字)]:”;

cinselect;

if(select0||select9)

{

cout”對不起您輸入錯誤!請重新輸入【0-9】:”endl;

cinselect;

}

return select;

}

/////////////////////////////////////////////////////////////////

int menu();

void worker::changeitem(int code) //修改某職工部分工資信息

{

worker_inf *p=find(code);

if(!p){cout”不存在職工編號為”code”的職工工資信息”endl;return;}

int select;

while(1)

{

float m;

select=menu();

if(select==0){system(“cls”);break;}

cout”請輸入修改後的值”;

cinm;

int n;

if(select=4){

n=select-1;

p-get[n]=m;}

else{

n=select-5;

p-pay[n]=m;}

tax_num();

theorynumber();

reducenumber();

practicenumber();

cout”修改成功”endl;

}

}

////////////////////////////////////////////////////////////////////

void worker::changemonth() //修改月份

{

worker_inf *p=head;

while(p)

{

if(p-month==12)p-month=1;

else

p-month++;

p=p-next;

}

}

//////////////////////////////////////////////////////////////////////

void worker::print(worker_inf *p)//輸出worker_inf制定的記錄

{

cout.precision(0);

coutp-month” “;

coutp-code” “;

coutp-name”\t”;

for(int i=0;i4;i++)

{coutsetiosflags(ios::fixed)p-get[i]”\t”;}

for(int j=0;j4;j++)

{coutp-pay[j]”\t”;}

coutp-tax”\t”;

coutp-theory_num”\t”;

coutp-reduce_num”\t”;

coutp-practice_numendlendl;

return;

}

///////////////////////////////////////////////////////////////////////

void worker::list() //列出當前鏈表中的所有記錄

{

if(listcount==0)

{

cout”錯誤:當前的列表為空!”endl;

return;

}

worker_inf *p=head;

cout”共有記錄:”listcount()endl;

cout”月份\t編號\t姓名\t基本工資\t津貼\t房帖\t交通補貼\t房租\t儲蓄\t交通費\t會費\t個人所得稅\t應發工資\t應扣工資\t實際工資”endl;

while(p)

{

print(p);

p=p-next;

}

coutendl;

return;

}

/////////////////////////////////////////////////////////////////////////

void worker::search(int code) //在當前鏈表查找指定記錄並輸出

{

cout”searching…..”endl;

worker_inf *p=find(code);

if(p)

{

cout”月份\t編號\t姓名\t基本工資\t津貼\t房帖\t交通補貼\t房租\t儲蓄\t交通費\t會費\t個人所得稅\t應發工資\t應扣工資\t實際工資”endl;

print(p);

}

coutendl;

}

//////////////////////////////////////////////////////////////////////////

worker_inf *worker::find(int code) //查找條例條件的記錄,並返回該指針

{

if(listcount==0)

{

cout”錯誤:當前列表為空!”endl;

return NULL;

}

worker_inf *p=head;

while(p)

{

if(p-code==code)break;

p=p-next;

}

if(!p)

{

cout”錯誤:找不到該記錄!\n”;

return NULL;

}

return p;

}

//////////////////////////////////////////////////////////////////////////

float worker::theorynumber() //計算應發數

{

int i;

if(listcount()==0)

{

cout”錯誤:當前的列表為空!”endl;

return -1;

}

float sum;

worker_inf *p=head;

while(p)

{

sum=0;

for(i=0;i4;i++)

sum+=p-get[i];

p-theory_num=sum;

p=p-next;

}

return 0;

}

//////////////////////////////////////////////////////////////////

float worker::tax_num() //計算個人所得稅

{

if(listcount==0)

{

cout”錯誤:當前的列表為空!”endl;

return -1;

}

worker_inf *p=head;

while(p)

{

float s;

s=p-theory_num;

if(s=800)

p-theory_num=0;

else if(s=2000) p-theory_num=(s-800)*0.05;

else if(s=5000)

p-theory_num=(s-2000)*0.1+60;

else p-theory_num=(s-5000)*0.2+360;

p=p-next;

}

return 0;

}

///////////////////////////////////////////////////////////////////////

float worker::reducenumber() //計算應扣數

{

int i;

if(listcount==0)

{

cout”錯誤:當前的列表為空!”endl;

}

float sum;

worker_inf *p=head;

while(p)

{

sum=0;

for(i=0;i4;i++)

sum+=p-pay[i];

p-reduce_num=p-tax+sum;

p=p-next;

}

return 0;

}

/////////////////////////////////////////////////////////////////////////

float worker::practicenumber() //計算實發數

{

if(listcount()==0)

{

cout”錯誤:當前的列表為空!”endl;

return -1;

}

worker_inf *p=head;

while(p)

{

float a,b;

a=p-theory_num;

b=p-reduce_num;

p-practice_num=a-b;

p=p-next;

}

return 0;

}

////////////////////////////////////////////////////////////////////////////

worker worker; //定義全局變數

int menu()

{

int select=-1;

cout”*****************主菜單***********************”endlendl;

cout”1.添加職工信息;”endlendl;

cout”2.刪除職工信息;”endlendl;

cout”3.修改職工的工資信息;”endlendl;

cout”4.按職工編號查找記錄;”endlendl;

cout”5.列出所有記錄;”endlendl;

cout”6.從數據文件導入當月工資信息;”endlendl;

cout”7.將當月工資信息導出到磁碟文件;”endlendl;

cout”0.安全退出系統;”endlendl;

cout”[請選擇(輸入相應的數字)]:”;

cinselect;

return select;

}

/////////////////////////////////////////////////////////////////////////////

char exit()

{

char s;

cout”確定要退出程序嗎?[Y/N]:”;

cins;

return s;

}

//////////////////////////////////////////////////////////////////////////////

void input(int *month,int*code,string *name,float get[4],float pay[4]) //輸入職工信息

{

cout”請輸入月份 編號 姓名 基本工資 津貼 房帖 交通補貼 房租 儲蓄 交通費 會費:”endl;

cin*month;

cin*code;

if(*code==-1)return;

cin*nameget[0]get[1]get[2]get[3]pay[0]pay[1]pay[2]pay[3];

return;

}

///////////////////////////////////////////////////////////////////////////////

void addnew() //增加記錄

{

int month=0,code=0;float get[4]={0},pay[4]={0};

string name=””;

coutendl”當輸入的職工編號為-1時表示輸入結束。”endl;

input(month,code,name,get,pay);

while(code!=-1)

{

worker.additem(month,code,name,get,pay);

worker.tax_num();

worker.theorynumber();

worker.reducenumber();

worker.practicenumber();

input(month,code,name,get,pay);

}

return;

}

////////////////////////////////////////////////////////////////////////////////

void dofind() //按職工編號查找

{

int code;

coutendl”當輸入的編號為-1時表示結束輸入.”endl;

do

{

cout”請輸入要查找的職工的編號:”;

cincode;

if(code==-1)continue;

worker.search(code);

}while(code!=-1);

return;

}

/////////////////////////////////////////////////////////////////////////////////

void dodelete() //刪除職工信息

{

coutendl”當輸入的編號為-1時表示輸入結束.”endl;

int code;

do

{

cout”請輸入要刪除的職工的編號:”;

cincode;

if(code==-1)continue;

worker.removeitem(code);

}while(code!=-1);

return;

}

///////////////////////////////////////////////////////////////////////////////////

void domodify() //修改職工信息

{

int code;

cout”當輸入職工編號為-1時表示結束修改”endl;

while(1){

cout”請輸入所需修改職工編號”;

cincode;

if(code==-1)return;

else

worker.changeitem(code);

}

return;

}

///////////////////////////////////////////////////////////////////////////////////

void SaveFilethism()//將當月工資信息寫入文件

{

worker_inf *p;

char name[20];

fstream iofile;

int i=0;

iofile.open(“Worker_5th.dat”,ios::out|ios::binary);

if(!iofile)

{

cerr”open error!”endl;

abort();

}

p=worker.get_head();

while(p)

{

p-name.copy(name,20,0);

name[p-name.length()]=0;

iofile.write((char *) p-code,sizeof(int));

iofile.write((char *) p-month,sizeof(int));

iofile.write((char *) name,20);

for(int i=0;i4;i++)

{

iofile.write((char *) p-get[i],sizeof(float));

}

for(int j=0;j4;j++)

{

iofile.write((char *) p-pay[j],sizeof(float));

}

p=p-next;

}

iofile.close();

cout”成功將工資信息存入文件”endl;

}

////////////////////////////////////////////////////////////////////////

void Loadfilethism() //讀取當月全體職工的工資信息文件

{

int month,code;

char name[20]=””;

float get[4],pay[4];

fstream iofile;

int i=0;

iofile.open(“Worker_5th.dat”,ios::in|ios::binary);

if(!iofile)

{

cout”數據文件不存在,請先建立該文件”endl;

return;

}

if(iofile.eof())

{

cout”資料庫為空,請先添加數據”endl;

iofile.close();

}

else

{

while(iofile.peek()!=EOF)//peek()是取文件當前指針,EOF是文件尾標符

{

iofile.read((char *) code,sizeof(int));

iofile.read((char *) month,sizeof(int));

iofile.read((char *) name,20);

for(int i=0;i4;i++)

{

iofile.read((char *) get[i],sizeof(float));

} for(int j=0;j4;j++)

{

iofile.read((char *) pay[j],sizeof(float));

}

worker.additem(code,month,name,get,pay);

}

worker.tax_num();

worker.theorynumber();

worker.reducenumber();

worker.practicenumber();

iofile.close();

cout”成功導入工資信息”endl;

}

}

/////////////////////////////////////////////////////////////////////////

void list()

{

worker.list();

}

/////////////////////////////////////////////////////////////////////////

int main()

{

cout”******************歡迎進入職工工資管理系統*******************”endlendl;

int select;

char s;

while(1)

{

select=menu();

switch(select)

{

case 0: //退出程序

s=exit();

if(s==’y’||s==’Y’) return 0;

break;

case 1: //增加新記錄

addnew();

break;

case 2: //刪除記錄

dodelete();

break;

case 3: //修改記錄

domodify();

break;

case 4: //按條件查找

dofind();

break;

case 5: //列出全部記錄

list();

break;

case 6: //導入當月職工記錄

Loadfilethism();

break;

case 7: //將職工記錄存入磁碟

SaveFilethism();

break;

default:

cout”此輸入無效!”endl;

}

}

return 0;

}

用C語言設計職工工資管理系統

#includeiostream.h

#includestdlib.h

#includestring.h

#includeiomanip.h

using namespace std;

#define OK 1

#define ERROR 0

typedef struct LNode{

char num[20];

char name[20];

double basic;

double reward;

double total;

struct LNode *next;

}LNode,*LinkList; int initlist(LinkList L)

{ L=(LinkList)malloc(sizeof(LNode));

L-next=NULL;

return OK;

} int DisplayInfo(LinkList L)

{

LinkList p=L-next;

if(!p)

{

cout”當前無記錄!”endl;

return ERROR;

}

cout”編號”setw(12)”姓名”setw(12)”基本工資”setw(9)”獎金”setw(12)”工資總額”endl; while(p!=NULL)

{

coutp-numsetw(9)p-namesetw(8)p-basicsetw(12)p-rewardsetw(12)p-totalendl;

p=p-next;

}

cout’\n”\n’;

return OK;

} int InputInfo(LinkList L)

{

LinkList p; p=(LinkList)malloc(sizeof(LNode));

cout”請輸入職工工資信息:(格式如:2001001 james 1980 600 )”endl;

cinp-num;

cinp-name;

cinp-basic;

cinp-reward;

p-total=p-basic+p-reward;

p-next=L-next;

L-next=p; return OK;

}int DeleteByCode(LinkList L,char key[])

{

LinkList p=L,q;

while(p-next!=NULL)

{

if(strcmp(p-next-num,key)==0)

{

q=p-next;

p-next=q-next;

free(q);

return OK;

}

p=p-next;

}

return ERROR;} int Search(LinkList L,int tag)

{

LinkList p=L-next;

if(tag==1)

{

char num[20];

cout”請輸入要查找職工編號號:”endl;

cinnum;

while(p)

{

if(strcmp(p-num,num)==0)

{

cout”編號”setw(12)”姓名”setw(12)”基本工資”setw(9)”獎金”setw(12)”工資總額”endl;

coutp-numsetw(9)p-namesetw(8)p-basicsetw(12)p-rewardsetw(12)p-totalendl;

cout’\n’;

return OK;

}

p=p-next;

}

}

else if(tag==2)

{

char name[20];

cout”請輸入要查找的姓名:”endl;

cinname;

while(p)

{

if(strcmp(p-name,name)==0)

{

cout”編號”setw(12)”姓名”setw(12)”基本工資”setw(9)”獎金”setw(12)”工資總額”endl;

coutp-numsetw(9)p-namesetw(8)p-basicsetw(12)p-rewardsetw(12)p-totalendl;

cout’\n’;

return OK;

}

p=p-next;

}

}

else

cout”輸入錯誤!”endl;

return ERROR;}

int Sort(LinkList L)

{

LinkList p;

LinkList q,min,w=L;

for(p=L-next;p-next;p=p-next)

{

min=p;

for(q=p-next;q;q=q-next) if(min-totalq-total)

min=q; if(min!=p)

{ strcpy(w-num,p-num);

strcpy(w-name,p-name);

w-basic=p-basic;

w-reward=p-reward;

w-total=p-total;

strcpy(p-num,min-num);

strcpy(p-name,min-name);

p-basic=min-basic;

p-reward=min-reward;

p-total=min-total;

strcpy(min-num,w-num);

strcpy(min-name,w-name);

min-basic=w-basic;

min-reward=w-reward;

min-total=w-total; }

}

return OK;

}

int change(LinkList L)

{

LinkList p=L-next;

char q[20];

cout”請輸入要修改的職工編號號:”endl;

cinq;

while(p)

{

if(strcmp(p-num,q)==0)

{

cout”編號”setw(12)”姓名”setw(12)”基本工資”setw(9)”獎金”setw(12)”工資總額”endl;

coutp-numsetw(9)p-namesetw(8)p-basicsetw(12)p-rewardsetw(12)p-totalendl;

cout”請重新輸入該職工的工資信息:”endl;

cinp-basic;

cinp-reward;

cout’\n’;

return OK;

}

p=p-next;

}

}

int Menu(LinkList S)

{

int sign=1;

while(sign)

{

int i;

cout”請選擇要進行的操作:1:插入 2:刪除 3:輸出 4:查找 5:排序 6:修改 0:退出”endl;

cini;

if(i==1)

{ if(InputInfo(S))

cout”操作成功!”endl;

cout’\n’;

}

else if(i==2)

{

char num[20];

cout”請輸入要刪除的職工編號:”endl;

cinnum; if(DeleteByCode(S,num))

cout”操作成功!”endl; else

{

cout”此編號不存在!”endl;

cout’\n’;

}

}

else if(i==3)

DisplayInfo(S);

else if(i==4)

{

int tag;

cout”1:按編號查找 2:按姓名查找 “endl;

cintag;

if(!Search(S,tag))

cout”未找到!”endl;

cout’\n’; }

else if(i==5)

{

if(Sort(S));

cout”操作成功!”endl;

cout’\n’;

}

else if(i==6)

{

if(change(S))

cout”修改成功!”endl;

} else if(i==0)

sign=0;

else

cout”輸入有誤,請重新輸入!”endl;

cout’\n’;

}

return OK;

}

int main()

{

LinkList S;

initlist(S);

Menu(S);

return OK;} 已經調試無bug 有問題的話聯繫我。

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) 退出程序。

*/listemployee 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 linecout”請選擇操作:1.錄入 2.刪除 3.修改 4.查詢 5.顯示所有員工 6.退出 :”;

int choose=0;

cinchoose;

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.退出:”;

cinchoice;

if (choice==1) show_name();

if (choice==2) show_dep();

if (choice==3)

{

cout”請選擇操作:1.錄入 2.刪除 3.修改 4.查詢 5.顯示所有員工 6.退出 :”;

cinchoose;

assert(!cin.fail());

continue;

}

}

if (choose==5) show_all();

cout”請選擇操作:1.錄入 2.刪除 3.修改 4.查詢 5.顯示所有員工 6.退出 :”;

cinchoose;

assert(!cin.fail());

}

return 0;

}void print(const employee e)

{

cout”編號:”e.m_numendl;

cout”姓名:”e.m_nameendl;

cout”部門:”e.m_dependl;

cout”保險:”e.m_insuranceendl;

cout”稅金:”e.m_taxendl;

cout”應付工資:”e.m_salaryendl;

cout”實付工資:”e.m_salary-e.m_insurance-e.m_taxendl;

}void input()

{

string num,name,dep;

double salary,ins,tax;

cout”請輸入員工編號:”;

cinnum;

cout”請輸入員工姓名:”;

cinname;

cout”請輸入員工部門:”;

cindep;

cout”請輸入員工保險:”;

cinins;

assert(!cin.fail());

cout”請輸入員工稅金:”;

cintax;

assert(!cin.fail());

cout”請輸入員工應付工資:”;

cinsalary;

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”請輸入要刪除的員工姓名:”;

cinname;

listemployee::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”請輸入要修改的員工姓名:”;

cinname;

listemployee::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);

coutendl;

cout”請輸入新的員工編號:”;

cinnum;

cout”請輸入新的員工姓名:”;

cinname;

cout”請輸入新的員工部門:”;

cindep;

cout”請輸入新的員工保險:”;

cinins;

assert(!cin.fail());

cout”請輸入新的員工稅金:”;

cintax;

assert(!cin.fail());

cout”請輸入新的員工工資:”;

cinsalary;

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”;

listemployee::iterator iter;

for(iter=emps.begin();iter!=emps.end();iter++)

{

coutendl;

print(*iter);

coutendl;

}

cout”——————–\n”;

}void show_name()

{

if (emps.size()==0)

{

cout”員工記錄為空.\n”;

return;

}

bool isfind=false;

string name;

cout”請輸入要查詢的員工姓名:”;

cinname;

listemployee::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”請輸入要查詢的部門名稱:”;

cindep;

cout”部門[“dep”]的員工信息:\n”;

cout”——————–\n\n”;

listemployee::iterator iter;

for(iter=emps.begin();iter!=emps.end();iter++)

{

if (iter-m_dep==dep)

{

isfind++;

total_salary+=iter-m_salary;

print(*iter);

coutendl;

continue;

}

}

cout”——————–\n”;

if (isfind==0)

{

cout”沒有找到名稱為[“dep”]的部門.\n”;

}

else

{

cout”部門[“dep”]工資統計:\n”;

cout”工資總額:”total_salaryendl;

cout”平均工資:”total_salary/isfindendl;

}

}

用C語言課程設計—職工工資管理系統(分別用結構體數組和鏈表編寫程序)

#includestdio.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;in;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;in;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)!=0in);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;ji;j++)

fwrite(emp[j],sizeof(struct emploee),1,fp);

for(j=i+1;jn;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;in;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”);

}

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/286967.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-23 13:06
下一篇 2024-12-23 13:06

相關推薦

  • Python簡單數學計算

    本文將從多個方面介紹Python的簡單數學計算,包括基礎運算符、函數、庫以及實際應用場景。 一、基礎運算符 Python提供了基礎的算術運算符,包括加(+)、減(-)、乘(*)、除…

    編程 2025-04-29
  • AES加密解密演算法的C語言實現

    AES(Advanced Encryption Standard)是一種對稱加密演算法,可用於對數據進行加密和解密。在本篇文章中,我們將介紹C語言中如何實現AES演算法,並對實現過程進…

    編程 2025-04-29
  • Python滿天星代碼:讓編程變得更加簡單

    本文將從多個方面詳細闡述Python滿天星代碼,為大家介紹它的優點以及如何在編程中使用。無論是剛剛接觸編程還是資深程序員,都能從中獲得一定的收穫。 一、簡介 Python滿天星代碼…

    編程 2025-04-29
  • 學習Python對學習C語言有幫助嗎?

    Python和C語言是兩種非常受歡迎的編程語言,在程序開發中都扮演著非常重要的角色。那麼,學習Python對學習C語言有幫助嗎?答案是肯定的。在本文中,我們將從多個角度探討Pyth…

    編程 2025-04-29
  • Python被稱為膠水語言

    Python作為一種跨平台的解釋性高級語言,最大的特點是被稱為”膠水語言”。 一、簡單易學 Python的語法簡單易學,更加人性化,這使得它成為了初學者的入…

    編程 2025-04-29
  • Python海龜代碼簡單畫圖

    本文將介紹如何使用Python的海龜庫進行簡單畫圖,並提供相關示例代碼。 一、基礎用法 使用Python的海龜庫,我們可以控制一個小海龜在窗口中移動,並利用它的「畫筆」在窗口中繪製…

    編程 2025-04-29
  • OpenJudge答案1.6的C語言實現

    本文將從多個方面詳細闡述OpenJudge答案1.6在C語言中的實現方法,幫助初學者更好地學習和理解。 一、需求概述 OpenJudge答案1.6的要求是,輸入兩個整數a和b,輸出…

    編程 2025-04-29
  • Python按位運算符和C語言

    本文將從多個方面詳細闡述Python按位運算符和C語言的相關內容,並給出相應的代碼示例。 一、概述 Python是一種動態的、面向對象的編程語言,其按位運算符是用於按位操作的運算符…

    編程 2025-04-29
  • Python語言由荷蘭人為中心的全能編程開發工程師

    Python語言是一種高級語言,很多編程開發工程師都喜歡使用Python語言進行開發。Python語言的創始人是荷蘭人Guido van Rossum,他在1989年聖誕節期間開始…

    編程 2025-04-28
  • Python語言設計基礎第2版PDF

    Python語言設計基礎第2版PDF是一本介紹Python編程語言的經典教材。本篇文章將從多個方面對該教材進行詳細的闡述和介紹。 一、基礎知識 本教材中介紹了Python編程語言的…

    編程 2025-04-28

發表回復

登錄後才能評論