Question

Create a class named UserAccounts that defines an array of 8 accounts as an instance variable. In the default constructor of this class, write a loop that creates 8 accounts with ids 1 through 7 and initial balance of $50 for each account. Store these accounts in the array.
When the program runs, it asks the use to enter a specific id. When the user enters a correct id, the system displays a menu as shown in the sample run below. The menu options are self explanatory. Option 4 exits the main menu. So if option 4 was chosen, the system will prompt the use again to enter another id. This means that the system will keep running indefinitely.

Sample Run:

Enter an id: 3 Main menu 1: check balance 2: withdraw 3 deposit 4:exit Enter a choice: 1 The balance is 5Θ.Θ Main menu 1: check balance 2: withdraw 3 deposit 4: exit Enter a choice: 2 Enter an amount to withdraw: 25 Main menu 1: check balance 2: withdraw 3 deposit 4: exit Enter a choice: 1 The balance is 25.Θ Main menu 1: check balance 2: withdraw 3 deposit 4: exit Enter a choice: 3 Enter an amount to deposit: 1Θ Main menu 1: check balance 2: withdraw 3 deposit 4: exit Enter a choice: 1 The balance is 35.e Main menu 1: check balance 2: withdraw 3: deposit 4: exit Enter a choice: 4 Enter an id:

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I was using GCC so i could not use cin and cout functions, instead i have used printf and scanf. You can change the same if you want to:

Source Code:

#include<stdio.h>

class UserAccounts{

   public:
       int id;
       double balance;
      
};

