帮我写一个c语言代码:银行贷款信息包括:编号,姓名,贷款时间,贷款金额,货款年限,贷款利率等信息。试设计银行货款信息管理,使之能提供以下功能:系统以菜单方式工作(用键盘输入1~7之间的数来选择功能,其中7为退出);贷款信息录入功能(包括编号,姓名,贷款时间,贷款金额,贷款年限,贷款利率);监考信息整体浏览功能;按编号查询该人贷款的基本信息;统计相同货款年限的人数:按编号查询并修改货款人的姓名;按照“贷款金额〞升序排序;按照输入 “编号”信息删除该贷款人员的信息。所有数据符合实际应用要求。
时间: 2023-04-02 19:01:19 浏览: 205
以下是C语言代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100
struct Loan {
int id;
char name[20];
char time[20];
float amount;
int year;
float rate;
};
struct Loan loans[MAX];
int count = ;
void inputLoan() {
struct Loan loan;
printf("请输入贷款编号:");
scanf("%d", &loan.id);
printf("请输入贷款人姓名:");
scanf("%s", loan.name);
printf("请输入贷款时间:");
scanf("%s", loan.time);
printf("请输入贷款金额:");
scanf("%f", &loan.amount);
printf("请输入贷款年限:");
scanf("%d", &loan.year);
printf("请输入贷款利率:");
scanf("%f", &loan.rate);
loans[count++] = loan;
printf("贷款信息录入成功!\n");
}
void displayLoans() {
printf("编号\t姓名\t贷款时间\t贷款金额\t贷款年限\t贷款利率\n");
for (int i = ; i < count; i++) {
printf("%d\t%s\t%s\t%.2f\t%d\t%.2f\n", loans[i].id, loans[i].name, loans[i].time, loans[i].amount, loans[i].year, loans[i].rate);
}
}
void searchLoanById() {
int id;
printf("请输入贷款编号:");
scanf("%d", &id);
for (int i = ; i < count; i++) {
if (loans[i].id == id) {
printf("编号\t姓名\t贷款时间\t贷款金额\t贷款年限\t贷款利率\n");
printf("%d\t%s\t%s\t%.2f\t%d\t%.2f\n", loans[i].id, loans[i].name, loans[i].time, loans[i].amount, loans[i].year, loans[i].rate);
return;
}
}
printf("未找到该贷款人员的信息!\n");
}
void countLoanByYear() {
int year;
printf("请输入贷款年限:");
scanf("%d", &year);
int countYear = ;
for (int i = ; i < count; i++) {
if (loans[i].year == year) {
countYear++;
}
}
printf("贷款年限为%d的人数为%d人\n", year, countYear);
}
void modifyLoanName() {
int id;
printf("请输入贷款编号:");
scanf("%d", &id);
for (int i = ; i < count; i++) {
if (loans[i].id == id) {
printf("请输入新的贷款人姓名:");
scanf("%s", loans[i].name);
printf("贷款人姓名修改成功!\n");
return;
}
}
printf("未找到该贷款人员的信息!\n");
}
void sortLoanByAmount() {
for (int i = ; i < count - 1; i++) {
for (int j = ; j < count - i - 1; j++) {
if (loans[j].amount > loans[j + 1].amount) {
struct Loan temp = loans[j];
loans[j] = loans[j + 1];
loans[j + 1] = temp;
}
}
}
printf("按照贷款金额升序排序成功!\n");
}
void deleteLoanById() {
int id;
printf("请输入贷款编号:");
scanf("%d", &id);
for (int i = ; i < count; i++) {
if (loans[i].id == id) {
for (int j = i; j < count - 1; j++) {
loans[j] = loans[j + 1];
}
count--;
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("6. 按照贷款金额升序排序\n");
printf("7. 按照输入编号信息删除该贷款人员的信息\n");
printf("8. 退出\n");
scanf("%d", &choice);
switch (choice) {
case 1:
inputLoan();
break;
case 2:
displayLoans();
break;
case 3:
searchLoanById();
break;
case 4:
countLoanByYear();
break;
case 5:
modifyLoanName();
break;
case 6:
sortLoanByAmount();
break;
case 7:
deleteLoanById();
break;
case 8:
exit();
default:
printf("输入有误,请重新输入!\n");
break;
}
}
return ;
}
阅读全文