资源描述
c++课程设计-教师工资管理系统-源代码
34
2020年4月19日
资料内容仅供参考,如有不当或者侵权,请联系本人改正或者删除。
教师工资管理系统源代码
本文件包括四个文件, 下载后请自行分开, 每个文件由////分开, ////后面即是要保存的文件名。
本系统, 包括添加, 修改, 删除, 查询, 显示。教师信息保存到文件。有帮助系统, 更改字体和背景颜色功能。
还有, 本程序只需编译连接main.Cpp 不要把另外三个文件添加到工程, 否则会出现连接出错! ! ! ! ! ( 可是四个文件都要放在同一目录下, 因为都要用的。会自动加在External dependencies里面)
////main.cpp
#include"Chen.cpp"
#include"Liao.cpp"
#include<iostream>
using namespace std;
Function t[100];
int count;
Liao abc1;
Chen abc2;
void colorme();
void help();
void menu() //菜单
{
char c[60]="\t\t\t\t 欢 迎 使 用 ! ";
char b[100]="\t Welcome to use the teachers' salary management system !";
system("color fd");
cout<<"\n\n\n\n"<<endl;
cout<<"\t\t\t"<<" 教师工资管理系统\n\n\n"<<endl;
cout<<"\t\t\t 制作人: 陈 伟 廖亚斌"<<endl<<endl;
cout<<"\t\t\t学号: 08408 10 08408 09\n\n"<<endl;
cout<<"\t\t\t\t 12月\n\n\n\t\t\t"<<endl;
for(int i=0;i<=20;i++){
cout<<c[i];
_sleep(40); //延时
}
cout<<"\n\n";
for(i=0;i<=58;i++){
cout<<b[i];
_sleep(30); //延时
}
_sleep(1000);
system("cls");
while(1)
{
fflush(stdin); //清除输入流缓冲区
system("cls");
cout<<"\n\n\n\n"<<endl;
cout<<"\t\t\t\t教师工资管理系统\n\n\n";
cout<<"\t\t\t1.添加教师信息 2.修改教师信息"<<endl<<endl;
cout<<"\t\t\t3.删除教师信息 4.查询教师信息"<<endl<<endl;
cout<<"\t\t\t5.显示教师信息 6.系统帮助信息"<<endl<<endl;
cout<<"\t\t\t9.更改皮肤颜色 0.退出信息系统\n\n\n"<<endl;
cout<<"\t\t\t请选择: ";
char a[10];
gets(a);
switch(a[0])
{
case '1':abc1.add();break;
case '2':abc1.alter();break;
case '3':abc2.del();break;
case '4':abc2.inquiry();break;
case '5':abc2.display();break;
case '6':help();break;
case '9':colorme();break;
case '0':
cout<<"\n\t\t\t谢谢使用! \n\n\t\t\t";
exit(0);break;
default:
cout<<"\n\n\t\t\t输入错误, 请重新选择!\n\n\t\t\t";
_sleep(800);
break;
}
}
}
void colorme()
{
system("cls");
char a[10];
cout<<"\n\n\n\n\t\t\t1.黑白\t\t2.黑绿";
cout<<"\n\n\t\t\t3.黑蓝\t\t4.黑红";
cout<<"\n\n\t\t\t5.黑紫\t\t6.黑黄";
cout<<"\n\n\t\t\t7.白粉( 默认) \n\n\t\t\t";
gets(a);
switch(a[0])
{
case '1':{
system("color 07");
break;
}
case '2':{
system("color 0a");
break;
}
case '3':{
system("color 0b");
break;
}
case '4':{
system("color 0c");
break;
}
case '5':{
system("color 0d");
break;
}
case '6':{
system("color 0e");
break;
}
case '7':{
system("color fd");
break;
}
default:break;
}
}
void help()
{
system("cls");
cout<<"\n\n\n\t\t\t 欢迎使用教师工资管理系统";
cout<<"\n\n\t\t\t本系统由陈伟, 廖亚斌合作编写";
cout<<"\n\n\t本系统能够存储教师的教师号, 姓名, 性别, 职称, 基本工资, 奖金, 保险, 其它杂费, 实际工资。其中实际工资=基本工资+奖金-保险-其它杂费。";
cout<<"\n\n\t本系统能够添加, 修改, 删除, 显示教师工资信息; 还有皮肤颜色修改功能。教师工资都保存在磁盘的Infor.dat文件中。";
system("pause");
}
int main()
{
menu();
return 0;
}
////Function.cpp
#ifndef Teacher
#define Teacher
#include<fstream>
#include<string>
#include<iomanip>
#include<iostream>
using namespace std;
class Function
{
public:
string num; //教师号
string name; //姓名
string sex; //性别
string title; //职称
double base_pay; //基本工资
double reward; //奖金
double insure; //保险
double other; //其它杂费
double reality; //实际工资
//实际工资=基本工资+奖金-保险-其它
int c_num(string i); //按教师号查询
int c_name(string i,int b); //按姓名查询
void c_out(int i); //显示单条教师信息
void c_char(); //显示汉字教师信息提示
void out_file(); //输出到文件
void get_file(); //从文件输入
};
extern Function t[100];
extern int count;
void Function::c_char() //输出表格头
{
cout<<"\n ------------------------------------------------------------------------------ ";
cout<<"| 教师号 | 姓名 | 性别 | 职称 |基本工资 | 奖金 | 保险 | 其它 | 实际工资 |";
cout<<" ------------------------------------------------------------------------------ ";
}
int Function::c_name(string i,int b)
{
string temp;
int tmp=-1;
int c=b;get_file();
temp=i;
for(int a=0;a<count;a++){
if(temp==t[a].name){
tmp=a;
if(c!=0){
c_out(a);
}
}
}
return tmp;
}
int Function::c_num(string i)
{
// system("cls");
string temp;
int tmp=-1;
get_file();
if(count==0){
// cout<<"\n\t\t\t还没有教师信息! "<<endl;
}
else{
temp=i;
for(int i=0;i<count;i++)
{
if(temp==t[i].num){
tmp=i;
break;
}
}
}
return tmp;
}
//教师号 姓名 性别 职称 基本工资 奖金 保险 其它 实际工资
void Function::c_out(int i) //输出教师信息
{
cout<<"| "<<setw(11)<<t[i].num<<"|"<<setw(7)<<t[i].name<<" |"<<setw(5)<<t[i].sex<<" |"<<setw(6)<<t[i].title<<"|"<<setw(9)<<t[i].base_pay<<"|"<<setw(6)<<t[i].reward<<"|"<<setw(6)<<t[i].insure<<"|"<<setw(6)<<t[i].other<<"|"<<setw(9)<<t[i].reality<<" |";
cout<<" ------------------------------------------------------------------------------ ";
}
void Function::get_file() //文件读出
{
// system("cls");
ifstream in;
in.open("Infor.dat",ios::in);
if(!in){
cerr<<" ";
return;
}
for(int i=0;!in.eof();i++)
{
in>>t[i].num>>t[i].name>>t[i].sex>>t[i].title>>t[i].base_pay>>t[i].reward>>t[i].insure>>t[i].other>>t[i].reality;
}
in.close();
count=i;
if(t[0].num=="\0")
count=0;
//cout<<"\t\t\t信息读取完毕! 一共"<<count<<"条"<<endl;
}
void Function::out_file() //文件保存
{
//system("cls");
ofstream out;
out.open("Infor.dat",ios::out);
for(int i=0;i<=count;i++)
{
if(i!=0){
out<<endl;
}
out<<t[i].num<<' '<<t[i].name<<' '<<t[i].sex<<' '<<t[i].title<<' '<<t[i].base_pay<<' '<<t[i].reward<<' '<<t[i].insure<<' '<<t[i].other<<' '<<t[i].reality;
}
out.close();
//cout<<"\t\t\t信息保存完毕! 一共"<<i<<"条"<<endl;
}
#endif
////Liao.cpp
#include"Function.cpp"
using namespace std;
//#ifndef _Liao
//#define _Liao
class Liao:public Function
{
public:
void add();
void alter();
};
//#endif
void Liao::add()
{
system("cls");
string temp;
int tmp,i;
cout<<endl<<"\t\t\t请输入教师号: ";
fflush(stdin);
cin>>temp;
tmp=c_num(temp);
if(tmp!=-1){
cout<<"\n\n\t\t\t已存在该教师信息! 请重新输入! \n\n\n\t\t\t";
_sleep(1000);
return;
}
i=count;
t[i].num=temp;
cout<<endl<<"\t\t\t请输入姓名: ";
cin>>t[i].name;
cout<<endl<<"\t\t\t请输入性别: ";
cin>>t[i].sex;
cout<<endl<<"\t\t\t请输入职称: ";
cin>>t[i].title;
cout<<endl<<"\t\t\t请输入基本工资: ";
cin>>t[i].base_pay;
cout<<endl<<"\t\t\t请输入奖金: ";
cin>>t[i].reward;
cout<<endl<<"\t\t\t请输入保险: ";
cin>>t[i].insure;
cout<<endl<<"\t\t\t请输入其它杂费: ";
cin>>t[i].other;
t[i].reality=t[i].base_pay+t[i].reward-t[i].insure-t[i].other;
out_file();
}
void Liao::alter() //修改
{
string temp;
system("cls");
int tmp=c_num("test");
if(count==0){
cout<<"\n\n\t\t\t还没有教师信息! 请先输入! ";
_sleep(1000);
return;
}
else{
cout<<"\n\n\t\t\t请输入教师号: ";
fflush(stdin);
cin>>temp;
tmp=c_num(temp);
if(tmp==-1){
cout<<"\n\n\t\t\t没有找到该教师信息! \n\n\n\t\t\t";
// _sleep(1000);
}
else{
c_char();
c_out(tmp);
cout<<"\n\n\t\t\t1.修改编号 2.修改姓名";
cout<<"\n\n\t\t\t3.修改性别 4.修改职称";
cout<<"\n\n\t\t\t5.修改工资 6.修改奖金";
cout<<"\n\n\t\t\t7.修改保险 8.修改杂费";
cout<<"\n\n\t\t\t0.取消修改";
char a[10];
fflush(stdin);
gets(a);
switch(a[0])
{
case '1':{
while(1){
be:
cout<<"\n\n\t\t\t请输入修改后的教师号: ";
cin>>temp;
for(int i=0;i<count;i++)
{
if(temp==t[i].num){
cout<<"\n\n\t\t\t已有相同教师号信息存在! \n";
goto be;
}
}
t[tmp].num=temp;
break;
}
break;
}
case '2':{
cout<<"\n\n\t\t\t请输入修改后的姓名: ";
cin>>t[tmp].name;
break;
}
case '3':{
cout<<"\n\n\t\t\t请输入修改后的性别:";
cin>>t[tmp].sex;
break;
}
case '4':{
cout<<"\n\n\t\t\t请输入修改后的职称:";
cin>>t[tmp].title;
break;
}
case '5':{
cout<<"\n\n\t\t\t请输入修改后的基本工资:";
cin>>t[tmp].base_pay;
break;
}
case '6':{
cout<<"\n\n\t\t\t请输入修改后的奖金:";
cin>>t[tmp].reward;
break;
}
case '7':{
cout<<"\n\n\t\t\t请输入修改后的保险:";
cin>>t[tmp].insure;
break;
}
case '8':{
cout<<"\n\n\t\t\t请输入修改后的其它杂费:";
cin>>t[tmp].other;
break;
}
case '0':{
break;
}
}
t[tmp].reality=t[tmp].base_pay+t[tmp].reward-t[tmp].insure-t[tmp].other;
count--;
out_file();
}
}
_sleep(1000);
}
////Chen.cpp
#include"Function.cpp"
using namespace std;
extern Function t[100];
extern int count;
//#ifndef _Chen
//#define _Chen
class Chen:public Function
{
public:
void del();
void display();
void inquiry();
void statistics();
};
//#endif
void Chen::del()
{
string temp;
system("cls");
int tmp=c_num("test");
if(count==0){
cout<<" \n\n\t\t\t还没有教师信息! 请先输入! ";
_sleep(1000);
return;
}
else{
cout<<"\n\n\t\t\t请输入教师号: ";
fflush(stdin);
cin>>temp;
tmp=c_num(temp);
if(tmp==-1){
cout<<"\n\n\t\t\t没有找到该教师信息! ";
_sleep(1000);
}
else{
c_char();
c_out(tmp);
cout<<"\n\n\t\t\t确定删除此教师信息? ( 确定按 Y) ";
char a[10];
fflush(stdin);
gets(a);
switch(a[0])
{
case 'Y':case 'y':{
for(int i=tmp;i<count;i++){
t[i]=t[i+1];
}
count-=2;
out_file();
cout<<"\n\n\t\t\t删除成功! ";
break;
}
default : cout<<"\n\n\t\t\t没有删除! ";break;
}
}
}
_sleep(1000);
}
void Chen::display()
{
system("cls");
get_file();
if(count==0){
cout<<"\n\t\t\t还没有教师信息! 请先输入! "<<endl;
_sleep(1000);
}
else{
c_char();
for(int i=0;i<count;i++)
{
c_out(i);
}
statistics();
cout<<"\n\n\t\t\t";
system("pause");
}
}
void Chen::inquiry()
{
int i;
string temp;
system("cls");
i=c_num("test");
if(count==0){
cout<<"\n\n\t\t\t还没有教师信息! 请先输入! ";
_sleep(1000);
return;
}
while(1)
{
system("cls");
cout<<"\n\n\n\n\t\t1.按教师号查询 2.按姓名查找 0.返回菜单"<<"\n\n\t\t\t";
char a[10];
fflush(stdin);
gets(a);
switch(a[0])
{
case '1':{
cout<<"\n\n\t\t\t请输入教师号: ";
fflush(stdin);
cin>>temp;
i=c_num(temp);
if(i==-1){
cout<<"\n\n\t\t\t没有找到该教师信息! ";
_sleep(1000);
}
else{
system("cls");
c_char();
c_out(i);
cout<<"\n\n\t\t\t";
system("pause");
}
break;
}
case '2':{
int tmp=0;
cout<<"\n\n\n\t\t\t请输入教师姓名: ";
cin>>temp;
//get_file();
system("cls");
tmp=c_name(temp,0);
if(tmp==-1){
cout<<"\n\n\t\t\t没有找到教师信息! ";
_sleep(1000);
break;
}
else{
c_char();
tmp=c_name(temp,1);
cout<<"\n\n\t\t\t";
system("pause");;
break;
}
}
case '0':return;break;
default:
cout<<"\n\n\t\t\t输入错误, 请重新选择!\n\n\t\t\t";
_sleep(1000);
break;
}
}
}
void Chen::statistics()
{
double a=0,b=0,c=0,d=0,e=0,f=0;
for(int i=0;i<count;i++){
a=a+t[i].base_pay;
b=b+t[i].reward;
c=c+t[i].insure;
d=d+t[i].other;
e=e+t[i].reality;
}
f=e/count;
cout<<"\n\n\t\t\t\t数据统计: ";
cout<<"\n\n\t 一共有"<<setw(4)<<count<<"位教师信息";
cout<<"\n\t 基本工资和为: "<<setw(8)<<a<<"\t奖金总和为: "<<setw(8)<<b;
cout<<"\n\t 保险总和为: "<<setw(8)<<c<<" \t其它总和为: "<<setw(8)<<d;
cout<<"\n\t 实际工资和为: "<<setw(8)<<e<<"\t平均工资为: "<<setw(8)<<f;
}
展开阅读全文