Computer Science and Programming
Prof. Gregory Safko
Assigned: February 17, 2003
Due February 24, 2003
(Hint: the #include file <cctype> contains some useful functions, in particular toupper and tolower, which accept a char argument and return the character converted to uppercase or lowercase. Letters which are already in the correct case, and nonletters, are returned unchanged. For example, toupper('a') returns 'A', toupper('B') returns 'B', tolower('C') returns 'c', and tolower('4') returns '4'. This can help you make only 5 comparisons instead of 10.)
Also write a suitable main program to demonstrate your function.
The prototype should look like this:
bool isVowel(char v);
Write a function makeTriangle that takes a single int parameter t and draws a triangle that is t rows by t columns.
Here are two example runs (User input is underlined here for illustration only.)
Please enter a nonnegative integer: 4
*
**
***
****
Press any key to continue
Please enter a nonnegative integer: 1
*
Press any key to continue
The prototype should look like this:
void makeTriangle(int);
Modify the function makeTriangle (from above) that takes a single int parameter t and draws a triangle that is t rows by t columns, and then finishes with it's mirror image below it
Here are two example runs (User input is underlined here for illustration only.)
Please enter a nonnegative integer: 4
*
**
***
*******
**
*
Press any key to continue
Please enter a nonnegative integer: 1
*
Press any key to continue
Please enter a nonnegative integer: 2
***
*
Press any key to continue
The prototype should still look like this:
void makeTriangle(int);
The calculation for compound interest is:
a = p * (1 + r) n
Where p = the original amount invested (i.e. the principal)
r = the annual interest rate
n = the number of years
a = the amount on deposit at the end of the nth year
A sample run is as follows:
Please enter an initial investment: 1000
Please enter the interest rate: 5
Please enter the number of years: 10
Year Amount on Deposit
1 1050.00
2 1102.50
3 1157.62
4 1215.51
5 1276.28
6 1340.10
7 1407.10
8 1477.46
9 1551.33
10 1628.89
Press any key to continue
Some ideas and hints:
1. To calculate a number raised to another power, use the pow( ) function, by putting #include <cmath> in your preprocessor directive area. The function pow(double base, double exponent) returns a value of type double. Therefore, to calculate 4.1 raised to the power of 3, (i.e., 4.13), you would use pow(4.1,3); and use the value returned from that function.
2. The annual interest rate r should be entered by the user as a number, but when plugged into the equation it should be converted to "percentage as a decimal" form. In other words, if the user enters 5, you plug .05 (or 5/100) into the equation.
3. To print the 0's in the tenths and hundredths positions, use the technique described by Savitch on page 56:
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);