- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
-
- void choice();
- void read();
- void add();
- void browse();
- void refer();
- void amend();
- void result();
-
- struct cost
- {
- char num[20];//编号
- char type[20];//类型
- char name[20];//经办人姓名
- char reason[200];//原因
- double amount;//收入金额
- char remarks[200];//备注
- double balances;//余额
- }all[100];
-
- int a;
- double b;
-
- int main()
- {
- char b;
- do
- {
- choice();
- printf("是否要继续使用?(yes/no)\n");
- scanf("%c", &b);
- } while (b!='n');
- printf("\n");
- printf("谢谢使用\n");
- return 0;
- }
-
- void choice()
- {
- char b;
- printf("********************************************\n");
- printf(" 班费收支管理系统\n");
- printf("请选择您所需要的服务,输入对应的序号:\n");
- printf(" 1.添加班费收支信息\n");
- printf(" 2.浏览所有班费收支信息\n");
- printf(" 3.查询班费收支信息\n");
- printf(" 4.修改班费收支信息\n");
- printf(" 5.直接查询余额信息\n");
- printf("********************************************\n");
- scanf("%c", &b);
- while (b !='1'&&b != '2'&&b != '3'&&b != '4')
- {
- printf("请重新输入有效数字\n");
- scanf("%c", &b);
- }
- switch (b)
- {
- case '1': add(); break;
- case '2': browse(); break;
- case '3': refer(); break;
- case '4': amend(); break;
- case '5': result(); break;
- }
- }
-
- void read()
- {
- FILE * fp, *NOM;
-
- if ((fp=fopen("Class_expense_information","rb")) ==NULL)
- {
- a = 0;
- fp = fopen("Class_expense_information", "wb");
- fwrite(&a, sizeof(int), 1, fp);
- fclose(fp);
- }
- }
-
- void add()
- {
-
- FILE * fp, *NOM;
-
- printf("请输入收支编号:\n");
- scanf("%s", all[a].num);
- printf("请输入经办人姓名:\n");
- scanf("%s", all[a].name);
- printf("请输入原因:\n");
- scanf("%s", all[a].reason);
- printf("请输入收支类型(in/out):\n");
- scanf("%s", all[a].type);
- printf("请输入金额:\n");
- scanf("%lf", all[a].amount);
- printf("请输入备注:\n");
- scanf("%s", all[a].remarks);
- switch (a)
- {
- case 0: fp = fopen("data", "wb"); break;
- default: fp = fopen("data", "ab"); break;
- }
- fwrite(&all[a], sizeof(struct cost), 1, fp);
- fclose(fp);
-
- a++;
-
- NOM = fopen("Class_expense_information", "wb");
- fwrite(&a, sizeof(int), 1, NOM);
- fclose(NOM);
- }
-
- void browse()
- {
- FILE *fp = NULL;
- int c;
- int sign = 1;
- double sum;
-
- fp = fopen("data", "rb");
-
- for (c = 0; c < a; c++)
- {
- fread(&all[c], sizeof(struct cost), 1, fp);
- printf("收支编号:%s\n", &all[c].num);
- printf("收支类型:%s\n", &all[c].type);
- printf("经办人姓名:%s\n", &all[c].name);
- printf("原因:%s\n", &all[c].reason);
- printf("金额:%lf\n", &all[c].amount);
- printf("备注:%s\n", &all[c].remarks);
- if (strcmp(all[c].type, "in") == 0) sign = 1;
- else if (strcmp(all[c].type, "out") == 0) sign = -1;
- sum = sum + (all[c].amount *sign);
- all[c].balances = sum;
- printf("余额:%lf\n", &all[c].balances);
- }
-
- }
-
- void amend() // 按不同字段查询班费信息
- {
- FILE *fp = NULL;
- int x, i, k, result[100];
- char key_world[20];
-
- begin3:
- k = 0;
- printf("\n");
- printf("1.按班费收支编号查询\n");
- printf("2.按班费收支类型查询\n");
- printf("3.按班费经办人姓名查询\n");
- printf("4.按班费收支原因查询\n");
- printf("5.返回上一级\n");
- printf("请输入你的选择:");
-
- begin2:
- scanf("%d", &x);
-
- printf("请输入要查询的关键字:");
-
- scanf("%s", key_world);
- fp = fopen("data", "rb");
-
- switch (x)
- {
- case 1:
- for (i = 0; i < a; i++)
- {
- fread(&all[i], sizeof(struct cost), 1, fp);
-
- if (strcmp(all[i].num, key_world) == 0)
- {
- result[k] = i;
- k++;
- }
- }
- break;
- case 2:
- for (i = 0; i < a; i++)
- {
- fread(&all[i], sizeof(struct cost), 1, fp);
-
- if (strcmp(all[i].type, key_world) == 0)
- {
- result[k] = i;
- k++;
- }
- }
- break;
- case 3:
- for (i = 0; i < a; i++)
- {
- fread(&all[i], sizeof(struct cost), 1, fp);
-
- if (strcmp(all[i].name, key_world) == 0)
- {
- result[k] = i;
- k++;
- }
- }
- break;
- case 4:
- for (i = 0; i < a; i++)
- {
- fread(&all[i], sizeof(struct cost), 1, fp);
-
- if (strcmp(all[i].reason, key_world) == 0)
- {
- result[k] = i;
- k++;
- }
- }
- break;
- case 5:
- return;
- break;
- default:
- printf("输入错误!请重新输入:");
- fflush(stdin);
- fclose(fp);
- goto begin2;
- break;
- }
-
- if (k == 0)
- {
- printf("没有查到相关的内容!\n");
- fclose(fp);
- goto begin3;
- }
-
- else
- {
- printf("\n\n查找到%d条记录:\n\n", k);
-
- for (i = 0; i < k; i++)
- {
- fread(&all[result[i]], sizeof(struct cost), 1, fp);
- printf("收支编号:%s\n", &all[result[i]].num);
- printf("收支类型:%s\n", &all[result[i]].type);
- printf("经办人姓名:%s\n", &all[result[i]].name);
- printf("原因:%s\n", &all[result[i]].reason);
- printf("金额:%lf\n", &all[result[i]].amount);
- printf("备注:%s\n", &all[result[i]].remarks);
- printf("当时余额:%lf\n", &all[result[i]].balances);
- }
-
- fclose(fp);
- }
- }
-
- void refer() // 修改班费信息
- {
- FILE * fp = NULL;
- int i, k, x, result[100];
- char key_world[20];
-
- printf("请输入你要修改的班费信息的编号:");
- scanf("%s", key_world);
- k = 0;
- fp = fopen("data", "rb");
-
- for (i = 0; i < a; i++)
- {
- fread(&all[i], sizeof(struct cost), 1, fp);
-
- if (strcmp(all[i].num, key_world) == 0)
- {
- result[k] = i;
- k++;
- }
- }
-
- fclose(fp);
-
- if (k == 0)
- {
- printf("没有查到相关的内容!\n");
- return;
- }
-
- else
- {
- printf("\n\n查找到%d条记录:\n\n", k);
- fp = fopen("data", "rb");
-
- for (i = 0; i < k; i++)
- {
- printf("记录%d:\n", i + 1);
- printf("收支编号:%s\n", &all[result[i]].num);
- printf("收支类型:%s\n", &all[result[i]].type);
- printf("经办人姓名:%s\n", &all[result[i]].name);
- printf("原因:%s\n", &all[result[i]].reason);
- printf("金额:%lf\n", &all[result[i]].amount);
- printf("备注:%s\n", &all[result[i]].remarks);
- printf("当时余额:%lf\n", &all[result[i]].balances);
- }
-
- close(fp);
-
- begin4:
- printf("请输入需要修改的记录的记录序号:");
- scanf("%d", &x);
-
- if (x > k)
- {
- printf("输入错误!");
- fflush(stdin);
- goto begin4;
- }
-
- else
- {
- printf("请输入班费编号:");
- scanf("%s", all[result[x - 1]].num);
- printf("请输入收支类型:");
- scanf("%s", all[result[x - 1]].type);
- printf("请输入经办人姓名:");
- scanf("%s", all[result[x - 1]].name);
- printf("请输入原因:");
- scanf("%s", all[result[x - 1]].reason);
- printf("请输入金额:");
- scanf("%lf", all[result[x - 1]].amount);
- printf("请输入备注:");
- scanf("%s", all[result[x - 1]].remarks);
-
-
- fp = fopen("data", "rb+");
-
- for (i = 0; i < a; i++)
- {
- if (i != result[x])
- {
- fwrite(&all[i], sizeof(struct cost), 1, fp);
- }
-
- else
- {
- fwrite(&all[result[x]], sizeof(struct cost), 1, fp);
- }
- }
-
- fclose(fp);
- }
- }
- }
-
- void result()
- {
- FILE *fp = NULL;
- int c;
- int sign = 1;
- double sum;
-
- fp = fopen("data", "rb");
-
- for (c = 0; c < a; c++)
- {
- fread(&all[c], sizeof(struct cost), 1, fp);
- if (strcmp(all[c].type, "in") == 0) sign = 1;
- else if (strcmp(all[c].type, "out") == 0) sign = -1;
- sum = sum + (all[c].amount *sign);
- all[c].balances = sum;
- printf("余额:%lf\n", &all[c].balances);
- }
-
- }
编译没有报错但是运行出错,求解决
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
5条回答 默认 最新
悬赏问题
- ¥15 kubeasz部署遇到问题
- ¥15 GUIDE to App Designer Migration Tool for MATLAB
- ¥50 第三代非支配排序遗传算法(NSGA-Ⅲ)和多目标粒子群优化算法(MOPSO)的实现
- ¥15 hbuilderx写一个这个网页🙏
- ¥20 plant simulation与python com接口实时数据交互
- ¥15 有关汽车的MC9S12XS128单片机实验
- ¥15 求c语言动态链表相关课程有偿,或能将这块知识点讲明白
- ¥15 FLKT界面刷新异常
- ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
- ¥50 单细胞测序拟时序分析