⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 text2.cpp

📁 职工工资管理,适合用于毕业设计,工资企业,和公司的员工工资管理
💻 CPP
字号:
#include <iostream> 
//#include <string> 
#include <iomanip> 
#include <cstdlib> 
#include <fstream> 
#include <vector> 

using namespace std ; 

const int fr = 10 ; 
int a[fr] ; 
//vector<int> a ; //单独记录职工号 
int Count=0 ; //计数器 计算一共有多少个员工 

class Person 
{ 
public: 
bool check( int , int ) ; //检查职工号是否重复和查询职工号 
void get() ; //得到数据 
void put( ) ; //向显示屏输出 
void put_txt(ofstream&); //向文本输出 
void change_pay () ; //换算税金和应发工资 
void come( ifstream& ) ; //从文本中 读取 
private: 
int number ; //职工号 
char name[10] ; //姓名 
char sex ; //性别 
int pay ; //应发工资 
double pay_out ; //税金 
double pay_true ; //实发工资 
}; 

void opening ( ifstream& , ofstream& ); 
void closing ( ifstream& , ofstream& ); 
int show_menu(); 

int main() 
{ 
ifstream in ; 
ofstream out ; 

opening ( in , out ) ; 

int choose1 ; //选择主菜单 
char choose2 ; //选择是否退出 
// vector<Person> person ; 
Person person[100] ; 

while(!in.eof()) 
{ 
char b ; 

in.get(b) ; 
if(b==':') 
{ 
in.putback(b) ; 
person[Count].come(in) ; 
Count++ ; 
} 
} 


do 
{ 
system ("cls") ; 
choose1=show_menu() ; 
system ("cls") ; 
switch(choose1) 
{ 
case 1: 
{ 
for(int i=0;i<80;i++) 
cout << "#" ; 
cout << setw(20) << "职工基本信息和应发工资的录入\n" ; 
for(int j=0;j<80;j++) 
cout << "#" ; 
do 
{ 
//a.push_back(0) ; 
person[Count].get() ; 
//person.push_back(0) ; 
Count++ ; 
cout << "\n是否继续录入?(y or n):" ; 
cin >> choose2 ; 
}while(choose2=='y'); 
} 
break ; 
case 2: 
{ 
for(int i=0;i<80;i++) 
cout << "#" ; 
cout << setw(20) << "职工工资信息浏览\n" ; 
for(int j=0;j<80;j++) 
cout << "#" ; 
cout << endl ; 

for (int m=0;m<Count;m++) 
person[m].put() ; 
cout << endl ; 
} 
break ; 
case 3: 
{ 
int p=0 ; 
for(int i=0;i<80;i++) 
cout << "#" ; 
cout << setw(20) << "查询应发工资\n" ; 
for(int j=0;j<80;j++) 
cout << "#" ; 

int number ; 
cout << "\n输入你要查询的职工号:" ; 
cin >> number ; 
for (int m=0;m<Count;m++) 
if( person[m].check(number,2) ) 
{ 
cout << "\n找到了!\n" ; 
person[m].put () ; 
p=1 ; 
break; 
} 
if(p==0) 
cout << "\n没有 这个工号!\n" ; 
} 
break ; 
default: 
cout << "\n输入错误!" ; 
} 
cout << "\n是否继续察看主菜单?(y or n):" ; 
cin >> choose2 ; 
}while(choose2=='y') ; 
for (int i=0;i<=Count;i++) 
person[i].put_txt ( out ) ; 


closing ( in , out ) ; 

return 0 ; 
} 

void opening ( ifstream& ins , ofstream& outs ) 
{ 
ins.open("c:\\tc\\tc\\s a l a r y.txt" ) ; 
if (ins.fail()) 
{ 
cout << "wo can not open salary.txt!" ; 
exit (1); 
} 
outs.open("c:\\tc\\tc\\s a l a r y.txt" ) ; 
if (outs.fail()) 
{ 
cout << "wo con not opening s a l a r y.txt!" ; 
exit (1); 
} 
} 
void closing ( ifstream& ins , ofstream& outs ) 
{ 
ins.close(); 
outs.close(); 
} 
int show_menu () 
{ 
int word ; 
for(int i=0;i<80;i++) 
cout << "#" ; 

cout << "1. 职工基本信息和应发工资的录入; \n" ; 
cout << "2.职工工资信息浏览; \n" ; 
cout << "3.查询应发工资; \n" ; 
for(int j=0;j<80;j++) 
cout << "#" ; 
cout << "请你输入选择的项目的代码(1,2...) :" ; 

cin >> word ; 

return word ; 
} 
void Person::change_pay() 
{ 
if(pay<1000) 
{ 
pay_out = 0 ; 
pay_true = pay ; 
} 
if( (pay<4999) && (pay>=1000) ) 
{ 
pay_out = pay*0.05 ; 
pay_true = pay - pay_out ; 
} 
if(pay>=5000) 
{ 
pay_out = pay*0.1 ; 
pay_true = pay - pay_out ; 
} 
} 
void Person::come(ifstream& in) 
{ 
char b ; 

in.get(b) ; 
if(b==':') 
in >> number ; 
a[Count]=number ; 

do 
{ 
in.get(b) ; 
}while(b!=':') ; 
if(b==':') 
in >> name ; 
do 
{ 
in.get(b) ; 
}while(b!=':') ; 
in >> pay ; 
do 
{ 
in.get(b) ; 
}while(b!=':') ; 
in >> pay_out ; 
do 
{ 
in.get(b) ; 
}while(b!=':') ; 
in >> pay_true; 


} 
void Person::get() 
{ 
do 
{ 
cout << "\n职工号:" ; 
cin >> number ; 
a[Count]=number ; 
if( check(number,1) ) 
break ; 
cout << "\n职工号有重复,请重新输入!" ; 
}while(1); 
cout << "\n姓名:" ; 
cin >> name; 
cout << "\n应发工资:" ; 
cin >> pay ; 
} 
void Person::put() 
{ 
change_pay() ; 

for(int i=0;i<80;i++) 
cout << "#" ; 

cout << "\n职工号:" << number 
<< "\n姓名:" << name 
<< "\n应发工资:" << pay 
<< "\n税金:" << pay_out 
<< "\n实发工资:" << pay_true ; 
cout << endl ; 
} 
void Person::put_txt( ofstream& out ) 
{ 
for(int i=0;i<80;i++) 
cout << "#" ; 

out << "\n职工号:" << number 
<< "\n姓名:" << name 
<< "\n应发工资:" << pay 
<< "\n税金:" << pay_out 
<< "\n实发工资:" << pay_true ; 
} 
bool Person::check( int b , int choose) 
{ 
switch(choose) 
{ 
case 1: 
{ 
for(int i=0;i<Count;i++) 
if(b == a[i]) 
return (b!=a[i]) ; 
return 1 ; 
} 
case 2: 
return (b==number) ; 
default: 
cout << "\n系统错误!" ; 
exit(1) ; 
} 
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -