班费收支管理系统c语言
时间: 2023-07-03 14:09:57 浏览: 110
班费收支管理系统可以分为三个模块:收入管理、支出管理以及查询功能。
以下是一个简单的班费收支管理系统的C语言代码示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 定义常量
#define MAX_RECORDS 1000
#define MAX_NAME_LENGTH 20
// 定义记录结构体
struct record {
char name[MAX_NAME_LENGTH];
int amount;
char type;
};
// 声明函数
void add_record(struct record records[], int *num_records);
void show_records(struct record records[], int num_records);
void show_balance(struct record records[], int num_records);
int main() {
struct record records[MAX_RECORDS];
int num_records = 0;
int choice;
while (1) {
printf("\n班费收支管理系统\n");
printf("1. 添加记录\n");
printf("2. 查看所有记录\n");
printf("3. 查看账户余额\n");
printf("4. 退出\n");
printf("请选择操作:");
scanf("%d", &choice);
switch (choice) {
case 1:
add_record(records, &num_records);
break;
case 2:
show_records(records, num_records);
break;
case 3:
show_balance(records, num_records);
break;
case 4:
exit(0);
default:
printf("输入错误,请重新选择操作。\n");
break;
}
}
return 0;
}
// 添加记录
void add_record(struct record records[], int *num_records) {
char name[MAX_NAME_LENGTH];
int amount;
char type;
printf("\n添加记录\n");
printf("请输入姓名:");
scanf("%s", name);
printf("请输入金额:");
scanf("%d", &amount);
printf("请输入类型(收入-1,支出-2):");
scanf("%d", &type);
struct record r;
strcpy(r.name, name);
r.amount = amount;
r.type = type;
records[*num_records] = r;
(*num_records)++;
printf("记录添加成功!\n");
}
// 查看所有记录
void show_records(struct record records[], int num_records) {
printf("\n所有记录\n");
if (num_records == 0) {
printf("暂无记录。\n");
} else {
printf("姓名\t金额\t类型\n");
for (int i = 0; i < num_records; i++) {
printf("%s\t%d\t%c\n", records[i].name, records[i].amount, records[i].type);
}
}
}
// 查看账户余额
void show_balance(struct record records[], int num_records) {
printf("\n账户余额\n");
int income = 0;
int expense = 0;
int balance = 0;
for (int i = 0; i < num_records; i++) {
if (records[i].type == '1') {
income += records[i].amount;
} else {
expense += records[i].amount;
}
}
balance = income - expense;
printf("收入:%d元,支出:%d元,账户余额:%d元。\n", income, expense, balance);
}
```
这个班费收支管理系统可以让用户添加记录、查看所有记录以及查看账户余额。用户可以在程序运行时选择操作,直到选择退出为止。
阅读全文