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