Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Account.h #include class Account { public: // member functions accessible by anyone Account(std::string, int); Account(); void deposit(int); void withdraw(int); int getBalance() const; void setName(std::string); std::string
Account.h
#includeclass Account { public: // member functions accessible by anyone Account(std::string, int); Account(); void deposit(int); void withdraw(int); int getBalance() const; void setName(std::string); std::string getName() const; void accountInfo() const; private: // data members only accessible by member functions // (and "friend" functions/classes) std::string name; int balance{0}; // default initial value };
Account.cpp
#include#include "Account.h" Account::Account(std::string accountName, int startingBalance) : name{accountName} // member initializer list { if (startingBalance > 0){ balance = startingBalance; } } // default constructor Account::Account() {} // function to add to balance void Account::deposit(int depositAmount){ if (depositAmount > 0){ balance += depositAmount; } } // function to reduce balance void Account::withdraw(int withdrawAmount){ if (withdrawAmount > 0){ if (withdrawAmount
main.cpp
#includeCSCI 272-Spring 2019 Lab 2- Classes and Streams - 15 pts Start with the Account.h, Account.cpp and main.cpp files modified in class. 2.la Add data validation to all input of integers in main.cpp. If the user enters a character instead of an integer value, clear the failed input stream and ignore the rest of the characters in the input stream. Reprompt the user to enter an integer. 2.1b Test your validation code by entering characters instead of numbers when prompted fora deposit or withdrawal amount. You should be reprompted to enter an amount. 2.2a Add an accountStatement function to the Account class that will print the name of the account and all the stored transactions in order. Next to each transaction, include a text label that indicates whether it is a deposit or a withdrawal transaction. 2.2b Test your accountStatement function after creating several deposit and withdraw transactions for the account#include #include "Account.h" using namespace std; int main() { Account accountA("John Doe", 100); Account accountB("Jane Doe", -100); //Account accountA; //Account accountB; // display initial information accountA.accountInfo(); accountB.accountInfo(); int depositAmt; cout > depositAmt; accountA.deposit(depositAmt); // use member function cout > depositAmt; accountB.deposit(depositAmt); // use member function // display updated information accountA.accountInfo(); accountB.accountInfo(); int withdrawAmount; cout > withdrawAmount; accountA.withdraw(withdrawAmount); // use member function cout > withdrawAmount; accountB.withdraw(withdrawAmount); // use member function // display updated information accountA.accountInfo(); accountB.accountInfo(); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started