Question

I need help modifying this code please ASAP using C++

Here is what I missed on this code below

Produce correct70 pts O pts Full Marks No Marks results and statisfy requirements view longer Comments 1. Your display amount

Here are the instructions

Purpose: Develop a program using the C++ class and inheritance Solve problems using Object Oriented Programming Use arrays, v

5. Show all transactions: The transactions must be shown with nice formatted column headings as follows: Date/Time Wed Apr 25

Here is the code

//MyBank.cpp #include<iostream> #include« string» #include«ctime> #include<vector> #include«exception» using namespace std; c

hi class BankAccount private: vector<transaction> transactions; string name double intialBalance; string openYear; double int

this->namename; string getName ) return this->name; void setInitialBalance (double bal)f this->intialBalance -bal; double get

(transaction trans) void addTransaction( this->transactions.push_back (trans) vector<transaction> getTransactios()f Or returnSavingAccount(string name, double initialBal, string year, double rate) BankAccount name, initialBal, year, rate) SavingAccouint count0; string password; while (count 3) cout<Please enter the password << endl; cin >>password; if (password.compare(

cout <<1. Open an accountIn cout<<2. Depositin cout<<3. Withdrawln cout<4. Show balance (including principal and inter

cin >year; cout <e Enter interest rate: .; cininterestRate; bankAccount.setName (name) bankAccount.setInitialBalance(initial

catch(std: :exception& e) //Other errors Helset time_t timer; tm time; std::time (&timer) time - localtime (&timer); transact

catch(BadInput& e) f std::cout<Bad Input caught << std::endl; std::cout << e.what) << std: :endl; catch(std: :exception& e)

case 5 bankAccount.showTransactions); break; case 6 cout<Enter interest rate: << endl; cin >> interestRate; 0){ if(intere

LeaK default: cout << Please enter valid choice <<endl break; if(choice-7) break; break the while loop return 0

Produce correct70 pts O pts Full Marks No Marks results and statisfy requirements view longer Comments 1. Your display amount is not readable 2. I withdraw more than my balance, but I didn't see any error message description Documentations10 pts 0 pts Full Marks No Marks : comment i code and block comment in function headers view longer description Comments You don't have any comments 10 pts O pts Good structured Full Marks No Marks and well designed. view longer description 10 pts O pts Turn in on-time Full Marks No Marks view longer description
Purpose: Develop a program using the C++ class and inheritance Solve problems using Object Oriented Programming Use arrays, vectors, strings, and files if needed Manipulate data by calling object's methods Use exception to handle errors Description: Write a C++ program named "MyBank" that provides the following options 1. Open an account 2. Deposit 3. Withdraw 4. Show balance (including principal and interest) 5. Show all transactions 6. Set interest rate 7. Exit At the beginning, the program asks the user for the password before proceeding The correct password is "abc123". If the user enters the wrong password 3 times, the program prints an error message and exit. Explanation of options 1. Open an account: the program asks the user to enter name, initial balance year open and interest rate. This option only works the first time (where is no account yet). If an account already exists and the user chooses this option, it's considered an error. The program should print an error message 2. Deposit: the program asks the user for amount and check to make sure the mount must be > 0. Otherwise, it throws an exception. You must define a user-defined exception. The program needs to keep track of the time and amount the user deposits money. If there is no account yet and the user enters this option, it's an error 3. Withdraw: the withdraw amount must be #include #include«exception» using namespace std; class BadInput public exception public: const char what) const throw )f return "Bad Input" ti struct transactiont string type double amount: tm *trans_time; transaction(string type, double amount, tm* transTime) type- type: amountamount; trans_timetransTime;
hi class BankAccount private: vector transactions; string name double intialBalance; string openYear; double interestRate; public: BankAccount BankAccount (string name, double initialBal, string year, double rate) this->namename initialBal; this->intialBalance - this->openYearyear this->interestRate-rate; BankAccount() void setName (string name)i
this->namename; string getName ) return this->name; void setInitialBalance (double bal)f this->intialBalance -bal; double getInitialBalance) return this->intialBalance; void setopenYear (string year)f this->openYear-year; string getOpenYear)i return this->openYear; void setInterestRate(double rate)f this->interestRate - rate; double getInterestRate)t return this->interestRate;
(transaction trans) void addTransaction( this->transactions.push_back (trans) vector getTransactios()f Or return this->transactions; void showTransactions ) cout
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note : I added few comments.I think there is some problem with the code which u posted ...I will fix it.Thank u

