C语言班费收支管理系统代码有1.输入班费收入或支出的日期,来源,金额,2.班费信息的修改,3.按班费支出或收入的日期查询班费信息,4.班费信息展示并计算班费余额。的功能
时间: 2024-02-28 09:56:57 浏览: 69
Java-springboot班费收支管理系统计算机毕业设计程序.zip
以下是一个包含输入日期、来源、金额、修改、查询和展示班费信息以及计算余额的C语言班费收支管理系统代码:
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_RECORDS 100
struct Record {
char date[20];
char source[50];
float amount;
};
struct Record records[MAX_RECORDS];
int num_records = 0;
void add_record() {
if (num_records >= MAX_RECORDS) {
printf("Maximum number of records reached!\n");
return;
}
struct Record new_record;
printf("Enter date (MM/DD/YYYY): ");
scanf("%s", new_record.date);
printf("Enter source: ");
scanf("%s", new_record.source);
printf("Enter amount: ");
scanf("%f", &new_record.amount);
records[num_records++] = new_record;
printf("Record added successfully!\n");
}
void modify_record() {
if (num_records == 0) {
printf("No records found!\n");
return;
}
char date[20];
printf("Enter date of record to modify (MM/DD/YYYY): ");
scanf("%s", date);
for (int i = 0; i < num_records; i++) {
if (strcmp(records[i].date, date) == 0) {
printf("Enter new source: ");
scanf("%s", records[i].source);
printf("Enter new amount: ");
scanf("%f", &records[i].amount);
printf("Record modified successfully!\n");
return;
}
}
printf("Record not found!\n");
}
void search_record() {
if (num_records == 0) {
printf("No records found!\n");
return;
}
char date[20];
printf("Enter date of record to search (MM/DD/YYYY): ");
scanf("%s", date);
printf("Date\t\tSource\t\tAmount\n");
for (int i = 0; i < num_records; i++) {
if (strcmp(records[i].date, date) == 0) {
printf("%s\t%s\t\t%.2f\n", records[i].date, records[i].source, records[i].amount);
return;
}
}
printf("Record not found!\n");
}
void list_records() {
if (num_records == 0) {
printf("No records found!\n");
return;
}
printf("Date\t\tSource\t\tAmount\n");
for (int i = 0; i < num_records; i++) {
printf("%s\t%s\t\t%.2f\n", records[i].date, records[i].source, records[i].amount);
}
}
void calculate_balance() {
float balance = 0;
for (int i = 0; i < num_records; i++) {
balance += records[i].amount;
}
printf("Balance: %.2f\n", balance);
}
int main() {
int choice;
do {
printf("\n1. Add record\n2. Modify record\n3. Search record\n4. List records\n5. Calculate balance\n6. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_record();
break;
case 2:
modify_record();
break;
case 3:
search_record();
break;
case 4:
list_records();
break;
case 5:
calculate_balance();
break;
case 6:
printf("Exiting program...\n");
break;
default:
printf("Invalid choice!\n");
break;
}
} while (choice != 6);
return 0;
}
```
这个程序包含以下功能:
- 添加一条班费记录,包括日期、来源和金额
- 修改一条班费记录的来源和金额
- 查询一条班费记录
- 显示所有的班费记录
- 计算班费余额
你可以根据需要进行修改和扩展。希望这可以对你有所帮助!
阅读全文