Question

In: Computer Science

11.7: Customer Accounts Write a program that uses a structure to store the following data about...

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.

Solutions

Expert Solution

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


Related Solutions

Write a program that uses a structure to store the following data about a customer account:...
Write a program that uses a structure to store the following data about a customer account: Name Address City, State and Zip Telephone number Account balance Date of last payment The program should use an array of at least 5 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 interface and use functions as appropriate. Input validation:...
Write a program that uses a structure to store the following weather data for a particular...
Write a program that uses a structure to store the following weather data for a particular month: Total Rainfall High Temperature Low Temperature Average Temperature. The program should have an array of 12 structures to hold weather data for an entire year. When the program runs, it should ask the user to enter data for each month. (The average temperature should be calculated.) Once the data are entered for all the months, the program should calculate and display the average...
Write a program that uses a structure to store the following data: (Remember to use proper...
Write a program that uses a structure to store the following data: (Remember to use proper formatting and code documentation) Member Name Description name student name idnum Student ID number Scores [NUM_TESTS] an array of test scores Average Average test score Grade Course grade Declare a global const directly above the struct declaration const int NUM_TESTS = 4; //a global constant The program should ask the user how many students there are and should then dynamically allocate an array of...
Write a program that does the following in C++ 1 ) Write the following store data...
Write a program that does the following in C++ 1 ) Write the following store data to a file (should be in main) DC Tourism Expenses 100.20 Revenue 200.50 Maryland Tourism Expenses 150.33 Revenue 210.33 Virginia Tourism Expenses 140.00 Revenue 230.00 2 ) Print the following heading: (should be in heading function) Store name | Profit [Note: use setw to make sure all your columns line up properly] 3 ) Read the store data for one store (should be in...
Write a program for a beauty store that uses an InputBox to ask the guest for...
Write a program for a beauty store that uses an InputBox to ask the guest for a membership code. Embed this in a Do loop so that the user has to keep trying until the result is a valid membership code that starts with “Beauty” (case insensitive) and is followed by 4 digits with the final digit equal to either 6 or 8. Then use a message box to display the input promotion code and inform the user that the...
Write a C program that will read different data types from the following file and store...
Write a C program that will read different data types from the following file and store it in the array of structures. Given file: (This file have more than 1000 lines of similar data): time latitude longitude depth mag magType nst gap dmin 2020-10-19T23:28:33.400Z 61.342 -147.3997 12.3 1.6 ml 12 84 0.00021 2020-10-19T23:26:49.460Z 38.838501 -122.82684 1.54 0.57 md 11 81 0.006757 2020-10-19T23:17:28.720Z 35.0501667 -117.6545 0.29 1.51 ml 17 77 0.1205 2020-10-19T22:47:44.770Z 38.187 -117.7385 10.8 1.5 ml 15 100.22 0.049 2020-10-19T22:42:26.224Z...
Write a program that uses the defined structure and all the above functions. Suppose that the...
Write a program that uses the defined structure and all the above functions. Suppose that the class has 20 students. Use an array of 20 components of type studentType. Other than declaring the variables and opening the input and output files, the function main should only be a collection of function calls. The program should output each student’s name followed by the test scores and the relevant grade. It should also find and print the highest test score and the...
Program must be in C++! Write a program which: Write a program which uses the following...
Program must be in C++! Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to...
Write a C++ program that uses array to store the salaries of 10 employees working in...
Write a C++ program that uses array to store the salaries of 10 employees working in a small firm. The program should take average of the salaries and the max and min salaries being paid to the employees
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest...
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Prompt the user for 12 months of highest and lowest.   Write two methods : one to calculate and return the average high and one to calculate and return the average low of the year. Your program should output all the values in the array and then output the average high and the average low. im trying to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT