I need help with the second part of my project! I also need this is be done in C
ID: 3772138 • Letter: I
Question
I need help with the second part of my project! I also need this is be done in C please!
Now it is time to consider more than one customer for the ATM application. We suppose that a customer has an account number (that we are going to use as personal identification number), a balance and a name. In this project, you’re asked to use a structure where every structure is containing the following fields:
Account as int
Balance as double
Name as an array of char
Here is a sample data:
Accounts Balances Names
1200457
1257441
8542212
6565741
1215478
John Smith
Safia Walter
Kevin Broke
Todd Rich
Laura Happy
1245.32
15.23
.21
55656.28
887.66
Suppose you’re in charge of this simulation and here is a scenario of what is required to do:
You will divide the application into two parts: part one is what the user will run and part two is what the banker will use.
First you display a message saying like :
Press 1 if your are a customer
Press 2 if you are the banker
P A R T T W O
In this part, you will implement what a banker might use to manage the database like:
displaying the list of customers
displaying the list of customers who are having balances greater than a certain value
Searching a customer
Sorting the list of customers by name, by account # or by balance
Deleting an account
Opening an account by adding a new customer
…
(Feel free to add other functionalities)
Sample execution for part two: bolded text represents the user entry
1-Display all customers
2-Display customer w/ balance greater than a value
3-Search
4-Sort
5-Delete an account
6-Add a new account
7-Exit
Your option here: 4
( clear screen )
a-sort by name
b-sort by account number
c-sort by balance
x- return main menu
Your option here: b
(clear screen )
Accounts Balances Names
8542212
1257441
1215478
1200457
6565741
Kevin Broke
Safia Walter
Laura Happy
John Smith
Todd Rich
.21
15.23
887.66
1245.32
55656.28
Hit any key to continue …
1.Display all customers
2.Display customer w/ balance greater than a value
3.Search
4.Sort
5.Delete an account
6.Add a new account
7.Exit
Your option here: 6
( clear screen )
Enter Account # : 12121212
Enter Name : Edgar Sanchez
Opening balance : 700.00
Customer Added to the database…
Hit any key to continue …
1.Display all customers
2.Display customer w/ balance greater than a value
3.Search
4.Sort
5.Delete an account
6.Add a new account
7.Exit
Your option here: 7
GOODBYE...
1200457
1257441
8542212
6565741
1215478
Explanation / Answer
I did everything except sorting due to lack of time. I hope this helps
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100
struct CUSTOMER {
int Account;
double Balance;
char Name[20];
};
int main(int argc, char const *argv[])
{
struct CUSTOMER customers[MAX];
int choice, i, numberOfAccounts = 0;
do {
printf("1-Display all customers ");
printf("2-Display customer w/ balance greater than a value ");
printf("3-Search ");
printf("4-Sort ");
printf("5-Delete an account ");
printf("6-Add a new account ");
printf("7-Exit ");
printf("Your option here: ");
scanf("%d", &choice);
switch (choice) {
case 1:
{
printf("1-Display all customers ");
for (i = 0; i < numberOfAccounts; i++) {
printf("%d %f %s ", customers[i].Account, customers[i].Balance, customers[i].Name);
}
break;
}
case 2:
{
printf("2-Display customer w/ balance greater than a value ");
printf("Enter the threshold value: ");
double thresholdBalance;
scanf("%lf", &thresholdBalance);
for (i = 0; i < numberOfAccounts; i++) {
if (customers[i].Balance > thresholdBalance)
printf("%d %f %s ", customers[i].Account, customers[i].Balance, customers[i].Name);
}
break;
}
case 3:
{
printf("3-Search ");
int accountSearch;
int flag = 0;
printf("Enter the account # to search: ");
scanf("%d", &accountSearch);
for (i = 0; i < numberOfAccounts; i++) {
if (customers[i].Account == accountSearch) {
flag = 1;
printf("%d %f %s ", customers[i].Account, customers[i].Balance, customers[i].Name);
break;
}
}
if (!flag)
printf("No such account found ");
break;
}
case 4:
{
printf("4-Sort ");
printf("a-sort by name ");
printf("b-sort by account number ");
printf("c-sort by balance ");
printf("x-return main menu ");
char c;
printf("Your option here: ");
scanf("%c", &c);
switch (c) {
case 'a':
break;
case 'b':
break;
case 'c':
break;
}
break;
}
case 5:
{
printf("5-Delete an account ");
int accountSearch, flag = 0;
printf("Enter the account # to delete: ");
scanf("%d", &accountSearch);
for (i = 0; i < numberOfAccounts; i++) {
if (customers[i].Account == accountSearch) {
flag = 1;
int j;
for (j = i; j < numberOfAccounts-1; j++) {
customers[j] = customers[j+1];
}
numberOfAccounts--;
break;
}
}
if (!flag)
printf("No such account found ");
break;
}
case 6:
{
printf("6-Add a new account ");
if (numberOfAccounts < 100) {
struct CUSTOMER newCustomer;
printf("Enter account # of new customer: ");
scanf("%d", &newCustomer.Account);
printf("Enter ac balance of new customer: ");
scanf("%lf *[^ ]", &newCustomer.Balance);
printf("Enter name of new customer: ");
fgets(newCustomer.Name, sizeof(newCustomer.Name), stdin);
customers[numberOfAccounts++] = newCustomer;
printf("Customer added to database ");
}
else {
printf("Max limit of database reached ");
}
}
}
} while (choice != 7);
return 0;
}