CodeReview Community! I was hoping you'd be able to review my basic OOP program. Last year I did a strictly procedural one and now I’ve incorporated OOP techniques. Ignore the commented out piece of code. The Hungarian Notation is a requirement for my university course so please don’t criticise the fact I’ve used it. I’d like to know what I’ve done well vs what I haven’t and any suggestions in making my code better. Many thanks in advance. The following scenario is what I’ve based the program on:
Scenario A reputable bank has asked you to create a personal finance management program. The program will need to be able to take the user's monthly wage, their monthly bills, and any weekly bills that they may occur. This will then be broken down to find out how much of their wages they will then have left to save.
The user should be able to enter any amount of monthly bills and weekly bills. The user should also have the option to add other users from their household to be handled within the calculations.
Once all of the relevant information has been included, an overview of the bills against a weekly, monthly and yearly cost should be output.
Inputs User's Name (Must be more than 1) Monthly Wage (Must be more than 1) The different bills the user has to pay (Per Person) Outputs User's Name Weekly, Monthly, Yearly Wage Total Weekly, Monthly, Yearly Bills Total Total Spent on Bills Total left to Save 10% over and under the total that can be saved How much can be saved per month 10% over and under the total that can be saved per month
// Personal Finance Tool.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <vector>
#include <string>
#include <memory>
#include "Utils.h"
class Bill
{
private:
std::string m_sBillName;
double m_dMonthlyBill;
public:
Bill(std::string sBillName, double dMonthlyBill)
:m_sBillName(sBillName),m_dMonthlyBill(dMonthlyBill) {}
double GetMonthlyBill() {
return m_dMonthlyBill;
}
};
class User
{
private:
std::string m_sName;
double m_dMonthlyWage;
std::vector<Bill>objBillsToPay;
public:
User(std::string sName, double dMonthlyWage)
:m_sName(sName), m_dMonthlyWage(dMonthlyWage) {}
void AddBill(std::string sBillName, double dMonthlyBill)
{
objBillsToPay.push_back({ sBillName, dMonthlyBill });
}
double WeeklyWage() {
return m_dMonthlyWage / 4;
}
double YearlyWage() {
return m_dMonthlyWage * 12;
}
double TotalSpentOnBills()
{
double dTotal = 0;
for (Bill &objBill : objBillsToPay)
{
dTotal += objBill.GetMonthlyBill();
}
return dTotal;
}
double LeftToSaveMonthly()
{
return (YearlyWage() / 12) - (TotalSpentOnBills() / 12);
}
double TotalLeftToSaveYearly()
{
return YearlyWage() - TotalSpentOnBills();
}
double OverSaved()
{
return TotalLeftToSaveYearly() * 0.10;
}
double UnderSaved() {
return TotalLeftToSaveYearly() - (TotalLeftToSaveYearly() * 0.10);
}
};
void DisplayResults(std::vector<User>& objUsers) {
for (User& objUser : objUsers) {
std::cout << "***" << std::endl;
std::cout << "Weekly wage: " << objUser.WeeklyWage() << std::endl;
std::cout << "Yearly wage: " << objUser.YearlyWage() << std::endl;
std::cout << "10% over total that can be saved: " << objUser.OverSaved() << std::endl;
std::cout << "10% under total that can be saved: " << objUser.UnderSaved() << std::endl;
std::cout << "Total left to save yearly: " << objUser.TotalLeftToSaveYearly() << std::endl;
std::cout << "Total spent on bills: " << objUser.TotalSpentOnBills() << std::endl;
}
std::cout << std::endl;
}
void TestData(std::vector<User>& objUsers)
{
objUsers.push_back({ "Jack Kimmins", 764});
objUsers.at(0).AddBill("Water Bill", 65);
objUsers.push_back({ "George Bradley", 332});
objUsers.push_back({ "Jason Hill", 343 });
objUsers.push_back({ "Sean Shearing", 374 });
}
int main()
{
std::vector<User>objUsers;
TestData(objUsers);
//CreateUser(objUsers); Will need to be wrapped in a while loop if uncommented
DisplayResults(objUsers);
system("pause"); //Ignore this, I know using system isn't good, just to stop it
}
x
after reading your code. You should never edit and addx
to your code since this will nullify his review. \$\endgroup\$