In: Computer Science
11.7: Customer Accounts
Write a program that uses a structure to store the following data
about a customer account:
Customer name
Customer address
City
State
ZIP code
Telephone
Account balance
Date of last payment
The program should use an array of at least 20 structures. It should let the user enter data into the array, change the contents of any element, and display all the data stored in the array. The program should have a menu-driven user interface.
Prompts And Output Labels. Your main menu
should be the following:
1. Enter new account
information
2. Change account information
3. Display all account
information
4. Exit the program
The user is expected to enter 1 or 2 or 3 or 4.
The main menu is displayed at the start of the program and after
the handling of choices 1, 2, and 3.
If 1 is entered for the main menu, the program
prompts for each of the data listed above, in the order listed
above, using the above data descriptions (e.g. "ZIP code") as
prompts (followed in each case by a colon). After reading in and
processing the data, the program prints
You have entered information for
customer number X
where X is the customer number: 0 for the first customer and
increasing by 1 for each subsequent customer that is entered.
If 2 is entered for the main menu, the program
prompts for the customer number:
Customer number:
Upon entering a valid customer number the program displays all the
data for the particular customer that has been saved:
Customer name: ...
Customer address: ...
City: ...
State: ...
ZIP code: ...
Telephone: ...
Account balance: ...
Date of last payment: ...
The program then skips one or two lines and prompts for a change,
using the same prompts as in choice 1 above for
all the data items associated with a customer.
If 3 is entered for the main menu, the program
displays all the data for each customer that has been saved, using
the display format in choice 2 above. After the
display of each customer, the program prompts "Press enter to
continue..." and waits for the user to hit return.
If 4 is entered for the main menu, the program
terminates.
Input Validation (OPTIONAL). When the data for a new account is entered, be sure the user enters data for all the fields. No negative account balances should be entered.
the language used is c language
The code is as follows :
#include <stdio.h>
#define SIZE 20
struct customer // customer structure
{
char name[20];
char address[20];
char city[20];
char state[20];
int zipcode;
int id;
int telephone;
double accbalance;
int date;
};
int main() {
int option = 0; //variable used for choice
int i = 0;
int store = 0;
struct customer cust[SIZE] = {0}; //variable for the customer structure
int searchnm = 0;
int storeThenm = 0;
do {
/*choice's for customer*/
printf("1. Enter new account Information\n");
printf("2. Change account Information\n");
printf("3. Display all account information\n");
printf("4. Exit the program\n\n");
printf("Enter your Choice: ");
scanf("%d", &option);
printf("\n");
switch (option) {
case 1: // adding the customer data
printf("----------------Add Customer Information-----------------\n");
if (store < SIZE)
{
printf("Enter Customer ID: ");
scanf("%d", &cust[store].id);
printf("Enter Customer name: ");
scanf("%s", &cust[store].name);
printf("Enter Customer Address: ");
scanf("%s", &cust[store].address);
printf("Enter Customer City: ");
scanf("%s", &cust[store].city);
printf("Enter Customer State: ");
scanf("%s", &cust[store].state);
printf("Enter Customer ZIPcode: ");
scanf("%d", &cust[store].zipcode);
printf("Enter Customer Telephone: ");
scanf("%d", &cust[store].telephone);
printf("Enter Customer Account Balance: ");
scanf("%lf", &cust[store].accbalance);
printf("Enter Customer Date of last payment: ");
scanf("%d", &cust[store].date);
printf("\n");
store++;
}
else {
printf("limit exeed \n");
printf("\n");
}
break;
case 2: //updating the customer data
printf("-----------------Update Customer Information-------------------------\n");
do {
printf("Enter Customer ID which need to be update: ");
scanf("%d", &searchnm);
for (i = 0; i < SIZE; i++)
{
if (searchnm == cust[i].id)
{
storeThenm = i;
}
}
} while (storeThenm < 0);
printf("------------------Customer's New Information-------------------------\n ");
printf("Enter Customer ID: ");
scanf("%d", &cust[storeThenm].id);
printf("Enter Customer name: ");
scanf("%s", &cust[storeThenm].name);
printf("Enter Customer Address: ");
scanf("%s", &cust[storeThenm].address);
printf("Enter Customer City: ");
scanf("%s", &cust[storeThenm].city);
printf("Enter Customer State: ");
scanf("%s", &cust[storeThenm].state);
printf("Enter Customer ZIPcode: ");
scanf("%d", &cust[storeThenm].zipcode);
printf("Enter Customer Telephone: ");
scanf("%d", &cust[storeThenm].telephone);
printf("Enter Customer Account Balance: ");
scanf("%lf", &cust[storeThenm].accbalance);
printf("Enter Customer Date of last payment: ");
scanf("%d", &cust[storeThenm].date);
printf("\n");
break;
case 3: //displaying the customer data
printf("------------------Display Customer Information---------------------------\n");
printf("\n");
printf("ID NAME ADDRESS CITY STATE ZIPCODE PHONE BALANCE DATE\n");
printf("== ==== ======= ==== ===== ======= ===== ======= ====\n");
for (i = 0; i < SIZE; i++)
{
printf("%d\t%s\t%s\t%s\t%s\t%d\t%d\t%lf\t%d\t",cust[i].id,cust[i].name,cust[i].address,cust[i].city,cust[i].state,cust[i].zipcode,cust[i].telephone,cust[i].accbalance,cust[i].date);
printf("\n");
}
printf("\n");
break;
case 4: //exiting the code
printf("Exiting the program ....\n");
break;
default:
printf("error try again \n\n");
}
} while (option != 4);
return 0;
}
--------------------------------------------------------------------------------------------------------------------------------------
The output of code is :
the first image define the adding of the customer :
fig.1
the fig 2 define the adding record of 2nd customer
fig. 2
the fig.3 image define the display of data
fig. 3
the fig.4 define the update of record
fig. 4
the fig. 5 display the updated data
fig. 5
the fig.6 define the exit of code
fig.6