I have to write a program in C++ that will calculate the yearly interest and final value of a certificate of Deposit, given the initial investment and five interest rates. In the program the interest rate on a 5-year variable rate (certificate of Deposit) is changed every year, the interest is also compounded annually.
Any code suggestions will do!
output:
Enter initial investment: (decimal number)
Enter interest rate for year 1: (decimal number)
Enter interest rate for year 2: (decimal number)
Enter interest rate for year 5: (decimal number)
You earned $(interest)
Your certificate of Deposit is worth $(value)
C++ program question?
At the end of the message, I posted a similar program with a very straightforward implementation.
Although, since this is a relatively trivial problem, I'd probably spruce up the code below to have better C++ structure. You probably want to create an Account class with private variables for the balance and interest rates and methods in the Account class to act on the method. Your main should really look like:
main()
{
{input variables, get inputs}
Account grandmas(initial);
grandmas.setRates(year1, year2, year3, year4, year5);
cdValue = grandmas.returnBalance();
cout %26lt;%26lt; "You earned $" %26lt;%26lt; cdValue-initial %26lt;%26lt; endl;
cout %26lt;%26lt;"Your certificate of Deposit is worth $" cdValue %26lt;%26lt; endl;
}
Notes:
When you create "Account" you should initialize it with the starting investment.
setRates would populate the private variables in Account class with the return rates.
returnRates would run the computation using the information in the private variables and return the final result.
For bonus points, implement error handling.
Bad program (too much like regular C) template below.....
-----------------
Bank_Accounts.cpp
-----------------
#include %26lt;iostream%26gt;
#include %26lt;fstream%26gt;
#include %26lt;iomanip%26gt;
using namespace std;
const double minimumBalance = 1000.00;
int main()
{
// Declare Variables
int acctNumber;
char acctType;
float acctBalance;
double interest;
// For input, get the account number, account type, and current balance
cout %26lt;%26lt; "Enter the Account Number: ";
cin %26gt;%26gt; acctNumber;
cout %26lt;%26lt; "Account Type" %26lt;%26lt; endl;
cout %26lt;%26lt; "C = Checking Account" %26lt;%26lt; endl;
cout %26lt;%26lt; "S = Savings Account" %26lt;%26lt; endl;
cout %26lt;%26lt; "Enter the Account Type: ";
cin %26gt;%26gt; acctType;
cout %26lt;%26lt; "Enter the Account Balance: ";
cin %26gt;%26gt; acctBalance;
if (acctType == 'S' %26amp;%26amp; acctBalance %26lt; minimumBalance)
acctBalance = acctBalance - 10.00;
else if (acctType == 'C' %26amp;%26amp; acctBalance %26lt; minimumBalance)
acctBalance = acctBalance - 25.00;
else if (acctType == 'S' %26amp;%26amp; acctBalance %26gt;= minimumBalance)
interest = (acctBalance,4);
else if (acctType == 'C' %26amp;%26amp; acctBalance %26gt;= 5000.00)
interest = (acctBalance,3);
else if (acctType == 'C' %26amp;%26amp; acctBalance %26gt;= minimumBalance)
interest = (acctBalance,5);
cout %26lt;%26lt; "Account Number: " %26lt;%26lt; acctNumber;
cout %26lt;%26lt; "Account Type: " %26lt;%26lt; acctType;
cout %26lt;%26lt; "Account Balance: " %26lt;%26lt; acctBalance;
cout %26lt;%26lt; "Amount of Interest Earned: " %26lt;%26lt; interest;
}
Reply:First things first...Go here...{:-{}.
Reply:Sure here's the pseudocode:
take input
process
display output
I'd suggest you write the code yourself - the best way to learn programming is to get programming! If you get people on the net to do it for you, you learn absolutely nothing. That kind of defeats the object of giving you homework in the first place. Your teachers aren't just creating work for you to waste your time - they're doing it to help, so by "cheating the system" you are really only cheating yourself out of an education. This being said, at least you didn't ask for the code to be written for you - so I'll let ya off this time ;) lol
Rawlyn.
Reply:BAHAHAHA YOU AER TEH PROGRAMMAR!?!?
All I can do is hello world.
sympathy flowers
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment