Programming Exercises

I l @ ve RuBoard

Programming Exercises

  1. Write a program that reads input until encountering the # character and then reports the number of spaces read, the number of newline characters read, and the number of all other characters read.

  2. Write a program that reads input until encountering # . Have the program print each input character and its ASCII decimal code. Print eight character-code pairs per line. Suggestion: Use a character count and the modulus operator (%) to print a newline character for every eight cycles of the loop.

  3. Write a program that reads integers until 0 is entered. Once input terminates, the program should report the total number of even integers (excluding the 0) entered, the average value of the even integers, the total number of odd integers entered, and the average value of the odd integers.

  4. Using if else statements, write a program that reads input up to # , replaces each period with an exclamation mark, replaces each exclamation mark initially present with two exclamation marks, and reports at the end the number of substitutions it has made.

  5. Redo Exercise 3, but use a switch .

  6. Write a program that reads input up to # and reports the number of times that the sequence ei occurs.

    Note

    The program will have to "remember" the preceding character as well as the current character. Test it with input like "Receive your eieio award."


  7. Write a program that requests the hours worked in a week and then prints the gross pay, the taxes, and the net pay. Assume the following:

    1. Basic pay rate = $10.00/hr

    2. Overtime (in excess of 40 hours) = time and a half

    3. Tax rate

      15% of the first $300

      20% of the next $150

      25% of the rest

    Use #define constants, and don't worry if the example does not conform to current tax law.

  8. Modify assumption a. in Exercise 6 so that the program presents a menu of pay rates to choose from. Use a switch to select the pay rate. The beginning of a run should look something like this:

     ***************************************************************** Enter the number corresponding to the desired pay rate or action: 1) .75/hr             2) .33/hr 3) .00/hr            4) .20/hr 5) quit ***************************************************************** 

    If choices 1 through 4 are selected, then the program should request the hours worked. The program should recycle until 5 is entered. If something other than choices 1 through 5 is entered, the program should remind the user what the proper choices are and then recycle. Use #defined constants for the various earning rates and tax rates.

  9. Write a program that accepts an integer as input and then displays all the prime numbers smaller than or equal to that number.

  10. The 1988 United States Federal Tax Schedule was the simplest in recent times. It had four categories, and each category has two rates. Here is a summary; dollar amounts are taxable income.

    Category Tax
    Single 15% of first $17,850 plus 28% of excess
    Head of Household 15% of first $23,900 plus 28% of excess
    Married, Joint 15% of first $29,750 plus 28% of excess
    Married, Separate 15% of first $14,875 plus 28% of excess

    For instance, a single wage earner with a taxable income of $20,000 dollars owes 0.15 — $17,850 + 0.28 — ($20,000 - $17,850). Write a program that lets the user specify the tax category and the taxable income and that then calculates the tax. Use a loop so that the user can enter several tax cases.

I l @ ve RuBoard


C++ Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 314
Authors: Stephen Prata

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net