TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/apursley2012/airgead-investment-calculator/llms.txt
Use this file to discover all available pages before exploring further.
Investment class encapsulates the four parameters of a compound interest projection and provides methods to calculate and display growth reports. It is declared in investment.h and implemented in investment.cpp.
YearlyInvestmentResult Struct
The YearlyInvestmentResult struct is used as the element type of the vectors returned by both calculation methods. Each instance represents the rolled-up results for a single year.
| Field | Type | Description |
|---|---|---|
year | int | The year number (1-indexed in the C++ version) |
yearEndBalance | double | The total balance at year end, with full decimal precision |
yearEndEarnedInterest | double | The interest earned during that year only |
Constructor
Investment(double initAmt, double monthlyDep, double annualInt, int yrs) initializes all four private data members in a single call. The annual interest rate is stored as a percentage (e.g., pass 5.0 for 5%) and converted to a monthly decimal rate inside the calculation methods.
Setter Methods
Each setter updates a single private data member. Setters can be used to modify anInvestment object after construction without creating a new instance.
| Method | Parameter | Description |
|---|---|---|
setInitialAmount(double amt) | amt — initial investment | Sets the starting balance |
setMonthlyDeposit(double amt) | amt — monthly deposit | Sets the monthly contribution |
setAnnualInterest(double rate) | rate — as percentage (e.g. 5.0 for 5%) | Sets the annual interest rate |
setYears(int yrs) | yrs — number of years | Sets the projection period |
Getter Methods
All getters are declaredconst and return the stored value directly with no transformation.
| Method | Return Type | Description |
|---|---|---|
getInitialAmount() | double | Returns the initial investment amount |
getMonthlyDeposit() | double | Returns the monthly deposit |
getAnnualInterest() | double | Returns the annual interest rate |
getYears() | int | Returns the projection period |
Calculation Methods
Both calculation methods derive the monthly interest rate from the stored annual rate using(annualInterest / 100.0) / 12.0 and iterate over years × 12 months, accumulating per-year interest before pushing a YearlyInvestmentResult entry to the result vector.
calculateWithoutMonthlyDeposit() const → vector<YearlyInvestmentResult>
Computes monthly interest on the running total for each of years × 12 months. No deposit is added. Accumulates yearlyInterest per year. The starting value of total is initialAmount.
calculateWithMonthlyDeposit() const → vector<YearlyInvestmentResult>
Adds monthlyDeposit to the total before computing monthly interest. This means the deposit earns interest in the same month it is contributed.
This deposit-first ordering differs from the JavaScript version, which applies interest before adding the deposit each month. The two approaches produce slightly different final balances for the same inputs.
Display Methods
displayWithoutMonthlyDeposit() and displayWithMonthlyDeposit() each call the file-scoped static function printReport(), passing a title string and the corresponding result vector. printReport() writes a formatted table to stdout using std::setw, std::left, std::right, and std::fixed with std::setprecision(2). The report header format is:
$ sign and two decimal places.