InvestmentPlanner.cpp
上传用户:sz0451
上传日期:2022-07-29
资源大小:256k
文件大小:3k
- // This is the main project file for VC++ application project
- // generated using an Application Wizard.
- #include "stdafx.h"
- #using <mscorlib.dll>
- using namespace System;
- // Function prototypes
- void DisplayWelcome();
- void DisplayProjectedValue(double amount, int years, double rate);
- void DisplayProjectedValue(double amount, int years);
- double GetInvestmentAmount();
- int GetInvestmentPeriod(int min=10, int max=25);
- // Define and initialize a global integer variable
- int numberOfYourFunctionsCalled = 0;
- // This is the entry point for this application
- #ifdef _UNICODE
- int wmain(void)
- #else
- int main(void)
- #endif
- {
- DisplayWelcome();
-
- Console::WriteLine(S"nIllustration...");
- DisplayProjectedValue(10000, 25, 6.0);
- Console::WriteLine(S"nEnter details for your investment:");
- double sum = GetInvestmentAmount();
- int period = GetInvestmentPeriod(5, 25);
- Console::WriteLine(S"nYour plan...");
- DisplayProjectedValue(sum, period, 6.0);
- Console::Write(S"nNumber of your functions called: ");
- Console::WriteLine(numberOfYourFunctionsCalled);
- return 0;
- }
- // Display a welcome message to the user
- void DisplayWelcome()
- {
- numberOfYourFunctionsCalled++;
-
- Console::WriteLine(S"-------------------------------------------");
- Console::WriteLine(S"Welcome to your friendly Investment Planner");
- Console::WriteLine(S"-------------------------------------------");
- return;
- }
- // Calculate and display the projected value of the investment
- void DisplayProjectedValue(double amount, int years, double rate)
- {
- numberOfYourFunctionsCalled++;
-
- double rateFraction = 1 + (rate/100);
- double finalAmount = amount * Math::Pow(rateFraction, years);
- finalAmount = Math::Round(finalAmount, 2);
- Console::Write(S"Investment amount: ");
- Console::WriteLine(amount);
- Console::Write(S"Growth rate [%]: ");
- Console::WriteLine(rate);
- Console::Write(S"Period [years]: ");
- Console::WriteLine(years);
- Console::Write(S"Projected final value of investment: ");
- Console::WriteLine(finalAmount);
- return;
- }
- // Ask the user how much money they want to invest
- double GetInvestmentAmount()
- {
- numberOfYourFunctionsCalled++;
-
- Console::Write(S"How much money do you want to invest? ");
-
- String __gc * input = Console::ReadLine();
- double amount = input->ToDouble(0);
- return amount;
- }
- // Ask the user how long they want to invest their money (between min and max)
- int GetInvestmentPeriod(int min, int max)
- {
- numberOfYourFunctionsCalled++;
-
- Console::Write(S"Over how many years [");
- Console::Write(S"min=");
- Console::Write(min);
- Console::Write(S", max=");
- Console::Write(max);
- Console::Write(S"] ? ");
-
- String __gc * input = Console::ReadLine();
- int years = input->ToInt32(0);
- return years;
- }