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

c語言統計工資

發布時間: 2022-08-07 15:04:19

A. 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;
}
}

B. C語言 計算程序員的收入


#include <stdio.h>

int main()

{

int hour;

int money;

scanf("%d",&hour);

if(hour < 160)

{

money = hour * 10;

}

else

{

money = 10 * 160 + (hour - 160) * 30;

}

printf("%d ",money);

return 0;

}

C. 用C語言編寫計算工人工資怎麼編寫

用C語言編寫計算工人工資怎麼編寫?

某工廠按工人的工時計算工人工資,規則如下:工資按每小時84元計發。若總工時>120小時,超過120小時的部分每小時加發15%;若總工時<60小時,則總工資扣發700元。編寫程序,從鍵盤錄入某工人的工時,程序能計算並輸出該工人的工資。(畫出程序流程圖)

D. 用C語言編寫計算工人工資

#include&amp;lt;stdio.h&amp;gt;
void main()
{
int hour;
int salary;
scanf("%d",hour);
switch(hour/60)
{
case 0:
{
salary=hour*84-700;
break;
}
case 1:
{
salary=hour*84;
break;
}
case 2:
{
salary=120*84+(hour-120)*(84*1.5);
break;
}
default:
printf("工時錯誤!");
}
printf("工資為%d",salary);
}

抱歉,好久沒弄C了,上面隨便寫沒編譯,剛才又弄了一下

#include<stdio.h>
void main()
{
int hour=0;
double salary;
scanf("%d",&hour);
while(hour<0)
{
printf("工時錯誤,重新輸入!");
scanf("%d",&hour);
}
switch(hour/60)
{
case 0:
{
salary=hour*84-700;
break;
}
case 1:
{
salary=hour*84;
break;
}
case 2:
{
salary=120*84+(hour-120)*(84*1.15);
break;
}
}
printf("工資為%f",salary);
}

E. 求C語言課程設計—職工工資統計部分的編程

#include<stdio.h>
#include<string.h>
#define N 5 /*假設有5名員工*/
void main()
{ char name[20],sex,e[15]; double salary_low,salary_high,sum=0; int i,k; char b;
/*用於查找系統的姓名、性別、年齡、教育程度、最低工資、最高工資、工資總計*/
struct salary
{ double basic;
double allowance;
};
/*工資結構體定義:工資=基本工資和獎金 */
struct fellow /*定義員工結構體*/
{ char name[20]; /*姓名*/
char sex; /*性別*/
char birth_day[9]; /*生日*/
char ID[20]; /*工號*/
char e[15]; /*教育程度*/
char indate_time[9]; /*入廠時間*/
struct salary s; /*工資*/
}fw[N]; /* 結構體定義完畢,是一個結構體數組*/
for(i=0;i<N;i++) /*輸入提示和過程*/
{ printf("\nEnter No%d name\n",i+1) ; /*提示輸入第n個員工的姓名*/
scanf("%s",fw[i].name);
printf("\n Male(M) or Female(F)\n"); /*提示出入性別*/
do fw[i].sex=getch();
while((fw[i].sex!='F')&&(fw[i].sex!='M')); /*do-while 循環,保證輸入的字元為M或F*/
printf("\nEnter His/Her birth day\n");
scanf("%s",fw[i].birth_day); /* 輸入生日 ,如19870101*/
printf("\nEnter ID\n");
scanf("%s",fw[i].ID); /*工號*/
printf("\nEnter ecation\n");
scanf("%s",fw[i].e); /*教育程度,如大學為High,碩士為Master*/
printf("\nIndate time?\n");
scanf("%s",fw[i].indate_time); /*入廠時間,如20010101*/
printf("\nEnter salary\n");
scanf("%f,%f",&(fw[i].salary.basic),&(fw[i].salary.allowance)); /*工資,基本工資和獎金*/
printf("\nNow the next\n");
}
printf("\nfind in name(1),find in salary(2),find in sex(3),find in e(4),find the sum(5)\n");
scanf("%d",&k);
if(k==1)
{while(1)
{ printf("\nTo exit enter the kay b\n");
scanf("%c",&b);
if(b=='b') break;
else
{ printf("\nEnter a name\n");
scanf("%s",name);
for(i=0;i<N;i++)
if(strcmp(name,fw[i].name)==0)
printf("%s;%c,%s,%s,%s,%s",fw[i].name,fw[i].sex,fw[i].ID,fw[i].indate_time,fw[i].salary.basic, fw[i]. salary[i].allowance);
}
}
}
else if(k==2)
{while(1)
{ printf("\nTo exit enter the kay b\n");
scanf("%c",&b);
if(b=='b') break;
else
{ printf("\nEnter the salary range\n");
scanf("%f,%f",&salary_low,&salary_high);
for(i=0;i<N;i++)
if(((fw[i].salary.basic+fw[i].salary.allowance)>=salary_low)&&((fw[i].salary.basic+fw[i].salary.allowance)<=salary_high))

printf("%s;%c,%s,%s,%s,%s",fw[i].name,fw[i].sex,fw[i].ID,fw[i].indate_time,fw[i].salary.basic, fw[i]. salary[i].allowance);
}
}
}
else if(k==3)
{while(1)
{ printf("\nTo exit enter the kay b\n");
scanf("%c",&b);
if(b=='b') break;
else
do sex=getch();
while((sex!='M')&&(sex!='F'))
for(i=0;i<N;i++)
if(fw[i].sex==sex)

printf("%s;%c,%s,%s,%s,%s",fw[i].name,fw[i].sex,fw[i].ID,fw[i].indate_time,fw[i].salary.basic, fw[i]. salary[i].allowance);
}
}
}
else if(k==4)
{while(1)
{ printf("\nTo exit enter the kay b\n");
scanf("%c",&b);
if(b=='b') break;
else
printf("\nEnter ecation\n")
scanf("%s",e);
for(i=0;i<N;i++)
if(strcmp(e,fw[i].e)==0)
printf("%s;%c,%s,%s,%s,%s",fw[i].name,fw[i].sex,fw[i].ID,fw[i].indate_time,fw[i].salary.basic, fw[i]. salary[i].allowance);
}
}
}
else
{ for(i=0;i<N;i++)
sum+=fw[i].salary.basic+fw[i].salary.allowance;
printf("%f",sum);
}
}
/*以五種方式進行統計查詢,你可以把printf的內容再豐富一點,while(1)保證這個是一個死循環,並且用輸入鍵盤上b鍵的方法退出循環,可以保證每一次運行時可以按照不同的方法進行統計*/
我只是這樣寫了一下,能否運行,還要自己去試試,因為在寫的過程中難免把一些字幕寫錯,這么多行,就不一一檢查了!

F. 用C語言編寫一個計算薪水的程序

/*工資計算程序*/
#include <stdio.h>

main()
{
float originWage; /*應發工資*/
float realWage; /*實發工資*/
float tax; /*所繳稅款*/
int i,hour,amount,money;

printf("請選擇工資種類:\n1.計時工資\n2.計件工資\n3.固定月工資\n");
scanf("%d",&i);
switch(i)
{
case 1:{
printf("請輸入工作時間(單位:小時)\n");
scanf("%d",&hour);
printf("請輸入單位時間的薪水(單位:元)\n");
scanf("%f",&money);
originWage=money*hour;
}
break;
case 2:{
printf("請輸入生產產品數量(單位:件)\n");
scanf("%d",&amount);
printf("請輸入生產一件產品的薪水(單位:元)\n");
scanf("%f",&money);
originWage=money*amount;
}
break;
case 3: printf("請輸入你的固定工資\n");
scanf("%f",&originWage);
break;
default:printf("輸入錯誤!\n");
return 0;
}

if(originWage<0)
{
printf("數據錯誤!\n");
return 0;
}
if(originWage<2000)
tax=0;
else if(originWage>2000&&originWage<=2500)
tax=(originWage-2000)*0.05;
else if(originWage>2500&&originWage<=4000)
tax=(originWage-2500)*0.1+500*0.05;
else
tax=(originWage-4000)*0.15+1500*0.1+500*0.05;
printf("應發工資: %f\n",originWage);
printf("所繳稅款: %f\n",tax);
printf("實發工資: %f\n",originWage-tax);
return 0;
}

G. C語言計算工資的代碼

源代碼中,你的if語句裡面兩個表達式是用逗號分開的,這樣並不能滿足兩個條件都滿足的要求
現修改代碼如下,

#include<stdio.h>
intmain()
{
inty,t;
doublem;
scanf("%d%d",&y,&t);
if(y<5&&t<=40)//使用&&表示要求兩個條件都滿足
printf("%.2f",m=t*30);
elseif(y<5&&t>40)
printf("%.2f",m=40*30+(t-40)*30*1.5);
elseif(y>=5&&t<=40)
printf("%.2f",m=t*50);
else
printf("%.2f",m=40*50+(t-40)*50*1.5);
}

