課程設計統計工資
1. 課程設計教職工工資程序
認識你,我給你!
2. 統計工資 C++ 課程設計 有高手幫做嗎
//=================================================
//文件名:Wage.cpp
//文件描述:這個文件描述了公司職員工資統計
//編譯環境:C-Free4.1 MingGW32 && Microsoft Visual Studio 2008
//作者:無敵隊長(effor)
//完成日期:2008-11-2
//保留所有權利(c)東北大學秦皇島分校,2008.
//=================================================
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#define OK 1
#define ERROR 0
#define MAX_SIZE 100
using namespace std;
//-------------------------------------------------
typedef int Status;
struct employee
{
int age;
char name[15];
double salary;
};//-----------------------------------------------
void display(employee company[],int N)//展示所有員工作息
{
if(N==0){cout<<"沒有任何員工信息;\n";return;}
cout<<"===================="<<endl
<<"姓名 年齡 工資\n";
for(int i=0;i<N;i++)
{
cout<<setiosflags(ios::left)<<setw(7)<<company[i].name<<" "
<<setw(4)<<company[i].age<<" "
<<setw(10)<<company[i].salary<<endl;
}
cout<<"====================\n";
system("pause");
}//------------------------------------------------
int readfile(employee company[])//從文件讀入所有員工作息
{
int N=0;
ifstream in("incompany.txt");//讀入文件,文件名為incompany.txt
for(int i=0;;i++,N++)
{
in>>company[i].name>>company[i].age>>company[i].salary;
if(!in) break;
}
cout<<"你選擇了文件輸入:\n";
display(company,N);
return N;
}//---------------------------------------------------
void savefile(employee company[],int N)//將所有員工信息寫入文件
{
for(int i=0;i<N;i++)
{
cout<<company[i].name<<" "
<<company[i].age<<" "
<<company[i].salary<<endl;
}
cout<<"保存成功!\n";
}//----------------------------------------------------
Status update(employee company[],int N)//更新某個員工信息
{
char eName[15];
cout<<"請輸入員工姓名:\n";
cin>>eName;
for(int i=0;i<N;i++)
{
if(strcmp(company[i].name,eName)==0)
{
cout<<setw(7)<<company[i].name<<" "
<<setw(4)<<company[i].age<<" "
<<setw(10)<<company[i].salary<<endl
<<"請輸入修改後員工的姓名,年齡,工資.\n";
cin>>company[i].name>>company[i].age>>company[i].salary;
return OK;
}
}
cout<<"找不到這個員工的信息!\n";
return ERROR;
}//-------------------------------------------------
int read(employee company[])//手動輸入員工信息,並列印出來
{
int N;
cout<<"你選擇了手動輸入\n";
cout<<"請輸入員工人數:\n";
cin>>N;
for(int i=0;i<N;i++)
{
cout<<"輸入第"<<i+1<<"個員工姓名:\n";
cin>>company[i].name;
cout<<"輸入第"<<i+1<<"個員工年齡:\n";
cin>>company[i].age;
cout<<"輸入第"<<i+1<<"工資:\n";
cin>>company[i].salary;
}
display(company,N);
return N;
}//-----------------------------------------------
double total(employee company[],int N,int AgeStart=0,int AgeEnd=100)
{//計算某個年齡段的員工總工資,返回值為總工資
cout<<"請輸入起始年齡:\n";
cin>>AgeStart;
cout<<"請輸出結束年齡\n";
cin>>AgeEnd;
double sum=0;
for(int i=0;i<N;i++)
{
if(company[i].age>=AgeStart&&company[i].age<=AgeEnd)
sum+=company[i].salary;
}
cout<<"年齡段:"<<AgeStart<<"~"<<AgeEnd<<";\n";
cout<<"人數為"<<N<<",\n總工資:"<<sum<<endl;
return sum;
}//-----------------------------------------------
double mean(employee company[],int N,int AgeStart=0,int AgeEnd=100)
{//計算某個年齡段的員工平均工資,返回值為平均工資
cout<<"請輸入起始年齡:\n";
cin>>AgeStart;
cout<<"請輸出結束年齡\n";
cin>>AgeEnd;
double sum=0;
int num=0;
for(int i=0;i<N;i++)
{
if(company[i].age>=AgeStart&&company[i].age<=AgeEnd)
{
sum+=company[i].salary;
num++;
}
}
cout<<"年齡段:"<<AgeStart<<"~"<<AgeEnd<<";\n";
cout<<"人數為"<<N<<",\n平均工資:"<<sum/num<<endl;
return sum/num;
}//-----------------------------------------------
int main()
{
int slct;//選擇讀入方式
int N=0;
employee company[MAX_SIZE];//定義員工信息表
cout<<"請選擇:\n"
<<"1.文件讀取員工信息;\n"
<<"2.手動輸入員工信息;\n";
cin>>slct;
if(slct==1) N=readfile(company);
else if(slct==2) N=read(company);
else N=0;
for(int choice;;)//無限循環,輸入0退出
{
system("cls");
cout<<"================================\n"
<<" 歡迎使用員工工資管理系統\n"
<<"================================\n"
<<"請選擇:\n"
<<"1.更新員工信息;\n"
<<"2.計算員工總工資;\n"
<<"3.計算員工平均工資;\n"
<<"4.保存員工信息到文件;\n"
<<"0.退出!\n"
<<"================================\n";
cin>>choice;
if(!cin) continue;
switch(choice)
{
case 1:update(company,N);break;
case 2:total(company,N);break;
case 3:mean(company,N);break;
case 4:savefile(company,N);break;
case 0:exit(0);
}
system("pause");
}
return 0;
}//主函數結束
以下是incompany.txt文件內容(分隔線內(不函分隔線))
---------------------------------
Selina 27 130000
Ella 27 140000
Hebe 25 120000
---------------------------------
PS:這是學習C/C++非常簡單的題目,要經常編才行.
由於網路知道回答過濾多餘空格,要源文件給留下你的Email吧.
3. C語言課程設計-員工工資統計
使用C的結構指針數組?
看來只是為了使用而使用了
4. 課程設計,工資管理系統完整源代碼
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#define MONTH_NUM 5 /* 最多的月份 */
struct worker
{
int number; /* 每個工人的工號 */
char name[15]; /* 每個工人的姓名 */
int salary[MONTH_NUM]; /* 每個工人M月的工資 */
int sum; /* 每個工人的總工資 */
float average; /* 每個工人的平均工資 */
struct worker *next;
};
typedef struct worker STU;
char Menu(void);
int Ascending(int a, int b);
int Descending(int a, int b);
void IntSwap(int *pt1, int *pt2);
void CharSwap(char *pt1, char *pt2);
void FloatSwap(float *pt1, float *pt2);
STU *AppendNode(STU *head, const int m);
STU *DeleteNode(STU *head, int nodeNum);
STU *ModifyNode(STU *head, int nodeNum, const int m);
STU *SearchNode(STU *head, int nodeNum);
STU *Appendsalary(STU *head, const int m);
void Totalsalary(STU *head, const int m);
void Printsalary(STU *head, const int m);
STU *Deletesalary(STU *head, const int m);
void Modifysalary(STU *head, const int m);
void Sortsalary(STU *head, const int m, int (*compare)(int a, int b));
void Searchsalary(STU *head, const int m);
void DeleteMemory(STU *head);
main()
{
char ch;
int m;
STU *head = NULL;
printf("輸入要記錄的月份(m<10):");
scanf("%d", &m);
while (1)
{
ch = Menu();
switch (ch)
{
case'1':head = Appendsalary(head, m);
Totalsalary(head, m);
break;
case'2':Printsalary(head, m);
break;
case'3':head = Deletesalary(head, m);
printf("\nAfter deleted\n");
Printsalary(head, m);
break;
case'4':Modifysalary(head, m);
Totalsalary(head, m);
printf("\nAfter modified\n");
Printsalary(head, m);
break;
case'5':Searchsalary(head, m);
break;
case'6':Sortsalary(head, m, Descending);
printf("\nsorted in descending order by sum\n");
Printsalary(head, m);
break;
case'7':Sortsalary(head, m, Ascending);
printf("\nsorted in ascending order by sum\n");
Printsalary(head, m);
break;
case'0':exit(0);
DeleteMemory(head);
printf("End of program!");
break;
default:printf("Input error!");
break;
}
}
}
char Menu(void)
{
char ch;
printf("\n管理工人的工資\n");
printf(" 1.添加記錄\n");
printf(" 2.列出記錄\n");
printf(" 3.刪除記錄\n");
printf(" 4.修改記錄\n");
printf(" 5.查找記錄\n");
printf(" 6.降序排列\n");
printf(" 7.升序排列\n");
printf(" 0.退出\n");
printf("請輸入你的選擇:");
scanf(" %c", &ch); /*在%c前面加一個空格,將存於緩沖區中的回車符讀入*/
return ch;
}
STU *Appendsalary(STU *head, const int m)
{
int i = 0;
char c;
do{
head = AppendNode(head, m); /*向鏈表末尾添加一個節點*/
printf("你想添加一個新的記錄嗎(Y/N)?");
scanf(" %c",&c); /*%c前面有一個空格*/
i++;
}while (c=='Y' || c=='y');
printf("%d new nodes have been apended!\n", i);
return head;
}
STU *Deletesalary(STU *head, const int m)
{
int i = 0, nodeNum;
char c;
do{
printf("請輸入你想刪除的記錄編號:");
scanf("%d", &nodeNum);
head = DeleteNode(head, nodeNum); /*刪除工號為nodeNum的工人信息*/
Printsalary(head, m); /*顯示當前鏈表中的各節點信息*/
printf("Do you want to delete a node(Y/N)?");
scanf(" %c",&c); /*%c前面有一個空格*/
i++;
}while (c=='Y' || c=='y');
printf("%d nodes have been deleted!\n", i);
return head;
}
void Modifysalary(STU *head, const int m)
{
int i = 0, nodeNum;
char c;
do{
printf("請輸入你想修改的記錄編號:");
scanf("%d", &nodeNum);
head = ModifyNode(head, nodeNum, m); /*修改工號為nodeNum的節點*/
printf("Do you want to modify a node(Y/N)?");
scanf(" %c",&c); /*%c前面有一個空格*/
i++;
}while (c=='Y' || c=='y');
printf("%d nodes have been modified!\n", i);
}
void Totalsalary(STU *head, const int m)
{
STU *p = head;
int i;
while (p != NULL) /*若不是表尾,則循環*/
{
p->sum = 0;
for (i=0; i<m; i++)
{
p->sum += p->salary[i];
}
p->average = (float)p->sum / m;
p = p->next; /*讓p指向下一個節點*/
}
}
void Sortsalary(STU *head, const int m, int (*compare)(int a, int b))
{
STU *pt;
int flag = 0, i;
do{
flag = 0 ;
pt = head;
/*若後一個節點的總工資比前一個節點的總工資高,則交換兩個節點中的數據
注意只交換節點數據,而節點順序不變,即節點next指針內容不進行交換*/
while (pt->next != NULL)
{
if ((*compare)(pt->next->sum, pt->sum))
{
IntSwap(&pt->number, &pt->next->number);
CharSwap(pt->name, pt->next->name);
for (i=0; i<m; i++)
{
IntSwap(&pt->salary[i], &pt->next->salary[i]);
}
IntSwap(&pt->sum, &pt->next->sum);
FloatSwap(&pt->average, &pt->next->average);
flag = 1;
}
pt = pt->next;
}
}while(flag);
}
/*交換兩個整型數*/
void IntSwap(int *pt1, int *pt2)
{
int temp;
temp = *pt1;
*pt1 = *pt2;
*pt2 = temp;
}
/*交換兩個實型數*/
void FloatSwap(float *pt1, float *pt2)
{
float temp;
temp = *pt1;
*pt1 = *pt2;
*pt2 = temp;
}
/*交換兩個字元串*/
void CharSwap(char *pt1, char *pt2)
{
char temp[15];
strcpy(temp, pt1);
strcpy(pt1, pt2);
strcpy(pt2, temp);
}
/*決定數據是否按升序排序,a<b為真,則按升序排序*/
int Ascending(int a, int b)
{
return a < b;
}
/* 決定數據是否按降序排序,a>b為真,則按降序排序 */
int Descending(int a, int b)
{
return a > b;
}
void Searchsalary(STU *head, const int m)
{
int number, i;
STU *findNode;
printf("請輸入你想查找的記錄編號:");
scanf("%d", &number);
findNode = SearchNode(head, number);
if (findNode == NULL)
{
printf("Not found!\n");
}
else
{
printf("\nNo.%3d%8s", findNode->number, findNode->name);
for (i=0; i<m; i++)
{
printf("%7d", findNode->salary[i]);
}
printf("%9d%9.2f\n", findNode->sum, findNode->average);
}
}
void Printsalary(STU *head, const int m)
{
STU *p = head;
char str[100] = {'\0'}, temp[3];
int i, j = 1;
strcat(str, "Number Name ");
for (i=1; i<=m; i++)
{
strcat(str, "salary");
itoa(i,temp, 10);
strcat(str, temp);
strcat(str, " ");
}
strcat(str," sum average");
printf("%s", str); /* 列印表頭 */
while (p != NULL) /*若不是表尾,則循環列印*/
{
printf("\nNo.%3d%15s", p->number, p->name);
for (i=0; i<m; i++)
{
printf("%7d", p->salary[i]);
}
printf("%9d%9.2f", p->sum, p->average);
p = p->next; /*讓p指向下一個節點*/
j++;
}
printf("\n");
}
STU *AppendNode(STU *head, const int m)
{
STU *p = NULL;
STU *pr = head;
int j;
p = (STU *)malloc(sizeof(STU)); /*為新添加的節點申請內存*/
if (p == NULL) /*若申請內存失敗,則列印錯誤信息,退出程序*/
{
printf("No enough memory to alloc");
exit(0);
}
if (head == NULL) /*若原鏈表為空表,則將新建節點置為首節點*/
{
head = p;
}
else /*若原鏈表為非空,則將新建節點添加到表尾*/
{
/*若未到表尾,則繼續移動指針pr,直到pr指向表尾*/
while (pr->next != NULL)
{
pr = pr->next;
}
pr->next = p; /*將新建節點添加到鏈表的末尾*/
}
pr = p; /*讓pr指向新建節點*/
printf("Input node data......");
printf("\nInput number:");
scanf("%d", &p->number);
printf("Input name:");
scanf("%s", p->name);
for (j=0; j<m; j++)
{
printf("Input salary%d:", j+1);
scanf("%d", p->salary+j);
}
pr->next = NULL; /*將新建節點置為表尾*/
return head; /*返回添加節點後的鏈表的頭節點指針*/
}
STU *ModifyNode(STU *head, int nodeNum, const int m)
{
int j;
STU *newNode;
newNode = SearchNode(head, nodeNum);
if (newNode == NULL)
{
printf("Not found!\n");
}
else
{
printf("Input the new node data:\n");
printf("Input name:");
scanf("%s", newNode->name);
for (j=0; j<m; j++)
{
printf("Input salary%d:", j+1);
scanf("%d", newNode->salary+j);
}
}
return head;
}
STU *DeleteNode(STU *head, int nodeNum)
{
STU *p = head, *pr = head;
if (head == NULL) /*鏈表為空,沒有節點,無法刪除節點*/
{
printf("No Linked Table!\n");
return(head);
}
/*若沒找到節點nodeNum且未到表尾,則繼續找*/
while (nodeNum != p->number && p->next != NULL)
{
pr = p;
p = p->next;
}
if (nodeNum == p->number) /*若找到節點nodeNum,則刪除該節點*/
{
if (p == head) /*若待刪節點為首節點,則讓head指向第2個節點*/
{
head = p->next;
}
else /*若待刪節點非首節點,則將前一節點指針指向當前節點的下一節點*/
{
pr->next = p->next;
}
free(p); /*釋放為已刪除節點分配的內存*/
}
else /*沒有找到待刪除節點*/
{
printf("This Node has not been found!\n");
}
return head; /*返回刪除節點後的鏈表的頭節點指針*/
}
STU *SearchNode(STU *head, int nodeNum)
{
STU *p = head;
int j = 1;
while (p != NULL) /*若不是表尾,則循環*/
{
if (p->number == nodeNum) return p;
p = p->next; /*讓p指向下一個節點*/
j++;
}
return NULL;
}
void DeleteMemory(STU *head)
{
STU *p = head, *pr = NULL;
while (p != NULL) /*若不是表尾,則釋放節點佔用的內存*/
{
pr = p; /*在pr中保存當前節點的指針*/
p = p->next; /*讓p指向下一個節點*/
free(pr); /*釋放pr指向的當前節點佔用的內存*/
}
}
湊合著用吧,一些缺少的功能自己加上去就行了。。。
5. 幫忙下c語言課程設計 統計工資
csdn 是個網站,上面的東西比較牛逼
6. 求C語言課程設計—職工工資統計部分的編程
1:數據結構抄設計
typedef struct member
{
int id ; //key
char name [64];
unsigned int age ;
int salary ;
};
2: 程序結構設計
a) 輸入職工的基本信息
b) 查找(可根據姓名,ID, 年齡, 薪水)
c)統計某一范圍的人數,計算平均工資值,等。
d) 輸出模塊
3)程序結構設計
設計函數 記住模塊化。具體函數原型還是自己動手寫吧。根據自己的使用喜歡。
4)測試和調試
大致思路是這樣,希望對你有所幫助。
7. C++課程設計工資管理系統
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define FILENAME "staff.txt" //數據文件
/////////////////////////////////////////////
struct Staff //職工機構體
{
char CarNumber[10]; //卡號
char Name[10]; //姓名
int Month; //月份
float SPWages; //應發工資
float APWages; //實發工資
float Water; //水費
float Electrical; //電費
float Tax; //稅金
};
////////////////////////////////////////////// 文件操作模塊
FILE *FP; //全局文件指針
FILE * FileOpen(char FileName[]) //文件打開函數
{
FILE *fp;
if((fp=fopen(FileName,"r"))==NULL)
{
fp=fopen(FileName,"w");
cout<<"文件打開失敗重新創建記錄文件";
return fp;
}
fp=fopen(FileName,"r+");
return fp;
}
void FileClose(FILE *fp)
{
if(fclose(fp)==0)
cout<<"安全關閉"<<endl;
else
cout<<"文件關閉失敗"<<endl;
}
////////////////////////////////////////////////
void Increase() //添加職工信息
{
FP=FileOpen(FILENAME);
Staff temp;
cout<<endl;
cout<<"請輸入姓名:";
cin>>temp.Name;
cout<<"請輸入卡號:";
cin>>temp.CarNumber;
cout<<"請輸入月份:";
cin>>temp.Month;
cout<<"請輸入應發工資:";
cin>>temp.SPWages;
cout<<"請輸入水費:";
cin>>temp.Water;
cout<<"請輸入電費:";
cin>>temp.Electrical;
if(temp.SPWages<=800) temp.Tax=0;
if((temp.SPWages>800.0)&&(temp.SPWages<1400.0)) temp.Tax=(temp.SPWages-800)*0.05;
if(temp.SPWages>1400){temp.Tax=(temp.SPWages-1400)*0.1;}
temp.APWages=temp.SPWages-temp.Water-temp.Electrical-temp.Tax;
fwrite(&temp,sizeof(temp),1,FP);
cout<<"信息添加成功,請選擇瀏覽工資信息選項進行查看"<<endl;
FileClose(FP);
}
//////////////////////////////////////////////
void PrintInformation() //瀏覽工資信息
{
FP=FileOpen(FILENAME);
rewind(FP);
Staff temp;
while(fread(&temp,sizeof(Staff),1,FP)==1)
{
cout<<"姓名:"<<temp.Name<<endl;
cout<<"卡號:"<<temp.CarNumber<<endl;
cout<<"月份:"<<temp.Month<<endl;
cout<<"應發工資:"<<temp.SPWages<<endl;
cout<<"水費:"<<temp.Water<<endl;
cout<<"電費:"<<temp.Electrical<<endl;
cout<<"稅金:"<<temp.Tax<<endl;
cout<<"實發工資:"<<temp.APWages<<endl;
cout<<endl;
}
FileClose(FP);
}
//////////////////////////////////////////////////
void Statistics() //統計工資信息
{
Staff temp;
char nametemp[10];
float sum=0;
int monthstart=0,monthover=0;
cout<<"請輸入統計的人員姓名:"<<endl;
cin>>nametemp;
cout<<"請輸入統計時間段的起始月份(如:3)";
cin>>monthstart;
cout<<"請輸入統計時間段的終止月份(如:3)";
cin>>monthover;
FP=FileOpen(FILENAME);
while(fread(&temp,sizeof(Staff),1,FP)==1)
{
if(strcmp(temp.Name,nametemp)==0)
{
if(temp.Month>=monthstart&&temp.Month<=monthover)
{
sum=sum+temp.APWages;
}
}
}
cout<<"職工"<<nametemp<<"從"<<monthstart<<"月至"<<monthover<<"月合計"<<sum<<"元。"<<endl;
}
////////////////////////////////////////////////
void NameSearch()
{
char tempname[10];
Staff temp;
cout<<endl;
cout<<"請輸入要查詢的職工的名稱:";
cin>>tempname;
FP=FileOpen(FILENAME);
while(fread(&temp,sizeof(Staff),1,FP)==1)
{
if(strcmp(temp.Name,tempname))
{
cout<<"姓名:"<<temp.Name<<endl;
cout<<"卡號:"<<temp.CarNumber<<endl;
cout<<"月份:"<<temp.Month<<endl;
cout<<"應發工資:"<<temp.SPWages<<endl;
cout<<"水費:"<<temp.Water<<endl;
cout<<"電費:"<<temp.Electrical<<endl;
cout<<"稅金:"<<temp.Tax<<endl;
cout<<"實發工資:"<<temp.APWages<<endl;
cout<<endl;
}
}
FileClose(FP);
}
int Search()
{
int Choose=0;
while(1)
{
cout<<endl;
cout<<"請選擇查詢方式"<<endl;
cout<<"1、按照卡號查詢"<<endl;
cout<<"2、按照姓名查詢"<<endl;
cout<<"0、返回上級目錄"<<endl;
cout<<"請輸入查詢方式:"<<endl;
cin>>Choose;
switch(Choose)
{
case 1:;break;
case 2:NameSearch();break;
case 0:return 0;break;
}
}
}
//////////////////////////////////////////////
void ShowMenu() //目錄顯示函數
{
int Choose=0;
while(1)
{
cout<<endl;
cout<<"工資信息管理系統"<<endl;
cout<<"1、添加工資信息。"<<endl;
cout<<"2、瀏覽工資信息。"<<endl;
cout<<"3、統計工資信息。"<<endl;
cout<<"4、查詢工資信息。"<<endl;
cout<<"0、退出系統。"<<endl;
cout<<"請輸入服務類型:";
cin>>Choose;
switch(Choose)
{
case 1:Increase();break;
case 2:PrintInformation();break;
case 3:Statistics();break;
case 4:Search();break;
case 0:exit(0);break;
}
}
}
void main()
{
ShowMenu();
}
8. 數據結構課程設計。關於工資的.要C語言編寫的
員工工資表(員工號,姓名,工資,,,,)
1.插入:招聘新員工時,將其加入到系統中。
sql: insert into 員工工資表 values(員工號,,,,,)
2.刪除:某位員工離開時,將其刪除。
sql: delete from 員工工資表 where 員工號 = ?
3.修改:修改每位員工的工資時(包括長工資和減工資兩種
情況)
sql: update 員工工資表 工資 = '新工資' where 員工號 = ?
4.查詢:幫助老闆查詢某位員工的工資。
sql: select 工資 from 員工工資表 where 員工號 = ?
5.統計:統計員工的最高,最低,平均工資。
sql: select max(工資),min(工資),avg(工資) from 員工工資表