Question: Please write Narratives and Pseudocodes for the following code below. Please Type it not write. Thank You. #include #include #include #include struct Customer{ char banknumber[10];
Please write Narratives and Pseudocodes for the following code below. Please Type it not write. Thank You.
#include
struct Customer{ char banknumber[10]; char firstname[20]; char lastname[20]; char ssnumber[20]; char dob[10]; int age; char nationality[20]; char password[20]; int balance; };
//Declare an array of 10 Customers struct Customer customers[10]; int total = 0;
int authentication(); void welcomeCustomer(int i); int askUserChoice1(); int askUserChoice2(); void addNewCustomer(); void showCustomer(int i); void showAccountBalance(int i); void depositMoney(int i); void withdrawMoney(int i); void goodbyeCustomer(int i);
int main() { int user; int choice = 1; while(choice != 0){ choice = askUserChoice1(); switch(choice){ case 1: user = authentication(); if(user == -1) continue; welcomeCustomer(user); while (choice != 0){ choice = askUserChoice2(); switch (choice){ case 1: showCustomer(user); break; case 2: showAccountBalance(user); break; case 3: depositMoney(user); break; case 4: withdrawMoney(user); break; case 0: goodbyeCustomer(user); break; } } choice = 1; break; case 2: addNewCustomer(); break; } } return 0; }
int askUserChoice1(){ int choice = 0; do{ printf(" 1. Login "); printf(" 2. Add new Customer "); printf(" 0. Exit "); printf(" Enter Your Choice: "); scanf("%d", &choice); } while (choice < 0 || choice > 2); return choice; }
int askUserChoice2(){ int choice = 0; do{ printf(" 1. Show My Details "); printf(" 2. Show My Account Balance "); printf(" 3. Deposit money "); printf(" 4. Withdraw money "); printf(" 0. Log out "); printf(" Enter Your Choice: "); scanf("%d", &choice); } while (choice < 0 || choice > 4); return choice; }
int authentication(){ int i; char username[20]; char password[20]; printf("Enter Username: "); scanf("%s", username); for(i = 0; i < total; i++){ if(strcmp(customers[i].banknumber, username) == 0){ printf("Enter Password: "); scanf("%s", password); if(strcmp(customers[i].password, password)==0){ printf("Login Successful "); return i; } else{ printf("Wrong password "); return -1; } } }
printf("User not found "); return -1; }
void welcomeCustomer(int i){ printf("Welcome %s ! ", customers[i].firstname); }
void addNewCustomer(){ char temp[20]; int i, used; char ch; printf("Enter First Name : "); scanf("%s", customers[total].firstname); printf("Enter Last Name : "); scanf("%s", customers[total].lastname); printf("Enter Social Security Number: "); scanf("%s", customers[total].ssnumber); printf("Enter Date Of Birth : "); scanf("%s", customers[total].dob); printf("Enter Age : "); scanf("%d", &customers[total].age); printf("Enter Nationality : "); scanf("%s", customers[total].nationality); printf("Enter Password : "); for(i = 0; i < 20; i++){ ch = getch(); if(ch == 13) break; customers[total].password[i] = ch; ch = '*'; printf("%c", ch); } customers[total].password[i] = '\0'; //scanf("%s", customers[total].password); printf(" Enter Confirm Password : "); for(i = 0; i < 20; i++){ ch = getch(); if(ch == 13) break; temp[i] = ch; ch = '*'; printf("%c", ch); } temp[i] = '\0'; if(strcmp(customers[total].password, temp) != 0){ printf("Password does not match "); return; } printf(" Enter Account Balance : "); scanf("%d", &customers[total].balance); used = 1; while(used){ if(customers[total].firstname[0] >= 'A' && customers[total].firstname[0] <= 'Z') temp[0] = customers[total].firstname[0] + 32; else temp[0] = customers[total].firstname[0]; if(customers[total].lastname[0] >= 'A' && customers[total].lastname[0] <= 'Z') temp[1] = customers[total].lastname[0] + 32; else temp[1] = customers[total].lastname[0]; temp[2] = (char)(rand() % 10 + 48); temp[3] = (char)(rand() % 10 + 48); temp[4] = '\0'; used = 0; for(i = 0; i < total; i++){ if(strcmp(customers[i].banknumber, temp) == 0) used = 1; } } strcpy(customers[total].banknumber, temp); printf("New Customer added! Your Customer Number: %s ", customers[total].banknumber); total++; }
void showCustomer(int i){ printf("\tBank Number : %s ", customers[i].banknumber); printf("\tFirst Name : %s ", customers[i].firstname); printf("\tLast Name : %s ", customers[i].lastname); printf("\tSocial Security Number: %s ", customers[i].ssnumber); printf("\tDate Of Birth : %s ", customers[i].dob); printf("\tAge : %d ", customers[i].age); printf("\tNationality : %s ", customers[i].nationality); }
void showAccountBalance(int i){ printf("Your Account Balance: %d ", customers[i].balance); }
void depositMoney(int i){ int amount; printf("Enter Deposit Amount: "); scanf("%d", &amount); customers[i].balance += amount; }
void withdrawMoney(int i){ int amount; printf("Enter Withdrawal Amount: "); scanf("%d", &amount); if(customers[i].balance < amount){ printf("You do not have sufficient balance "); return; } customers[i].balance -= amount; }
void goodbyeCustomer(int i){ printf("Goodbye, and come again %s ", customers[i].firstname); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