H. 用C語言怎樣算工資

#include "stdio.h"

main()
{ int i,j,m,s=0;
scanf("%d",&j);
for(m=0;m<j;m++)
{
scanf("%d",&i);
if(i==0)
{
break;
}
if(i>=100)
{
s=s+i/100;
i=i%100;
}
if(i>=50)
{
s=s+i/50;
i=i%50;
}
if(i>=10)
{
s=s+i/10;
i=i%10;
}
if(1>=5)
{
s=s+i/5;
i=i%5;
}
if(i>=2)
{
s=s+i/2;
i=i%2;
}
if(i>=1)
{
s++;
}

}
printf("%d",s);
getch();
}

I. c語言程序設計工資統計

去網上找,應該很多的

J. C語言,模擬工資計算器,計算一個銷售人員的月工資的數量(月工資=基本工資+提成,提成=商品數*1.5)。

樓主的代碼存在兩個明顯問題:

1、數值類型掌握不好

計算工資時很可能出現小數,而樓主聲明變數時完全採用了int型,先不說是否邏輯正確。int型的變數直接與後面代碼沖突。

有兩個問題:

1.1:

scanf()中樓主在括弧內寫的是%ld,%ld等待的輸入類型是long int,而樓主聲明的是

int。

1.2:

iCommission=(iSales*1.5);

iSales為整形,1.5為浮點型,iSales*1.5的結果會隱式轉換為浮點型,而iCommission為

整型int。在賦值時會產生錯誤。


需要補充知識點:參數類型的定義和轉換。請查閱任何一本C語言教材。


2、scanf()函數掌握不好

這也是樓主最關心的問題,scanf()中 、空格和製表符都是是空白符。空白字元會使scanf()函數在讀操作中略去輸入中的一個或多個空白字元。只有輸入一個非空白符的時候才能終止scanf的輸入。另外在上一點提出的參數類型也需要格外注意。

需要補充知識點:scanf()函數的使用方法。請查閱相關文檔。

http://ke..com/link?url=_


再啰嗦幾句:puts()函數用來向標准輸出設備(屏幕)寫字元串並換行,其調用方式為,puts(s);其中s為字元串字元(字元串數組名或字元串指針)。雖然樓主的使用方式也正確,但是最好也查閱一下更標準的使用方法。

http://ke..com/link?url=MVSb8tWqQPMLWzKve4IpvgamU_2P--Rf63HG3AeUc3Cb7XRp53K35Bs9IQ_8IA3Y2lqRaZ0zCTenPgzg8RLSYK


下面貼出我修改後的代碼:

#include<stdio.h>

intmain()
{
doubleiSalary,iBasic,iCommission,iSales;

printf("Pleaseenterthebasicpayment:");
scanf("%lf",&iBasic);

printf("Pleaseenterthesales:");
scanf("%lf",&iSales);

iCommission=(iSales*1.5);
printf("提成工資為:%lf ",iCommission);

iSalary=(iBasic+iCommission);
printf("月工資數量:");
printf("%lf",iSalary);
return0;
}

請樓主注意其中變數類型的變化以及輸入輸出中%後面的變化。


小提示:編程過程中細節真的很重要啊,還有,以後遇到問題,試著分解成一個個小問題分析,再查找相關的解決辦法,學會善用搜索引擎。比如樓主在輸入時遇到了問題,就要想是不是scanf出問題了呀,進而去搜索它的正確用法。這才是真正的解決問題。

熱點內容
天津智慧網關伺服器雲伺服器 發布:2024-04-27 03:56:51 瀏覽:422
移門製作下料尺寸演算法 發布:2024-04-27 03:15:02 瀏覽:641
c語言5常量 發布:2024-04-27 02:38:49 瀏覽:991
源碼怎麼搭建 發布:2024-04-27 02:33:44 瀏覽:97
java獲取參數 發布:2024-04-27 02:22:21 瀏覽:501
unixlinuxwindows 發布:2024-04-27 02:10:55 瀏覽:445
nginx禁止ip訪問網站 發布:2024-04-27 02:05:43 瀏覽:845
webrtc伺服器搭建哪家價格低 發布:2024-04-27 01:30:08 瀏覽:141
oracle資料庫無法啟動 發布:2024-04-27 01:29:20 瀏覽:613
倪萍超級訪問 發布:2024-04-27 01:23:29 瀏覽:705