帮我写一个c语言代码,要求银行贷款信息包括:编号,姓名,贷款时问(如2018-1-2),贷款金额,货款年限,贷款利率等信息 试设计银行货款信息管理,使之能提供以下功能: 1) 系统以菜单方式工作(用键盘输入1~7之间的数来选择功能,其中7为退出): 2) 贷款信息录入功能(包括编号,姓名,贷款时间,贷款金额,贷款年限,贷款利率): 3) 监考信息整体浏览功能: 4) 按编号查询该人贷款的基本信息; 5) 统计相同货款年限的人数: 6) 按编号查询并修改货款人的姓名: ⑦按照“贷款金额〞升序排序; 8)按照输入 “编号”信息的州除该贷款人员的信息。 9)所有数据符合实际应用要求。
时间: 2023-04-07 20:01:59 浏览: 93
基于Objective-C和C语言的国外贷款工程外包项目设计源码
以下是C语言代码,实现银行贷款信息管理系统:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100
struct LoanInfo {
int id;
char name[20];
char date[20];
float amount;
int years;
float rate;
};
struct LoanInfo loan[MAX];
int count = 0;
void inputLoanInfo();
void displayAllLoanInfo();
void searchLoanInfoById();
void countLoanInfoByYears();
void modifyLoanInfoNameById();
void sortLoanInfoByAmount();
void deleteLoanInfoById();
int main() {
int choice;
do {
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");
printf("请选择功能(1-8):");
scanf("%d", &choice);
switch (choice) {
case 1:
inputLoanInfo();
break;
case 2:
displayAllLoanInfo();
break;
case 3:
searchLoanInfoById();
break;
case 4:
countLoanInfoByYears();
break;
case 5:
modifyLoanInfoNameById();
break;
case 6:
sortLoanInfoByAmount();
break;
case 7:
deleteLoanInfoById();
break;
case 8:
printf("谢谢使用!\n");
break;
default:
printf("输入错误,请重新选择!\n");
break;
}
} while (choice != 8);
return 0;
}
void inputLoanInfo() {
if (count >= MAX) {
printf("贷款信息已满,无法录入!\n");
return;
}
struct LoanInfo info;
printf("请输入贷款编号:");
scanf("%d", &info.id);
printf("请输入贷款人姓名:");
scanf("%s", info.name);
printf("请输入贷款时间(如2018-1-2):");
scanf("%s", info.date);
printf("请输入贷款金额:");
scanf("%f", &info.amount);
printf("请输入贷款年限:");
scanf("%d", &info.years);
printf("请输入贷款利率:");
scanf("%f", &info.rate);
loan[count++] = info;
printf("贷款信息录入成功!\n");
}
void displayAllLoanInfo() {
if (count == 0) {
printf("贷款信息为空!\n");
return;
}
printf("编号\t姓名\t贷款时间\t贷款金额\t贷款年限\t贷款利率\n");
for (int i = 0; i < count; i++) {
printf("%d\t%s\t%s\t%.2f\t%d\t%.2f\n", loan[i].id, loan[i].name, loan[i].date, loan[i].amount, loan[i].years, loan[i].rate);
}
}
void searchLoanInfoById() {
if (count == 0) {
printf("贷款信息为空!\n");
return;
}
int id;
printf("请输入贷款编号:");
scanf("%d", &id);
for (int i = 0; i < count; i++) {
if (loan[i].id == id) {
printf("编号\t姓名\t贷款时间\t贷款金额\t贷款年限\t贷款利率\n");
printf("%d\t%s\t%s\t%.2f\t%d\t%.2f\n", loan[i].id, loan[i].name, loan[i].date, loan[i].amount, loan[i].years, loan[i].rate);
return;
}
}
printf("未找到该贷款信息!\n");
}
void countLoanInfoByYears() {
if (count == 0) {
printf("贷款信息为空!\n");
return;
}
int years;
printf("请输入贷款年限:");
scanf("%d", &years);
int num = 0;
for (int i = 0; i < count; i++) {
if (loan[i].years == years) {
num++;
}
}
printf("贷款年限为%d的人数为%d\n", years, num);
}
void modifyLoanInfoNameById() {
if (count == 0) {
printf("贷款信息为空!\n");
return;
}
int id;
printf("请输入贷款编号:");
scanf("%d", &id);
for (int i = 0; i < count; i++) {
if (loan[i].id == id) {
printf("请输入新的贷款人姓名:");
scanf("%s", loan[i].name);
printf("贷款人姓名修改成功!\n");
return;
}
}
printf("未找到该贷款信息!\n");
}
void sortLoanInfoByAmount() {
if (count == 0) {
printf("贷款信息为空!\n");
return;
}
for (int i = 0; i < count - 1; i++) {
for (int j = 0; j < count - i - 1; j++) {
if (loan[j].amount > loan[j + 1].amount) {
struct LoanInfo temp = loan[j];
loan[j] = loan[j + 1];
loan[j + 1] = temp;
}
}
}
printf("按照“贷款金额”升序排序成功!\n");
}
void deleteLoanInfoById() {
if (count == 0) {
printf("贷款信息为空!\n");
return;
}
int id;
printf("请输入贷款编号:");
scanf("%d", &id);
for (int i = 0; i < count; i++) {
if (loan[i].id == id) {
for (int j = i; j < count - 1; j++) {
loan[j] = loan[j + 1];
}
count--;
printf("贷款信息删除成功!\n");
return;
}
}
printf("未找到该贷款信息!\n");
}
阅读全文