帮我写一个c语言代码,要求为:题目:约写程序,对本宿舍的财务收人和支出情况进行管理 (财务信息的浏览、财务变动信息的录入、财务信息的查询,财务信息的副除)。 所开发的系统应该包括以下几个模块: 1菜单选择模块(选择所要进行的操作) 2收入和支出情况录入模块(录入时要求要录入年、月、日、姓名、金额、收入or 支出、资金来源或去处) 3.浏览模块(显示总的支出和收入、当前余额、 明细) 4查询模块(查询收入和支出明细) 5.信息刷除模块(用于别除财务信息,需要先童找,再别除) 6.退出系統界面
时间: 2024-02-09 09:10:13 浏览: 35
以下是一个简单的实现该功能的 C 语言代码,供参考:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LEN 20 // 最大输入长度
// 账目结构体
struct account {
int year;
int month;
int day;
char name[MAX_LEN];
float amount;
char type[MAX_LEN];
char source[MAX_LEN];
};
// 全局变量
struct account accounts[100]; // 最多存储 100 条账目
int count = 0; // 当前存储的账目数量
// 函数声明
void show_menu();
void add_account();
void browse_accounts();
void query_accounts();
void delete_account();
int main() {
while (1) {
show_menu();
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
add_account();
break;
case 2:
browse_accounts();
break;
case 3:
query_accounts();
break;
case 4:
delete_account();
break;
case 5:
printf("谢谢使用!\n");
exit(0); // 退出程序
default:
printf("输入错误,请重新选择!\n");
break;
}
}
return 0;
}
// 显示菜单
void show_menu() {
printf("请选择操作:\n");
printf("1. 账目录入\n");
printf("2. 账目浏览\n");
printf("3. 账目查询\n");
printf("4. 账目删除\n");
printf("5. 退出系统\n");
}
// 添加账目
void add_account() {
printf("请输入年、月、日、姓名、金额、类型(收入/支出)、来源或去处:\n");
struct account new_account;
scanf("%d %d %d %s %f %s %s", &new_account.year, &new_account.month, &new_account.day, new_account.name, &new_account.amount, new_account.type, new_account.source);
accounts[count] = new_account;
count++;
printf("账目添加成功!\n");
}
// 浏览账目
void browse_accounts() {
float total_income = 0, total_expense = 0, balance = 0;
printf("所有账目:\n");
printf("年 月 日 姓名 金额 类型 来源/去处\n");
for (int i = 0; i < count; i++) {
printf("%d %d %d %s %.2f %s %s\n", accounts[i].year, accounts[i].month, accounts[i].day, accounts[i].name, accounts[i].amount, accounts[i].type, accounts[i].source);
if (strcmp(accounts[i].type, "收入") == 0) {
total_income += accounts[i].amount;
} else if (strcmp(accounts[i].type, "支出") == 0) {
total_expense += accounts[i].amount;
}
}
balance = total_income - total_expense;
printf("总收入:%.2f\n", total_income);
printf("总支出:%.2f\n", total_expense);
printf("当前余额:%.2f\n", balance);
}
// 查询账目
void query_accounts() {
printf("请输入要查询的姓名:\n");
char name[MAX_LEN];
scanf("%s", name);
printf("查询结果:\n");
printf("年 月 日 姓名 金额 类型 来源/去处\n");
for (int i = 0; i < count; i++) {
if (strcmp(accounts[i].name, name) == 0) {
printf("%d %d %d %s %.2f %s %s\n", accounts[i].year, accounts[i].month, accounts[i].day, accounts[i].name, accounts[i].amount, accounts[i].type, accounts[i].source);
}
}
}
// 删除账目
void delete_account() {
printf("请输入要删除的账目的下标:\n");
int index;
scanf("%d", &index);
if (index < 0 || index >= count) {
printf("输入错误,请重新选择!\n");
return;
}
for (int i = index; i < count - 1; i++) {
accounts[i] = accounts[i + 1];
}
count--;
printf("账目删除成功!\n");
}
```
注意:该代码仅作为参考,实际应用中可能需要根据具体情况进行修改和完善。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)