Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Could you please help me with my C++ and Object Oriented Programming homework question. 2-1 - Encapsulation (1pt) Implement a class called Account that contains
Could you please help me with my C++ and Object Oriented Programming homework question.
2-1 - Encapsulation (1pt) Implement a class called Account that contains the following attributes and behaviours: // Variables, both should be private double balance; std: : string accName; // Constructors Account() ; Account (std: : string name) ; // Methods void deposit(int amount); // Deposit amount into balance, only if amount is non-negative bool withdraw(int amount); // Withdraw amount from balance, see description for details void applyInterest(double interest); // Applies interest to account void printInfo(); // Prints account info as per format in description The method deposit(int) should only modify balance if passed amount is non-negative. withdraw(int) should only modify balance if passed amount is non-negative and the resulting balance is non-negative, this method should also return true if the withdrawal was successful and false otherwise. applyInterest(double) should increase balance by the passed interest. For example: if balance was 100 and the method was called like a. applyInterest(0.1), i.e. 0.1 = 10%, balance should then be 110. printInfo() should print in the format "Name: accName, Balance balance", for example if accName was "Rhys" and balance was 100: Name: Rhys, Balance: 100 including a newline at the end. Submit your class definition in a file called Account.h and your class implementation in a file called Account.cpp Marking criteria: o Correct files present: 0.1pt . Successfully compiled: 0.1pts Successful test: 0.2pt each (x4 for 0.8pts total) 2-2 - Aggregation (0.5pts) (Note: The following question relies on a successful implementation of the Account class in question 2-1 and will use your submission for the previous question) Implement a class called Bank that contains the following attributes and behaviours: // Variables, all should be private int capacity; int numAccounts; // Number of current accounts held by bank Account** accounts; // Pointer to array of Accounts // Constructors Bank() ; Bank(int accCapacity); // Methods void addAccount(Account* acc); // Add passed account to accounts array if room left Account** getAccounts(); // Return accounts int getNumAccounts(); void applyInterestAll(double interest); // Apply interest on all accounts Submit your class definition in a file called Bank.h and your class implementation in a file called Bank.cpp Marking criteria: . Correct files present: 0.1pt . Successfully compiled: 0.1pts o Successful test: 0.1pt each (x1 for 0.3pts total)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