i need guidance here please. i need to implement the +, = , == operators on my savingsaccount class. i really dont know where to start and any guidance will really be appreciated. here are my codes:
//SavingsAccount.h
[tag]
[/tag]Code:#ifndef SAVINGSACCOUNT_H #define SAVINGSACCOUNT_H class SavingsAccount { public: SavingsAccount(double x) { savingsBalance = x >= 0 ? x:0; } void calculateMonthlyInterest(); static void modifyInterestRate(double); void printoutBalance() const; private: double savingsBalance; static double annualInterestRate; };
//SavingsAccount.cpp
[tag]
[/tag]Code:#include <iostream> #include <iomanip> #include "SavingsAccount.h" double SavingsAccount::annualInterestRate = 0; void SavingsAccount::calculateMonthlyInterest() { savingsBalance += savingsBa lance * (annualInterestRate / 2.0); } void SavingsAccount::modifyInterestRate(double y) { annualInterestRate = (y >= 0 && y <= 1.0) ? y:0.03; } void SavingsAccount::printoutBalance() const { std::cout << '$' << savingsBalance << std::endl; }
//main.cpp
[tag]
[/tag]Code:#include <iostream> #include <iomanip> #include "SavingsAccount.h" int main() { SavingsAccount saver1(2000.0), saver2(3000.0); SavingsAccount::modifyInterestRate(.03); std::cout << "Monthly balances with 3% annual interest" << \ntBalances:\n\t\t\tSaver 1=>"; saver1.printoutBalance(); std::cout << "Saver 2=>"; saver2.printoutBalance(); for (int m = 1; m <= 12; ++m) { saver1.calculateMonthlyInterest(); saver2.calculateMonthlyInterest(); std::cout <<"\nMonth " << m << ":Saver 1=>"; saver1.printoutBalance(); std::cout << "Saver 2=>"; saver2.printoutBalance(); } SavingsAccount::modifyInterestRate(.04); saver1.calculateMonthlyInterest(); saver2.calculateMonthlyInterest(); std::cout << "\nBalances with 4% interest rate:" << "\nBalances:\nSaver 1=>"; saver1.printoutBalance(); std::cout << "Saver 2=>"; saver2.printoutBalance(); std::cout << std::endl; return 0; }
thankyou very much in advance!!



LinkBack URL
About LinkBacks


