Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include class Account { public: // member functions accessible by anyone // custom constructor Account(std::string accountName, int startingBalance) : name{accountName} // member initializer list {

image text in transcribed

#include  class Account { public: // member functions accessible by anyone // custom constructor Account(std::string accountName, int startingBalance) : name{accountName} // member initializer list { if (startingBalance > 0){ balance = startingBalance; } } // default constructor Account() {} // function to add to balance void deposit(int depositAmount){ if (depositAmount > 0){ balance += depositAmount; } } // function to return current balance int getBalance() const { return balance; } // function to set the value of the name void setName(std::string accountName){ name = accountName; } // function to get the value of the name // const -- function cannot modify name std::string getName() const { return name; } private: // data members only accessible by member functions // (and "friend" functions/classes) std::string name; int balance{0}; // default initial value }; 
 #include  #include  #include "Account.h" using namespace std; int main() { Account accountA{"John Doe", 100}; Account accountB{"Jane Doe", -100}; // display initial information cout > depositAmt; accountA.deposit(depositAmt); // use member function cout > depositAmt; accountB.deposit(depositAmt); // use member function // display updated information cout   CSCI 272-Spring 2019 Start with the Account.h and main.cpp files developed in class. 1.1a Add a member function withdraw to the Account class. This function will take one Lab 1 - Introduction to Classes 15 ps parameter for a withdrawal amount. The function should: compare the withdrawal amount passed in to the function to the account's balance if the account balance is greater than or equal to the withdrawal amount, subtract th withdrawal amount from the balance otherwise, display a message that the withdrawal amount is greater than the balance o o 1.1b Test the new withdraw function by modifying the main function code in main.cpp .Print out the balance of the account .Use a withdrawal amount greater than the current balance Print out the balance of the account o Expected result: The balance should be unchanged .Use a withdrawal amount less than the current balance Print out the balance of the account Expected result: The balance should be lowered by the withdrawal amount o Use a withdrawal amount equal to the current balance Print out the balance of the account Expected result: The balance should now be 0. o 1.2a Add a member function accountInfo to the Account class. This function will take no parameters. The function should: call the getName and getBalance functions and print out the results how the information is printed is up to you, but both the name and balance values should display, along with some descriptive text . .for example Account Name: John Doe Balance: $ 100 1.2b Test the new accountlnfo function by modifying the main function code in main.coD. Replace the individual calls to the getName and getBalance functions with a call to accountlnfo

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 12c SQL

Authors: Joan Casteel

3rd edition

1305251032, 978-1305251038

More Books

Students also viewed these Databases questions

Question

=+j Describe the various support services delivered by IHR.

Answered: 1 week ago