班费收支管理系统c语言
时间: 2023-07-03 12:10:00 浏览: 40
班费收支管理系统可以用C语言实现,以下是一个简单的示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_RECORDS 1000
typedef struct Record {
int id;
char name[20];
int amount;
char type[10];
} Record;
Record records[MAX_RECORDS];
int num_records = 0;
void add_record() {
Record new_record;
printf("请输入记录信息:\n");
printf("编号:");
scanf("%d", &new_record.id);
printf("姓名:");
scanf("%s", new_record.name);
printf("金额:");
scanf("%d", &new_record.amount);
printf("类型(支出/收入):");
scanf("%s", new_record.type);
records[num_records++] = new_record;
printf("添加成功!\n");
}
void show_records() {
printf("编号\t姓名\t金额\t类型\n");
for (int i = 0; i < num_records; i++) {
printf("%d\t%s\t%d\t%s\n", records[i].id, records[i].name, records[i].amount, records[i].type);
}
}
void search_record() {
int id;
printf("请输入要查询的记录编号:");
scanf("%d", &id);
for (int i = 0; i < num_records; i++) {
if (records[i].id == id) {
printf("编号\t姓名\t金额\t类型\n");
printf("%d\t%s\t%d\t%s\n", records[i].id, records[i].name, records[i].amount, records[i].type);
return;
}
}
printf("未找到该记录!\n");
}
void delete_record() {
int id;
printf("请输入要删除的记录编号:");
scanf("%d", &id);
for (int i = 0; i < num_records; i++) {
if (records[i].id == id) {
for (int j = i+1; j < num_records; j++) {
records[j-1] = records[j];
}
num_records--;
printf("删除成功!\n");
return;
}
}
printf("未找到该记录!\n");
}
int main() {
int choice;
while (1) {
printf("请选择操作:\n");
printf("1. 添加记录\n");
printf("2. 显示所有记录\n");
printf("3. 查询记录\n");
printf("4. 删除记录\n");
printf("5. 退出\n");
printf("选择:");
scanf("%d", &choice);
switch (choice) {
case 1:
add_record();
break;
case 2:
show_records();
break;
case 3:
search_record();
break;
case 4:
delete_record();
break;
case 5:
printf("再见!\n");
exit(0);
default:
printf("无效操作!\n");
}
}
}
```
这个示例中,我们使用了一个结构体 `Record` 来表示一条记录,包含编号、姓名、金额和类型。我们使用一个全局数组 `records` 来保存所有的记录,使用变量 `num_records` 来记录记录数。主程序中,我们使用一个无限循环来等待用户选择操作。用户可以选择添加记录、显示所有记录、查询记录、删除记录或退出程序。具体实现可以参考代码注释。