1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
| #include <iostream> #include <conio.h> #include <fstream> #include <string> using namespace std; class company{ //建立一个类 public: int num; string name; int basicwage; //基础工资 int postwage; //岗位工资 int bonus; //奖金 int salary; //应发工资 int funds; //公积金 float deduthetax; //税收 float thp; //实发工资 company(){};//默认构造函数 company(int n,string na,int ba,int po,int bo,int sa,int f,float de,float th):num(n),name(na),basicwage(ba),postwage(po),bonus(bo),salary(sa),funds(f),deduthetax(de),thp(th){} void setdata(); void display(); }; //逐个字符验证密码 int cmp(char *g,char *b){ int k; for(k=0;k<6;k++){ if(g[k]!=b[k]) break; } if(k==6) return 1; } //密码验证 int mmyz() { int i,j; int z=0; char g[6],b[]={"123456"};//设置初始密码 cout<<"请输入系统的6位初始密码"<<endl; for(i=0;i<3;i++) { for(j=0;j<6;j++) { g[j]=getch(); cout<<"*"; } if(cmp(g,b)==1) //调用密码比较函数 { cout<<"密码正确"<<endl; cout<<"成功进入系统"<<endl; break; } else { cout<<endl<<"密码错误,请重新输入"<<endl; z++; } if(z==3) { cout<<"禁止登陆"<<endl; break; } } return(z); } //输入函数 void company::setdata(){ cin>>num; cin>>name; cin>>basicwage; cin>>postwage; cin>>bonus; cin>>salary; cin>>funds; cin>>deduthetax; cin>>thp; } //输出函数 void company::display(){ cout<<"工号:"<<num<<endl; cout<<"姓名:"<<name<<endl; cout<<"基本工资:"<<basicwage<<endl; cout<<"岗位工资:"<<postwage<<endl; cout<<"奖金:"<<bonus<<endl; cout<<"应发工资:"<<salary<<endl; cout<<"公积金:"<<funds<<endl; cout<<"税收:"<<deduthetax<<endl; cout<<"实发工资:"<<thp<<endl; } //打印菜单 void menu(){ cout<<"|--------------------|"<<endl; cout<<"|-------1.添加-------|"<<endl; cout<<"|-------2.修改-------|"<<endl; cout<<"|-------3.删除-------|"<<endl; cout<<"|-------4.统计-------|"<<endl; cout<<"|-------5.查询-------|"<<endl; cout<<"|-------6.排序-------|"<<endl; cout<<"|-------7.输出-------|"<<endl; cout<<"|-------8.菜单-------|"<<endl; cout<<"|-------9.写入-------|"<<endl; cout<<"|-------0.退出-------|"<<endl; cout<<"|--------------------|"<<endl; } //添加函数 void add(company *stu,int &a){ int b,i; cout<<"请输入插入个数"<<endl; cin>>b; cout<<"输入插入数据:"<<endl; for(i=a;i<a+b;i++){ stu[i].setdata(); } a=a+b; } //修改函数 void change(company *stu,int a){ int c,i; cout<<"输入要修改的员工编号"<<endl; cin>>c; for(i=0;i<a;i++){ if(stu[i].num==c){ break; } } if(i==a){ cout<<"输入的员工编号无效"<<endl; } for(i=0;i<a;i++){ if(stu[i].num==c){ cout<<"输入要修改后员工数据"<<endl; stu[i].setdata(); } } } //删除函数 void delet(company *stu,int &a){ int d,i; cout<<"输入要删除的员工编号"<<endl; cin>>d; for(i=0;i<a;i++){ if(stu[i].num==d){ break; } } if(i==a){ cout<<"输入的员工编号无效"<<endl; } for(i=0;i<a;i++){ if(stu[i].num==d){ for(;i<a;i++){ stu[i]=stu[i+1]; } a=a-1; } } } //统计函数 void sum(company *stu,int a){ int i; int e=0; //员工总工资 for(i=0;i<a;i++){ e=e+stu[i].thp; } cout<<"员工总工资为:" <<e<<endl; } //查找函数 void search(company *stu,int a){ int f,i; cout<<"输入要查询的员工编号"<<endl; cin>>f; for(i=0;i<a;i++){ if(stu[i].num==f){ break; } } if(i==a){ cout<<"输入的员工编号无效"<<endl; } for(i=0;i<a;i++){ if(stu[i].num==f){ stu[i].display(); } } } //排序函数 void sort(company *stu,int a){ int i,j; company tmp; for(i=0;i<a;i++){ for(j=i+1;j<a;j++){ if(stu[i].thp>stu[j].thp){ tmp=stu[i]; stu[i]=stu[j]; stu[j]=tmp; } } } cout<<"按实发工资排序成功"<<endl; } //输出函数 void output(company *stu,int a){ int i; for(i=0;i<a;i++){ stu[i].display(); } } //写入文件 void save(company *stu,int a){ int i=0; fstream fs; fs.open("f:\\stud.txt",ios_base::out); fs<<"工号 姓 名 基础工资 岗位工资 奖 金 应发工资 公积金 税 收 实发工资 "<<endl; for(i=0;i<a;i++){ fs<<stu[i].num<<" "<<stu[i].name<<" "<<stu[i].basicwage<<" "<<stu[i].postwage<<" "<<stu[i].bonus<<" "<<stu[i].salary<<" "<<stu[i].funds<<" "<<stu[i].deduthetax<<" "<<stu[i].thp<<endl; } fs.close(); cout<<"写入成功"<<endl; }
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
int m; m=mmyz(); if(m==3){ printf("..........................\n"); } else{ //当密码正确时 int i; int n; //功能序号 int a; //输入员工个数 company st[100];//定义类数组 company *stu=st;//让类指针指向数组首地址 cout<<"输入员工个数"<<endl; cin>>a; cout<<"输入数据(编号,姓名,基本工资,岗位工资,奖励,应发工资,公积金,税收,实发工资)"<<endl; for(i=0;i<a;i++){ stu[i].setdata(); cout<<endl; } //输入函数 menu(); int o; for(;o!=0;){ cout<<"|--------------------|"<<endl; cout<<"|-请选择要操作的序号-|"<<endl; cin>>o; if(o==0){ cout<<"退出"<<endl; break; } else{ switch(o) { case 1:add(stu,a);break; case 2:change(stu,a);break; case 3:delet(stu,a);break; case 4:sum(stu,a);break; case 5:search(stu,a);break; case 6:sort(stu,a);break; case 7:output(stu,a);break; case 8:menu();break; case 9:save(stu,a);break; } } } } return 0; }
|