用C语言完成下列习题 -------*-------*------- 试设计一数据结构,用来表示某一银行储户基本信息(信息包括:账号、姓名、开户年月日、储蓄类型、存入累加数、利息、帐面总数和存入记录等)。
时间: 2024-03-19 11:37:45 浏览: 35
为了表示银行储户的基本信息,可以使用结构体来定义一个数据结构。以下是一个示例的C语言代码:
```c
#include <stdio.h>
#include <string.h>
// 定义银行储户基本信息的结构体
struct BankAccount {
int accountNumber;
char name[50];
int year;
int month;
int day;
char savingsType[20];
double depositAmount;
double interest;
double totalAmount;
char depositRecord[100];
};
int main() {
// 创建一个银行储户对象
struct BankAccount customer;
// 初始化银行储户对象的基本信息
customer.accountNumber = 123456789;
strcpy(customer.name, "John Doe");
customer.year = 2022;
customer.month = 1;
customer.day = 1;
strcpy(customer.savingsType, "Fixed Deposit");
customer.depositAmount = 10000.0;
customer.interest = 0.05;
customer.totalAmount = customer.depositAmount + (customer.depositAmount * customer.interest);
strcpy(customer.depositRecord, "01/01/2022 - $10000");
// 输出银行储户对象的基本信息
printf("Account Number: %d\n", customer.accountNumber);
printf("Name: %s\n", customer.name);
printf("Date of Account Opening: %d/%d/%d\n", customer.year, customer.month, customer.day);
printf("Savings Type: %s\n", customer.savingsType);
printf("Deposit Amount: $%.2f\n", customer.depositAmount);
printf("Interest Rate: %.2f%%\n", customer.interest * 100); printf("Total Amount: $%.2f\n", customer.totalAmount);
printf("Deposit Record: %s\n", customer.depositRecord);
return 0;
}
```
这段代码定义了一个名为`BankAccount`的结构体,包含了银行储户的各种基本信息。在`main`函数中,我们创建了一个`BankAccount`类型的对象`customer`,并初始化了其基本信息。最后,通过`printf`函数输出了银行储户对象的基本信息。