帮我写一个简单的C语言程序银行贷款信息包括:编号,姓名,贷款时问(如2018-1-2),贷款金额,货款年限,贷款利率等信息 试设计银行货款信息管理,使之能提供以下功能: 1) 系统以菜单方式工作(用键盘输入1~9之间的数来选择功能,其中9为退出); 2) 贷款信息录入功能(包括编号,姓名,贷款时间,贷款金额,贷款年限,贷款利率); 3) 监考信息整体浏览功能; 4) 按编号查询该人贷款的基本信息; 5) 统计相同货款年限的人数; 6) 按编号查询并修改货款人的姓名; 7)按照“贷款金额〞升序排序; 8)按照输入 “编号”信息删除该贷款人员的信息; 9)所有数据符合实际应用要求。
时间: 2023-04-06 13:03:00 浏览: 221
以下是一个简单的C语言程序,实现了银行贷款信息管理系统的基本功能:
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_RECORDS 100
typedef struct {
int id;
char name[20];
char date[20];
double amount;
int years;
double rate;
} LoanRecord;
LoanRecord records[MAX_RECORDS];
int num_records = 0;
void print_menu() {
printf("1. 录入贷款信息\n");
printf("2. 浏览所有贷款信息\n");
printf("3. 按编号查询贷款信息\n");
printf("4. 统计相同货款年限的人数\n");
printf("5. 按编号修改贷款人姓名\n");
printf("6. 按贷款金额排序\n");
printf("7. 按编号删除贷款信息\n");
printf("9. 退出\n");
}
void add_record() {
if (num_records >= MAX_RECORDS) {
printf("记录已满,无法添加!\n");
return;
}
LoanRecord record;
printf("请输入贷款编号:");
scanf("%d", &record.id);
printf("请输入贷款人姓名:");
scanf("%s", record.name);
printf("请输入贷款时间(格式如2018-1-2):");
scanf("%s", record.date);
printf("请输入贷款金额:");
scanf("%lf", &record.amount);
printf("请输入贷款年限:");
scanf("%d", &record.years);
printf("请输入贷款利率:");
scanf("%lf", &record.rate);
records[num_records++] = record;
printf("记录已添加!\n");
}
void print_records() {
printf("编号\t姓名\t贷款时间\t贷款金额\t贷款年限\t贷款利率\n");
for (int i = 0; i < num_records; i++) {
LoanRecord record = records[i];
printf("%d\t%s\t%s\t%.2lf\t%d\t%.2lf\n", record.id, record.name, record.date, record.amount, record.years, record.rate);
}
}
void search_record() {
int id;
printf("请输入贷款编号:");
scanf("%d", &id);
for (int i = 0; i < num_records; i++) {
LoanRecord record = records[i];
if (record.id == id) {
printf("编号\t姓名\t贷款时间\t贷款金额\t贷款年限\t贷款利率\n");
printf("%d\t%s\t%s\t%.2lf\t%d\t%.2lf\n", record.id, record.name, record.date, record.amount, record.years, record.rate);
return;
}
}
printf("未找到该贷款记录!\n");
}
void count_years() {
int years;
printf("请输入贷款年限:");
scanf("%d", &years);
int count = 0;
for (int i = 0; i < num_records; i++) {
LoanRecord record = records[i];
if (record.years == years) {
count++;
}
}
printf("贷款年限为%d的人数为%d\n", years, count);
}
void modify_name() {
int id;
printf("请输入贷款编号:");
scanf("%d", &id);
for (int i = 0; i < num_records; i++) {
LoanRecord record = records[i];
if (record.id == id) {
printf("请输入新的贷款人姓名:");
scanf("%s", record.name);
records[i] = record;
printf("贷款人姓名已修改!\n");
return;
}
}
printf("未找到该贷款记录!\n");
}
void sort_amount() {
for (int i = 0; i < num_records - 1; i++) {
for (int j = i + 1; j < num_records; j++) {
if (records[i].amount > records[j].amount) {
LoanRecord temp = records[i];
records[i] = records[j];
records[j] = temp;
}
}
}
printf("贷款信息已按贷款金额升序排序!\n");
}
void delete_record() {
int id;
printf("请输入贷款编号:");
scanf("%d", &id);
for (int i = 0; i < num_records; i++) {
LoanRecord record = records[i];
if (record.id == id) {
for (int j = i; j < num_records - 1; j++) {
records[j] = records[j + 1];
}
num_records--;
printf("贷款信息已删除!\n");
return;
}
}
printf("未找到该贷款记录!\n");
}
int main() {
int choice;
do {
print_menu();
printf("请输入选项:");
scanf("%d", &choice);
switch (choice) {
case 1:
add_record();
break;
case 2:
print_records();
break;
case 3:
search_record();
break;
case 4:
count_years();
break;
case 5:
modify_name();
break;
case 6:
sort_amount();
break;
case 7:
delete_record();
break;
case 9:
printf("谢谢使用!\n");
break;
default:
printf("无效选项!\n");
break;
}
} while (choice != 9);
return 0;
}
```
阅读全文