________________________

#include <iostream>
#include <string>
#include <ctime>
#include <vector>
#include <exception>

using namespace std;

/*
* Creating Exception class
*/
class BadInput : public exception
{
public :
const char * what () const throw ()
{
return "Bad Input";  
}  
};

/*
* Create transaction structure
*/
struct transaction
{
   //Declaring variables
   string type;
   double amount ;
   tm *trans_time;
   transaction(string type,double amount,tm* transTime)
   {
       type=type;
       amount=amount;
       trans_time=transTime;
   }
};
//Creating BankAccount class
class BankAccount
{
private :
    //Declaring instance variables
    vector<transaction> transactions;
    string name;
    double initialBalance;
    string openYear;
    double interestRate;
public :  
//Zero argumented Constructor
BankAccount()
{
  
   }
   //Parameterized Constructor
   BankAccount(string name,double initialBal,string year,double rate)
   {
       this->name=name;
       this->initialBalance=initialBal;
       this->openYear=year;
       this->interestRate=rate;
   }
   //Destructor
   ~BankAccount()
   {
      
   }
   //Setters and getters
   void setName(string name)
   {
       this->name=name;
   }
   string getName()
   {
       return this->name;
   }
   void setInitialBalance(double bal)
   {
       this->initialBalance=bal;
   }
   double getInitialBalance()
   {
       return this->initialBalance;
   }
   void setOpenYear(string year)
   {
       this->openYear =year;
   }
   string getOpenYear()
   {
       return this->openYear;
   }
   void setInterestRate(double rate)
   {
       this->interestRate=rate;
   }
   double getInterestRate()
   {
       return this->interestRate;
   }
   void addTransaction(transaction trans)
   {
       this->transactions.push_back(trans);
   }
   vector<transaction> getTransactions()
   {
       return this->transactions;
   }
   //This function will display the transactions
   void showTransactions()
   {
       cout<<"Transaction Type Amount DateTime :"<<endl;
       for(std::vector<transaction>::iterator it=transactions.begin(); it!=transactions.end();it++)
       {
           cout<<it->type<<"\t"<<it->amount<<"\t"<<it->trans_time<<endl;
       }
   }
};
//CreatinhSavingsAccount class
class SavingAccount : public BankAccount
{
private :
   //Declaring variables
   double accountBalance;
public :  
//Zero argumented constructor
SavingAccount()
{
  
   }
   //Parameterized constructor
   SavingAccount(string name,double initialBal,string year,double rate):BankAccount(name,initialBal,year,rate)
   {
      
   }
   //Destructor
   ~SavingAccount()
   {
      
   }
   //Getter
   double getAccountBalance()
   {
       return accountBalance;
   }
   //This function will add the amount to the balance
   void depositAmount(double amount)
   {
       this->accountBalance+=amount;
   }
       //This function will subtract the amount from the balance
   void withdrawAmount(double amount)
   {
       this->accountBalance-=amount;
   }
   void toString()
   {
       cout<<accountBalance<<endl;
   }
};
int main()
{
int count = 0;
string password;
while(count<3)
{
   cout<<"Please enter the password "<<endl;
   cin>>password;
   if(password.compare("abc123")==0)
   {
       break;
       }
       count++;
   }
   if(count==3)
   {
       cout<<"You entered 3 time wrong password.Account locked "<<endl;
       return 0;
   }
   else
   {
       bool isAccountOpened=false;
       string name,year;
       double initialBalance,interestRate,amount;
       SavingAccount bankAccount;
       while(true)
       {
           cout<<"1.Open an account\n";
           cout<<"2.Deposit\n";
           cout<<"3.withdraw\n";
           cout<<"4.Show balance (including principal and interest)\n";
           cout<<"5.Show all transactions\n";
           cout<<"6.Set Interest rate\n";
           cout<<"7.Exit\n";
           int choice;
           cout<<"Enter choice 1-7"<<endl;
           cin>>choice;
           switch(choice)
           {
               case 1:{
                   if(isAccountOpened)
                   {
                       cout<<"Error: Account already Opened"<<endl;
                       break;
                   }
                   cout<<"Enter name :";
                   cin>>name;
                  
                   cout<<"Enter initial Balance:";
                   cin>>initialBalance;
                   cout<<"Enter account open year:";
                   cin>>year;
                   cout<<"Enter interest rate:";
                   cin>>interestRate;
               bankAccount.setName(name);
               bankAccount.setInitialBalance(initialBalance);
               bankAccount.setOpenYear(year);
                   bankAccount.setInterestRate(interestRate);
                   isAccountOpened=true;
                  
               continue;
               }
               case 2:{
                   if(!isAccountOpened)
                   {
                       cout<<"Error: Account not opened yet"<<endl;
                       break;
                   }
                   cout<<"Enter amount to deposit:";
                   cin>>amount;
                   if(amount<0)
                   {
                       try{
                           throw BadInput();
                       }
                       catch(BadInput& e)
                       {
                           std::cout<<"Bad Input caught"<<std::endl;
                           std::cout<<e.what()<<std::endl;
                       }
                       catch(std::exception& e)
                       {
                          
                       }
                   }
                   else
                   {
                       time_t timer;
                       tm * time;
                       std::time(&timer);
                       time= localtime(&timer);
                       transaction trans("Deposit",amount,time);
                       bankAccount.addTransaction(trans);
                   }
                   continue;
               }
               case 3:{
                   if(!isAccountOpened)
                   {
                       cout<<"Error : Account not opened yet "<<endl;
                       break;
                   }
                   cout<<"Enter amount to withdraw:";
                   cin>>amount;
                   if(amount<0)
                   {
                       try
                       {
                           throw BadInput();
                          
                       }
                           catch(BadInput& e)
                       {
                           std::cout<<"Bad Input caught"<<std::endl;
                           std::cout<<e.what()<<std::endl;
                       }
                       catch(std::exception& e)
                       {
                          
                       }
                   }
                   else
                   {
                       time_t timer;
                       tm * time;
                       std::time(&timer);
                       time=localtime(&timer);
                       transaction trans("Withdraw",amount,time);
                       bankAccount.addTransaction(trans);
                      
                   }
                   continue;
               }
               case 4:{
                   if(!isAccountOpened)
                   {
                       cout<<"Error : Account not opened yet"<<endl;
                       break;
                   }
                   bankAccount.toString();
               continue;
              
               }
               case 5:{
                   bankAccount.showTransactions();
                   continue;
                  
               }
               case 6:{
                   cout<<"Enter interest rate :"<<endl;
                   cin>>interestRate;
                   if(interestRate<0)
                   {
                       try
                       {
                           throw BadInput();
                       }
                           catch(BadInput& e)
                       {
                           std::cout<<"Bad Input caught"<<std::endl;
                           std::cout<<e.what()<<std::endl;
                       }
                       catch(std::exception& e)
                       {
                          
                       }
                       break;
                   }
                   bankAccount.setInterestRate(interestRate);
                   continue;
               }
               case 7:{
                  
                   break;
               }
               default:{
                   cout<<"Please enter valid choice"<<endl;
                   continue;
               }
           }
           break;
       }
   }

return 0;
}

