I need help modifying this code please ASAP using C++
Here is what I missed on this code below
Here are the instructions
Here is the code
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;
}
________________________
I need help modifying this code please ASAP using C++ Here is what I missed on this code below Here are the instruction...
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: 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 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 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 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; 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 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 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 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...