Assignment2A(Due on November 30)
Assignment2A(Due on November 30)
1. Calculating the Sum of Odd Integers: Write a C++ program to Sum the
odd integers between 1 and 99 using a for statement. Assume the integer
variables sum and count have been defined.
2. Calculating the Product of Odd Integers: Write a program that calculates
and prints the product of the odd integers from 1 to 15.
3. Calculating Sales: An online retailer sells five different products whose
retail prices are shown in the following table:
5. Total Amount with Fixed Interest: Write a program that calculates how
much money you’ll end up with if you invest an amount of money at a fixed
interest rate, compounded yearly. Have the user furnish the initial amount,
the number of years, and the yearly interest rate in percent. Some interaction
with the program might look like this:
Enter initial amount: 3000
Enter number of years: 10
Enter interest rate (percent per year): 5.5
At the end of 10 years, you will have 5124.43 dollars.
At the end of the first year you have 3000 + (3000 * 0.055), which is 3165.
At the end of the second year you have 3165 + (3165 * 0.055), which is
3339.08. Do this as many times as there are years. A for loop makes the
calculation easy.
6. Possible Number of Arrangements: Suppose you give a dinner party for
six guests, but your table seats only four. In how many ways can four of the
six guests arrange themselves at the table? Any of the six guests can sit in
the first chair. Any of the remaining five can sit in the second chair. Any of
the remaining four can sit in the third chair, and any of the remaining three
can sit in the fourth chair. (The last two will have to stand.) So the number
of possible arrangements of six guests in four chairs is 6*5*4*3, which is
360. Write a program that calculates the number of possible arrangements
for any number of guests and any number of chairs. (Assume there will
never be fewer guests than chairs.) Don’t let this get too complicated. A
simple for loop should do it.
7. Computing Powers: Write a C++ program that prints numbers rose to
fourth power (starting from 1) with a constraint that maximum power should
not exceed 4-digit value.
8. Currency Conversion: In the heyday of the British Empire, Great Britain
used a monetary system based on pounds, shillings, and pence. There were
20 shillings to a pound, and 12 pence to a shilling. The notation for this old
system used the pound sign, £, and two decimal points, so that, for example,
£5.2.8 meant 5 pounds, 2 shillings, and 8 pence. (Pence is the plural of
penny.) The new monetary system, introduced in the 1950s, consists of only
pounds and pence, with 100 pence to a pound (like U.S. dollars and cents).
We’ll call this new system decimal-pounds. Thus £5.2.8 in the old notation
is £5.13 in decimal pounds (actually £5.1333333). Write a program to
convert the old pounds-shillings-pence format to decimal pounds. An
example of the user’s interaction with the program would be
Enter pounds: 7
Enter shillings: 17
Enter pence: 9
Decimal pounds = £7.89
In most compilers you can use the decimal number 156 (hex character
constant ‘\x9c’) to represent the pound sign (£). In some compilers, you can
put the pound sign into your program directly by pasting it from the
Windows Character Map accessory.
9. Reverse Currency Conversion: Write the inverse of Exercise 9, so that the
user enters an amount in Great Britain’s new decimal-pounds notation
(pounds and pence), and the program converts it to the old pounds-shillings-
pence notation. An example of interaction with the program might be
Enter decimal pounds: 3.51
Equivalent in old notation = £3.10.2.
10.Currency Calculator: Create a three-function calculator for old-style
English currency, where money amounts are specified in pounds, shillings,
and pence. (See Exercises 7 and 8 above.) The calculator should allow the
user to add or subtract two money amounts, or to multiply a money amount
by a floating-point number. (It doesn’t make sense to multiply two money
amounts; there is no such thing as square money. We’ll ignore division.
11.Fibonacci Series: Write a program in C to display the first n terms of
Fibonacci series. Your program may look like this
Number of terms to display: 10
Fibonacci series up to 10 terms: 0 1 1 2 3 5 8 13 21 34
12. Write a program that asks the user to enter a series of numbers. When the
number entered is 0, the loop terminates.
------------------------------