Question

In: Computer Science

Needed in C++ In this assignment, you are asked to create a class called Account, which...

Needed in C++

In this assignment, you are asked to create a class called Account, which models a bank account. The requirement of the account class is as follows

(1) It contains two data members: accountNumber and balance, which maintains the current account name and balance, respectively.

(1) It contains three functions: functions credit() and debit(), which adds or subtracts the given amount from the balance, respectively. The debit() function shall print ”amount withdrawn exceeds the current balance!” if the amount is more than balance. A function print(), which shall print ”A/C no: xxx Balance=xxx” (e.g., A/C no: 991234 Balance=$88.88), with balance rounded to two decimal places.

When you submit your code, please upload your class code(s) and your test code to prove that your code works correctly.

Solutions

Expert Solution

#include<iostream>
#include<stdlib.h>
#include<iomanip>
using namespace std;
//class account
class Account
{
   private:
       long int accountNumber;
       double balance;
   public:
       Account(); //constructor to assign the account number
       void credit(); //method credit
       void debit(); //method debit
       void print();//method print
};
//constructor
Account :: Account()
{
    //generate a random number and assign to accountnumber
    accountNumber = rand() % 9900000 + 99999;
}
//credit method
void Account :: credit()
{
    double amt;
    cout<<endl<<"Enter the amount to deposit";
    cin>>amt; //input the amount to ccredit
    if(amt>0)
    {   
           balance = balance + amt; //update the amount
           cout<<endl<<"Your account credited $"<<amt<<" successfully";
       }

    else
    cout<<endl<<"Invalid amount";
   
}
//debit method
void Account :: debit()
{
   double amt;
   cout<<endl<<"Enter the amount to withdraw";
   cin>>amt; //input the amount to withdraw
   if(amt>balance) //check the validity of amount
   {
      cout<<endl<<"Amount withdrawn exceeds the current balance";
       }
       else
       balance= balance-amt;//update the balance
   }
   //print method
   void Account :: print()
   {
      //print the details
      cout<<endl<<"Account Number : "<<accountNumber;
      cout<<endl<<"Balance in account : $"<<fixed<<setprecision(2)<<balance;
   }
   //driver program
   int main()
   {
       Account aobj; //create object
       int opt;
       //infinite loop
       while(1)
       { //display menu
           cout<<endl<<" 1. CREDIT\n 2. DEBIT\n 3. PRINT \n 4.EXIT";
           cout<<endl<<"Enter your choice : ";
           cin>>opt;
           if(opt==1) //option for credit
           aobj.credit();
           else
               if(opt==2) //option for debit
               aobj.debit();
               else
               if(opt==3) //option for print
               aobj.print();
               else
               if(opt==4) //option for exit
               exit(0);
               else
               cout<<endl<<"Invalid Choice";
           }
   }

OUTPUT


Related Solutions

In this assignment you create a small project with a base class 'Account' which represents a...
In this assignment you create a small project with a base class 'Account' which represents a generic account independent of whether the account is a Client or Vendor or Bank account. Then we will define a derived class 'BankAccount' class that represents the bank account. The BankAccount class is derived from the Account class, and extends the Account class functionality. The functionality of the BankAccount class is to handle deposits and withdrawals. You create a base class called Account and...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This class should contain information of a single student. last name, first name, credits, gpa, date of birth, matriculation date, ** you need accessor and mutator functions. You need a constructor that initializes a student by accepting all parameters. You need a default constructor that initializes everything to default values. write the entire program.
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main()...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main() function to coordinate the execution of the program. We will need methods: Method for Depositing values into the account. What type of method will it be? Method for Withdrawing values from the account. What type of method will it be? Method to output the balance of the account. What type of method will it be? Method that will output all deposits made to the...
Create a C# Application. Create a class object called “Employee” which includes the following private variables:...
Create a C# Application. Create a class object called “Employee” which includes the following private variables: firstN lastN idNum wage: holds how much the person makes per hour weekHrsWkd: holds how many total hours the person worked each week regHrsAmt: initialize to a fixed amount of 40 using constructor. regPay otPay After going over the regular hours, the employee gets 1.5x the wage for each additional hour worked. Methods: constructor properties CalcPay(): Calculate the regular pay and overtime pay. Create...
Create a new class called Account with a main method that contains the following: • A...
Create a new class called Account with a main method that contains the following: • A static variable called numAccounts, initialized to 0. • A constructor method that will add 1 to the numAccounts variable each time a new Account object is created. • A static method called getNumAccounts(). It should return numAccounts. Test the functionality in the main method of Account by creating a few Account objects, then print out the number of accounts
The Account class Create a class named Account, which has the following private properties:
in java The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber (), getBalance (), setBalan newBalance). There is no setNumber () once an account is created, its account number cannot change. Now implement these methods: void deposit (double amount) and void withdraw (double amount). For both these methods, if the amount is less than...
The Account class Create a class named Account , which has the following private properties:
 The Account class Create a class named Account , which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNunber(), getBalance(), setBalance (double newBalance) . There is no setNunber() - once an account is created, its account number cannot change. Now implement these methods: void deposit (double anount) and void withdraw(double anount). For both these methods, if the amount is less than zero,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) id: String   (5 pts) hours: int   (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception...
The Account class Create a class named Account, which has the following private properties: number: long...
The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement deposit(double amount) and withdraw(double amount) methods. If the amount is less than zero,...
The Account class Create a class named Account, which has the following private properties: number: long...
The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement deposit(double amount) and withdraw(double amount) methods. If the amount is less than zero,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT