#include#include #include #include #include #define MAX_LEN 20 #define WOR_NUM 200 #define MAX_ADD 20 #define N 30 typedef struct Worker { long long id; //编号 char name[MAX_LEN]; //姓名 int age; //年龄 char add[MAX_ADD]; //职位 int wage; //工资 long long num; //手机号码 }WOR; WOR wor[WOR_NUM]; int ch = -1; int Menu(void); int n = 0; int Menu(); //主菜单 void choose(int ch); //选择 void ReadData(); //读入数据 void Searchbyid(); //通过年龄搜索信息 void SortByid(); //按年龄从小到大排序 void Modifydata(); //修改信息 void Deletedatd(); //删除信息 int main() { printf("请输入职工的数量n(n<=200):n"); scanf("%d", &n); while (1) { ch = Menu(); choose(ch); ch = -1; } } int Menu() { int ch; printf("**********************┍ -----------------------┑ *********************n"); printf("********************** 欢迎使用职工管理系统 *********************n"); printf("**********************┕------------------------┙ *********************n"); printf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx菜单xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxn"); printf("======================================================================n"); printf("....... 1.录入信息 ..... 2.查询信息 .......n"); printf("....... 3.排序功能 ..... 4.修改信息 .......n"); printf("....... 5.删除数据 ..... 0.退出系统 .......n"); printf("请输入你的选择:n"); scanf("%d", &ch); return ch; } void choose(int ch) { switch (ch) { case 1: printf("请输入编号,姓名,年龄,职位,工资,手机号(Pause:0):n"); ReadData(); break; case 2: printf("请输入你想要查询的编号: n"); Searchbyid(); break; case 3: SortByid(); break; case 4: Modifydata(); break; case 5: Deletedatd(); break; case 0: printf("项目结束!"); exit(0); default: printf("Input error!n"); } } void ReadData() //读入数据 { int i; for (i = 0; i < n; i++) { printf("编号:"); scanf("%lld", &wor[i].id); if (wor[i].id == 0)break; getchar(); printf("姓名:"); gets(wor[i].name); printf("年龄:"); scanf("%d", &wor[i].age); printf("工资:"); scanf("%d", &wor[i].wage); printf("职位:"); scanf("%s", &wor[i].add); getchar(); printf("手机号:"); scanf("%lld", &wor[i].num); printf("n"); } } void Searchbyid() //2.查找 { long long int term = -1; int i; scanf("%lld", &term); for (i = 0; i < n; i++) { if (term == wor[i].id) { printf("编号:%lldn", wor[i].id); printf("姓名:%sn", wor[i].name); printf("年龄:%dn", wor[i].age); printf("工资:%dn", wor[i].wage); printf("职位:%sn", wor[i].add); printf("手机号:%lldn", wor[i].num); term = -2; } } if (term != -2) { printf("Not found!n"); } } void SortByid() //3.排序 { WOR temp1 = { 0 }; int i, j; for (i = 0; i < n - 1; i++) { if (wor[i].id > wor[i + 1].id) { temp1 = wor[i]; wor[i] = wor[i + 1]; wor[i + 1] = temp1; } } for (j = 0; j < n; j++) { printf("编号:%lldn", wor[j].id); printf("姓名:%sn", wor[j].name); printf("年龄:%dn", wor[j].age); printf("工资:%dn", wor[j].wage); printf("职位:%sn", wor[j].add); printf("手机号:%lldn", wor[j].num); printf("n"); } } void Deletedatd()//4.删除信息 { int i, j, flag = 0; long long id1; printf("请输入编号:n"); scanf("%lld", &id1); for (i = 0; i < n; i++) { if (wor[i].id == id1) { flag = 1; for (j = i; j < n - 1; j++) { wor[j] = wor[j + 1]; } } } } void Modifydata() //5.修改信息 { int i, item, j = -1; long long s1; printf("请输入编号:n"); scanf("%lld", &s1); for (i = 0; i < n; i++) { if (wor[i].id == s1) { j = i; printf("1.修改名字:n"); printf("2.修改年龄:n"); printf("3.修改工资:n"); printf("4.修改地址:n"); printf("5.修改手机号:n"); printf("0.结束项目!n"); while (1) { printf("请选择:"); scanf("%d", &item); switch (item) { case 1: printf("请输入新的名字:n"); scanf("%s", &wor[j].name); break; case 2: printf("请输入新的年龄:n"); scanf("%d", &wor[j].age); break; case 3: printf("请输入新的工资:n"); scanf("%d", &wor[j].wage); break; case 4: printf("请输入新的地址:n"); scanf("%s", &wor[j].add); break; case 5: printf("请输入新的手机号:n"); scanf("%lld", &wor[j].num); break; default: printf("输入错误!n"); } if (item == 0) break; } } } }
对我的博客或其他方面有任何见解或问题的话都可以私信我
或者联系本人QQ:3128909688
微信:DreamHerome
欢迎致电
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)