int main(){
   UserAccounts customer[8];
   int i, custId, choice;
   double remBal;
   char ch;
   for(i = 0 ; i < 8 ; i++){
       customer[i].id = i+1;
       customer[i].balance = 50.0;
   }
  
       printf( "Enter id: ");
       scanf( "%d",&custId);
      
       if(custId < 0 || custId > 9){
           printf( "Invalid id !");
           return -1;
       }
      
   do{  
       double withdraw, deposit;
       printf( "Main Menu\n1. Check balance\n2.Withdraw\n3.Deposit \n4.Exit\nEnter a choice: ");
       scanf( "%d", &choice);
       printf("\n");
      
       switch(choice){
           case 1:
               printf( "The balance is: %.2lf" , customer[custId].balance);
               break;
              
           case 2:
               printf( "Enter an amount to withdraw: ");
               scanf( "%lf", &withdraw);
               remBal = customer[custId].balance - withdraw;
               if(remBal < 0){
                   printf("Insufficient balance !!");
                   break;
               }else{
                   customer[custId].balance -= withdraw;
               }
               break;
              
           case 3:
               printf( "Enter amount you want to deposit:" );
               scanf( "%lf",&deposit);
               customer[custId].balance += deposit;
               break;
              
           case 4:
               printf( "Bye !!");
               break;
       }
      
       while(getchar() != '\n');               // flush the stream
       printf("\n\nDo you want to continue?(y/n): ");
       scanf( "%c", &ch);
   }while(ch == 'y' || ch == 'Y');
  
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Create a class named UserAccounts that defines an array of 8 accounts as an instance variable....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • this is for java programming Please use comments Use the Account class created in homework 8_2...

    this is for java programming Please use comments Use the Account class created in homework 8_2 to simulate an ATM machine. Create ten checking accounts in an array with id 0, 1, …, 9, initial balance of $100, and annualInterestRate of 0. The system prompts the user to enter an id between 0 and 9, or 999 to exit the program. If the id is invalid (not an integer between 0 and 9), ask the user to enter a valid...

  • answer in c++ code. use comments when writing the code to know what's your thinking. there is three pictures with information Write a C++ console program that defines and utilizes a cl...

    answer in c++ code. use comments when writing the code to know what's your thinking. there is three pictures with information Write a C++ console program that defines and utilizes a class named ATM. This program will demonstrate a composition relationship among classes because an ATM can contain many Accounts. You will need to reuse/modify the Account class you created in Assignment 10. The default constructor for the ATM class should initialize a private vector of 10 accounts, each with...

  • I need to write a java program call atm machine. Simulate An Atm Machine. create 10...

    I need to write a java program call atm machine. Simulate An Atm Machine. create 10 accounts in an array with id,…,9 and an initial balance of $100. The Systems Prompts the user to enter an id. If the id is entered incorrectly it will ask the user to enter a correct id. Once an id is accepted, the main menu is displayed as shown in the sample run. You can choice 1 for viewing the current balance, 2 for...

  • Banking System (Java Programming) 1 bank (Bank) has 5 accounts holder (Account) also designing te...

    Banking System (Java Programming) 1 bank (Bank) has 5 accounts holder (Account) also designing textbased menu (switch case): Main Menu: 1. Admin Login 2. User Login 3. Exit Admin Menu: 1. Add an Account 2. Remove an Account 3. Print total balance 4. Print total balance per city 5. Go back to main menu User Login 1. Withdraw //also redo last withdraw 2. Deposit //also redo last deposit 3. print account 4. Go back to main menu Designing class Account...

  • C++ Design a class bankAccount that defines a bank account as an ADT and implements the...

    C++ Design a class bankAccount that defines a bank account as an ADT and implements the basic properties of a bank account. The program will be an interactive, menu-driven program. a. Each object of the class bankAccount will hold the following information about an account: account holder’s name account number balance interest rate The data members MUST be private. Create an array of the bankAccount class that can hold up to 20 class objects. b. Include the member functions to...

  • 1. Create a String variable named menuChoice. 2. Display 3 options for your program. I recommend...

    1. Create a String variable named menuChoice. 2. Display 3 options for your program. I recommend using 3 System.out.println statements and a 4th System.out.print to show "Enter your Selection:". This needs to be inside the do -- while loop. A. Deposit Cash. B. Withdraw Cash X. Exit Enter your Selection: 3. Prompt for the value menuChoice. 4. If menuChoice is "A", display "Do Deposit" and redisplay the menu. If menuChoice is "B", display "Do withdrawal" and redisplay the menu. If...

  • Trying to figure out how to complete my fourth case 4 (option exit), write a function...

    Trying to figure out how to complete my fourth case 4 (option exit), write a function that display a “Good Bye” message and exits/log out from user’s account displaying a menu (sign in, balance, withdraw and exit.. #include<iostream> #include <limits> using namespace std; void printstar(char ch , int n); double balance1; int main() { system("color A0"); cout<<"\n\t\t ========================================="<< endl; cout<<"\t\t || VASQUEZ ATM SERVICES ||"<< endl; cout<<"\t\t ========================================\n\n"<< endl; int password; int pincode ; cout<<" USERS \n"; cout<<" [1] -...

  • Create a class named Program10. Your program should have the following 4 methods (other helper methods...

    Create a class named Program10. Your program should have the following 4 methods (other helper methods are allowed, but these four methods must be implemented as specified). You need to define a global scanner object and only use it inside the main method and the getValues method, since other methods do not get any values from the input. getValues: This method does not have any input parameter and returns an array of integers. This method prompts the user with a...

  • Please i need the .H, .cpp and main.cpp files. Please use vector. its for my midterm so correct code that can run only....

    Please i need the .H, .cpp and main.cpp files. Please use vector. its for my midterm so correct code that can run only. Thank you. Pointers and Dynamic Memory – Chapter 11 1. Write code using pointers and the Accounts class from week 1 assignment as follows – create a program in which you a. Create 10 accounts using an array with id’s 0 to 9 and refer to each account using pointer notation b. Add an initial balance of...

  • Textual menus work by showing text items where each item is numbered. The menu would have...

    Textual menus work by showing text items where each item is numbered. The menu would have items 1 to n. The user makes a choice, then that causes a function to run, given the user made a valid choice. If the choice is invalid an error message is shown. Whatever choices was made, after the action of that choice happens, the menu repeats, unless the menu option is to quit. Such kind of menus are displayed from the code under...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT