Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <math.h>
- using namespace std;
- //investment class
- class investment {
- private: //attributes (almost always private)
- double invAmt;
- double intRate;
- public: //methods (allow you to access attributes(private data)
- investment(); //constructor
- investment(double amt, double rate); //constructor
- void setIntRate(double rate); //setters
- void setInvAmt(double amt); //setters
- double getIntRate(); //getters
- double getInvAmt(); //getters
- long double futureValue(int years);
- };
- //constructor definition -- set a starting point for your values.
- investment::investment()
- {
- invAmt = 0.0;
- intRate = 0.0;
- };
- investment::investment(double amt, double rate)
- {
- invAmt = amt;
- intRate = rate;
- };
- void investment::setIntRate(double rate)
- {
- intRate = rate;
- };
- double investment::getIntRate()
- {
- return intRate;
- };
- void investment::setInvAmt(double amt)
- {
- invAmt = amt;
- };
- double investment::getInvAmt()
- {
- return invAmt;
- };
- long double investment::futureValue(int years)
- {
- return (invAmt*pow((1 + intRate), years)); //using 'pow' includes math header.
- };
- int main()
- {
- int years = 0;
- double rate;
- double amt;
- char answer;
- cout << "Would you like to use the Investment Program?(Y/N) \n";
- cin >> answer;
- while (answer == 'y' || answer == 'Y') {
- cout << "Please input your interest rate, amount, and number of years: \n";
- cout << "Interest Rate (in percent): \n";
- cin >> rate;
- cout << "Investment Amount: \n";
- cin >> amt;
- cout << "Number of years invested: \n";
- cin >> years;
- investment myInvestment(amt, rate);
- myInvestment.setIntRate(rate / 100);
- myInvestment.setInvAmt(amt);
- cout << "Your investment: " << myInvestment.futureValue(years);
- cout << endl;
- cout << "Your interest rate: " << myInvestment.getIntRate();
- cout << endl;
- cout << endl;
- cout << "Would you like to use the Investment Program?(Y/N) \n";
- cin >> answer;
- if (answer == 'n' || answer == 'N')
- {
- cout << "Thank you and have a nice day!";
- }
- }
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement