Skip to main content

Documentation 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.

The 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.
struct YearlyInvestmentResult {
    int year;
    double yearEndBalance;
    double yearEndEarnedInterest;
};
FieldTypeDescription
yearintThe year number (1-indexed in the C++ version)
yearEndBalancedoubleThe total balance at year end, with full decimal precision
yearEndEarnedInterestdoubleThe 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.
Investment investment(5000.0, 250.0, 5.0, 20);

Setter Methods

Each setter updates a single private data member. Setters can be used to modify an Investment object after construction without creating a new instance.
MethodParameterDescription
setInitialAmount(double amt)amt — initial investmentSets the starting balance
setMonthlyDeposit(double amt)amt — monthly depositSets 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 yearsSets the projection period

Getter Methods

All getters are declared const and return the stored value directly with no transformation.
MethodReturn TypeDescription
getInitialAmount()doubleReturns the initial investment amount
getMonthlyDeposit()doubleReturns the monthly deposit
getAnnualInterest()doubleReturns the annual interest rate
getYears()intReturns 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() constvector<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.
for (int month = 0; month < 12; ++month) {
    double monthlyInterest = total * monthlyRate;
    total += monthlyInterest;
    yearlyInterest += monthlyInterest;
}

calculateWithMonthlyDeposit() constvector<YearlyInvestmentResult>

Adds monthlyDeposit to the total before computing monthly interest. This means the deposit earns interest in the same month it is contributed.
for (int month = 0; month < 12; ++month) {
    total += monthlyDeposit;
    double monthlyInterest = total * monthlyRate;
    total += monthlyInterest;
    yearlyInterest += monthlyInterest;
}
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:
Balance and Interest Without Additional Monthly Deposits
==================================================================
Year     Year End Balance       Year End Earned Interest
------------------------------------------------------------------
Each data row prints the year number left-aligned in a field of width 8, followed by the year-end balance and year-end earned interest right-aligned with a leading $ sign and two decimal places.

Build docs developers (and LLMs) love