大一--纯C实现--职工信息管理--课程设计
从今日0点0分开始到凌晨2点 有了个基本思路和实现了一点
然后再折腾了大半个下午和一个晚自习 OK 基本上可以说就这样了吧
我可能还会 再添加点功能实现 但是呢 也不一定 明天去问下老师 这样成不.....
这应该算 自己的第一次蛮大的框架设计吧... 虽然 形容的不好...
这次 有很多收获:
1.....第一次 用到了工程这个东西.. 话说 其实 工程也可以自己去搭建MakeFile来实现的
2....还有当你在做一个项目设计的时候 肯定会用到很多头文件 这时候 一定要注意变量的声明 最好尽量声明为局部变量 因为当你声明为全局变量的时候 一旦多次引用这个头文件 很容易产生重定义错误 我运行的时候反正报错 划动鼠标滚轮到我手都酸了.......
3...头文件内 当你使用if while for什么的时候 一定要将它们放在函数内 不然也会编译报错的...
4...我还是更希望 用C++去实现 反正 到了大二 也还是有课程设计..
5...keep... 大神去了google .. this is a amazing company...
虽然 有很多文件 我还是将它贴上来好了 不然下次被自己搞丢了 都不知道... 一共17个 .h文件+.cpp文件
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include "company.h" 4 #include "sortBySalary.h" 5 #include "searchSalary.h" 6 #include "updateSalary.h" 7 #include "addData.h" 8 #include "removeData.h" 9 #include "showInformation.h" 10 #include "saveData.h" 11 12 int main() 13 { 14 init(); 15 while(1) 16 { 17 int choice; 18 scanf( "%d",&choice ); 19 switch (choice) 20 { 21 case 1: 22 show(); 23 break; 24 case 2: 25 add(); 26 break; 27 case 3: 28 remove(); 29 break; 30 case 4: 31 sort(); 32 break; 33 case 5: 34 search(); 35 break; 36 case 6: 37 update(); 38 break; 39 case 7: 40 system("cls"); 41 printf( "\t\t成功重启 继续使用\t\t\n" ); 42 init(); 43 break; 44 case 0: 45 save(); 46 printf( "\t\t谢谢使用 员工管理系统V1.0版\t\t\n" ); 47 exit(0); 48 break; 49 default: 50 printf( "请输入正确的数字功能键\n" ); 51 break; 52 } 53 } 54 return 0; 55 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 // company.h 2 #ifndef company 3 #define company 4 5 #include <stdio.h> 6 #include <string.h> 7 #include <stdlib.h> 8 9 extern int cnt; 10 11 typedef struct 12 { 13 int id; 14 char gender[20]; 15 int age; 16 char name[40]; 17 int basicSalary; 18 int jobSalary; 19 int jobSub; 20 int specialSub; 21 int sumSalary; 22 int flag; 23 }data; 24 25 extern data employee[10010]; 26 27 void init(); 28 29 #endif // company.h
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include "company.h" 2 3 int cnt = 3; 4 5 data employee[10010]; 6 7 void init() 8 { 9 printf( "\t\t欢迎使用 员工管理V1.0版 请根据下列数字键选择不同的功能\t\t\n" ); 10 printf( "\n\t\t<----1----> 显示员工信息 <----1---->\t\t\n" ); 11 printf( "\n\t\t<----2----> 增加员工信息 <----2---->\t\t\n" ); 12 printf( "\n\t\t<----3----> 根据员工编号来删除员工信息 <----3---->\t\t\n" ); 13 printf( "\n\t\t<----4----> 根据员工工资从小到大排序 <----4---->\t\t\n" ); 14 printf( "\n\t\t<----5----> 根据员工编号来查询员工工资 <----5---->\t\t\n" ); 15 printf( "\n\t\t<----6----> 根据员工编号来更新员工信息 <----6---->\t\t\n" ); 16 printf( "\n\t\t<----7----> 重启系统(仅保存初始员工信息) <----7---->\t\t\n" ); 17 printf( "\n\t\t<----0----> 安全退出 <----0---->\t\t\n" ); 18 int id; 19 char gender[20]; 20 int age; 21 char name[40]; 22 int basicSalary; 23 int jobSalary; 24 int jobSub; 25 int specialSub; 26 int sumSalary; 27 FILE* fp; 28 int i; 29 if ((fp = fopen("myInitalData.txt", "r")) == NULL) 30 { 31 printf("File open error please check again!!\n"); 32 exit(0); 33 } 34 if( cnt!=3 ) 35 { 36 cnt = 3; 37 } 38 if (cnt == 3) 39 { 40 for( i = 0 ; i<10010 ; i++ ) 41 { 42 employee[i].flag = 0; 43 } 44 for (i = 0; i < 3; i++) 45 { 46 fscanf(fp, "%s %d %s %d %d %d %d %d %d", name, &id, gender,&age, &basicSalary, &jobSalary, &jobSub, &specialSub,&sumSalary); 47 strcpy(employee[i].name, name); 48 employee[i].id = id; 49 employee[i].age = age; 50 strcpy(employee[i].gender, gender); 51 employee[i].basicSalary = basicSalary; 52 employee[i].jobSalary = jobSalary; 53 employee[i].jobSub = jobSub; 54 employee[i].specialSub = specialSub; 55 employee[i].sumSalary = sumSalary; 56 employee[i].id = i+1; 57 employee[i].flag = 1; 58 } 59 } 60 if (fclose(fp)) 61 { 62 printf("close the file error\n"); 63 exit(0); 64 } 65 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 //sortBySalary.h 2 #ifndef sortBySalary 3 #define soryBySalary 4 5 #include <stdio.h> 6 #include <stdlib.h> 7 #include "company.h" 8 9 int cmp(const void *p, const void *q); 10 11 void sort(); 12 13 #endif // sortBySalary.h
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include "sortBySalary.h" 2 3 int cmp(const void *p, const void *q) 4 { 5 data *a = (data *)p; 6 data *b = (data *)q; 7 if (a->sumSalary == b->sumSalary) 8 return a->id - b->id; 9 return a->sumSalary - b->sumSalary; 10 } 11 12 void sort() 13 { 14 int i, rank; 15 rank = 1; 16 qsort( employee, cnt , sizeof(employee[0]), cmp ); 17 for( i = cnt-1 ; i>=0 ; i-- ) 18 { 19 if( employee[i].flag ) 20 { 21 printf("NO.%d: %s %d %d %s %d %d %d %d %d\n",rank,employee[i].name,employee[i].id,employee[i].age,employee[i].gender,employee[i].basicSalary,employee[i].jobSalary,employee[i].jobSub,employee[i].specialSub,employee[i].sumSalary); 22 rank++; 23 } 24 } 25 printf( "排序完毕 返回上级菜单\n"); 26 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 //addData.h 2 #ifndef addData 3 #define addData 4 5 #include <stdio.h> 6 #include "company.h" 7 8 void add(); 9 10 #endif // addData.h
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include "addData.h" 2 3 void add() 4 { 5 int i , n; 6 printf( "请输入要增加的员工信息数量\n" ); 7 scanf( "%d",&n ); 8 for( i = 0 ; i<n; i++ ) 9 { 10 scanf("%s %s %d %d %d %d %d",employee[cnt].name,employee[cnt].gender,&employee[cnt].age,&employee[cnt].basicSalary,&employee[cnt].jobSalary,&employee[cnt].jobSub,&employee[cnt].specialSub ); 11 employee[cnt].id = cnt+1; 12 employee[cnt].flag = 1; 13 employee[cnt].sumSalary = employee[cnt].basicSalary + employee[cnt].jobSalary + employee[cnt].jobSub + employee[cnt].specialSub; 14 cnt++; 15 } 16 printf( "添加完毕 返回上级菜单\n"); 17 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 //removeData.h 2 #ifndef removeData 3 #define removeData 4 5 #include <stdio.h> 6 #include <string.h> 7 #include "company.h" 8 9 void remove(); 10 11 #endif // removeData.h
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include "addData.h" 2 3 void remove() 4 { 5 printf( "请输入要删除员工信息的人数\n" ); 6 int index , n; 7 scanf( "%d",&n ); 8 while( n-- ) 9 { 10 printf( "请输入待删除员工信息的编号\n" ); 11 scanf( "%d",&index ); 12 index-=1; 13 if( !employee[index].flag ) 14 { 15 printf( "你输入的编号信息不存在 请重新输入\n" ); 16 n++; 17 } 18 else 19 { 20 employee[index].flag = 0; 21 } 22 } 23 printf( "删除完毕 返回上级菜单\n"); 24 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 // removeData.h 2 #ifndef searchSalary 3 #define searchSalary 4 5 6 #include <stdio.h> 7 #include "company.h" 8 9 void search(); 10 11 #endif // searchSalary.h
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include "company.h" 2 3 void search() 4 { 5 int n , index; 6 printf( "请输入要查询的数量\n" ); 7 scanf( "%d",&n ); 8 while( n-- ) 9 { 10 printf( "请输入查询的编号\n" ); 11 scanf( "%d",&index ); 12 index-=1; 13 if( !employee[index].flag ) 14 { 15 printf( "你输入的编号信息不存在 请重新输入\n" ); 16 n++; 17 } 18 else 19 { 20 printf( "%s %d %d\n",employee[index].name,employee[index].id,employee[index].sumSalary ); 21 } 22 } 23 printf( "查询完毕 返回上级菜单\n"); 24 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 // showInformation.h 2 #ifndef showInformation 3 #define showInformation 4 5 #include <stdio.h> 6 #include "company.h" 7 8 9 void show(); 10 11 #endif // showInformation.h
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include "showInformation.h" 2 3 void show() 4 { 5 int i; 6 printf( "员工信息表:\n"); 7 printf( "姓名 编号 性别 年龄 基本工资 职务工资 岗位津贴 特殊津贴 总工资\n"); 8 for( i = 0 ; i<cnt ; i++ ) 9 { 10 if( employee[i].flag ) 11 { 12 printf("%s %d %s %d %d %d %d %d %d\n",employee[i].name,employee[i].id,employee[i].gender,employee[i].age,employee[i].basicSalary,employee[i].jobSalary,employee[i].jobSub,employee[i].specialSub,employee[i].sumSalary,employee[i].sumSalary); 13 } 14 } 15 printf( "展示完毕 返回上级菜单\n"); 16 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 // updataSalary.h 2 #ifndef updateSalary 3 #define updateSalary 4 5 #include <stdio.h> 6 #include "company.h" 7 8 void update(); 9 #endif // updataSalary.h
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include "updateSalary.h" 2 3 void update() 4 { 5 char name[20]; 6 int age; 7 char gender[10]; 8 int basicSalary; 9 int jobSalary; 10 int jobSub; 11 int specialSub; 12 int sumSalary; 13 14 int index , choice; 15 int isOver = 0; 16 while(1) 17 { 18 printf( "请输入要更新信息的员工的编号 或输入<=0的数直接退出\n"); 19 scanf( "%d",&index ); 20 if( index<=0 ) 21 { 22 printf( "安全退出 返回上级菜单\n" ); 23 break; 24 } 25 index-=1; 26 while( !employee[index].flag ) 27 { 28 printf( "该员工编号不存在...请重新输入\n"); 29 scanf( "%d",&index ); 30 } 31 printf( "请输入更新的模块与内容\n" ); 32 printf( "\t\t<----1---->姓名<----1---->\t\t\n\n"); 33 printf( "\t\t<----2---->年龄<----2---->\t\t\n\n"); 34 printf( "\t\t<----3---->性别<----3---->\t\t\n\n"); 35 printf( "\t\t<----4---->基本工资<----4---->\t\t\n\n"); 36 printf( "\t\t<----5---->职务工资<----5---->\t\t\n\n"); 37 printf( "\t\t<----6---->岗位津贴<----6---->\t\t\n\n"); 38 printf( "\t\t<----7---->特殊津贴<----7---->\t\t\n\n"); 39 printf( "\t\t<----7---->总工资<----7---->\t\t\n\n"); 40 printf( "\t\t<----0---->更新完毕 返回上层界面<----0---->\t\t\n\n"); 41 scanf( "%d",&choice ); 42 switch (choice) 43 { 44 case 1: 45 scanf( "%s",name ); 46 strcpy( employee[index].name , name ); 47 printf( "更新成功 继续操作\n"); 48 break; 49 case 2: 50 scanf( "%d",&age ); 51 employee[index].age = age; 52 printf( "更新成功 继续操作\n"); 53 break; 54 case 3: 55 scanf( "%s",gender ); 56 strcpy( employee[index].gender , gender ); 57 printf( "更新成功 继续操作\n"); 58 break; 59 case 4: 60 scanf( "%d",&basicSalary ); 61 employee[index]. sumSalary-=employee[index].basicSalary; 62 employee[index].basicSalary = basicSalary; 63 employee[index]. sumSalary+=employee[index].basicSalary; 64 printf( "更新成功 继续操作\n"); 65 break; 66 case 5: 67 scanf( "%d",&jobSalary ); 68 employee[index]. sumSalary-=employee[index].jobSalary; 69 employee[index].jobSalary = jobSalary; 70 employee[index]. sumSalary+=employee[index].jobSalary; 71 printf( "更新成功 继续操作\n"); 72 break; 73 case 6: 74 scanf( "%d",&jobSub ); 75 employee[index]. sumSalary-=employee[index].jobSub; 76 employee[index].jobSub = jobSub; 77 employee[index]. sumSalary+=employee[index].jobSub; 78 printf( "更新成功 继续操作\n"); 79 break; 80 case 7: 81 scanf( "%d",&specialSub ); 82 employee[index]. sumSalary-=employee[index].specialSub; 83 employee[index].specialSub = specialSub; 84 employee[index]. sumSalary+=employee[index].specialSub; 85 printf( "更新成功 继续操作\n"); 86 break; 87 case 8: 88 scanf( "%d",&sumSalary ); 89 employee[index].sumSalary = sumSalary; 90 printf( "更新成功 继续操作\n"); 91 break; 92 case 0: 93 isOver = 1; 94 break; 95 default: 96 printf( "输入错误 重新输入编号信息与更新模块和内容\n" ); 97 } 98 if( isOver ) 99 { 100 printf( "更新成功 安全退出 返回上级菜单\n" ); 101 break; 102 } 103 } 104 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 // savaData.h 2 #ifndef saveData 3 #define saveData 4 5 #include <stdio.h> 6 #include "company.h" 7 8 void save(); 9 #endif // savaData.h
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include "saveData.h" 2 3 void save() 4 { 5 int i; 6 FILE* fp; 7 if((fp = fopen("myResultData.txt", "a")) == NULL) 8 { 9 printf("File open error please check again!!\n"); 10 exit(0); 11 } 12 printf( "\t\t员工信息已保存 请查阅\t\t\n" ); 13 for( i = 0 ; i<cnt ; i++ ) 14 { 15 fprintf(fp,"%s %d %s %d %d %d %d %d %d\n", employee[i].name, employee[i].id, employee[i].gender,employee[i].age,employee[i].basicSalary, employee[i].jobSalary, employee[i].jobSub, employee[i].specialSub,employee[i].sumSalary); 16 } 17 }
很不满意地方 就是 没用到任何的算法-----------但是 感觉当你代码写多之后 思路还是蛮开阔的 排版也慢慢养成了
today:
你来 我等着
念念不忘 必有回响
我在最好的时候遇到你,是我的运气。可惜我没时间了。想想说人生无悔,都是赌气的话。人生若无悔,那该多无趣啊!
我和你 应该是在最好时节相遇的吧---高中--回不去了---我的错---
just follow your heart