________________________

Add a comment
Know the answer?
Add Answer to:
I need help modifying this code please ASAP using C++ Here is what I missed on this code below Here are the instruction...
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
  • C++ Help. PLEASE include detailed comments and explanations. PLEASE follow the drections exactly. Thank you. Define...

    C++ Help. PLEASE include detailed comments and explanations. PLEASE follow the drections exactly. Thank you. Define a class with the name BankAccount and the following members: Data Members: accountBalance: balance held in the account interestRate: annual interest rate. accountID: unique 3 digit account number assigned to each BankAccount object. Use a static data member to generate this unique account number for each BankAccount count: A static data member to track the count of the number of BankAccount objects created. Member...

  • I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7:...

    I need help with this code. I'm using C++ and Myprogramming lab to execute it. 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...

  • C++ Banks offer various types of accounts, such as savings, checking, certificate of deposits, and money...

    C++ Banks offer various types of accounts, such as savings, checking, certificate of deposits, and money market, to attract customers as well as meet their specific needs. Two of the most commonly used accounts are savings and checking. Each of these accounts has various options. For example, you may have a savings account that requires no minimum balance but has a lower interest rate. Similarly, you may have a checking account that limits the number of checks you may write....

  • How would I alter this code to have the output to show the exceptions for not...

    How would I alter this code to have the output to show the exceptions for not just the negative starting balance and negative interest rate but a negative deposit as well? Here is the class code for BankAccount: /** * This class simulates a bank account. */ public class BankAccount { private double balance; // Account balance private double interestRate; // Interest rate private double interest; // Interest earned /** * The constructor initializes the balance * and interestRate fields...

  • MAIN OBJECTIVE       Develop a polymorphic banking program using the Account hierarchy created (below). C++ Capture...

    MAIN OBJECTIVE       Develop a polymorphic banking program using the Account hierarchy created (below). C++ Capture an output. polymorphism. Write an application that creates a vector of Account pointers to two SavingsAccount and two CheckingAccountobjects. For each Account in the vector, allow the user to specify an amount of money to withdraw from the Account using member function debit and an amount of money to deposit into the Account using member function credit. As you process each Account, determine its...

  • Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string;...

    Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string; class Account { public: Account(); Account(string, double); void deposit(double); bool withdraw(double); string getName() const; double getBalance() const; private: string name; double balance; }; #endif ////////////////////////////////////////////// //AccountManager.hpp #ifndef _ACCOUNT_MANAGER_HPP_ #define _ACCOUNT_MANAGER_HPP_ #include "Account.hpp" #include <string> using std::string; class AccountManager { public: AccountManager(); AccountManager(const AccountManager&); //copy constructor void open(string); void close(string); void depositByName(string,double); bool withdrawByName(string,double); double getBalanceByName(string); Account getAccountByName(string); void openSuperVipAccount(Account&); void closeSuperVipAccount(); bool getBalanceOfSuperVipAccount(double&) const;...

  • 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...

  • I need to update the code listed below to meet the criteria listed on the bottom....

    I need to update the code listed below to meet the criteria listed on the bottom. I worked on it a little bit but I could still use some help/corrections! import java.util.Scanner; public class BankAccount { private int accountNo; private double balance; private String lastName; private String firstName; public BankAccount(String lname, String fname, int acctNo) { lastName = lname; firstName = fname; accountNo = acctNo; balance = 0.0; } public void deposit(int acctNo, double amount) { // This method is...

  • Requirements I have already build a hpp file for the class architecture, and your job is to imple...

    Requirements I have already build a hpp file for the class architecture, and your job is to implement the specific functions. In order to prevent name conflicts, I have already declared a namespace for payment system. There will be some more details: // username should be a combination of letters and numbers and the length should be in [6,20] // correct: ["Alice1995", "Heart2you", "love2you", "5201314"] // incorrect: ["222@_@222", "12306", "abc12?"] std::string username; // password should be a combination of letters...

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