Lab 9

  1. Write a program asking the user to enter a positive number. Validate the input. Using a for loop, print the sequence of numbers from 1 through the user's number, but print negative values for even numbers.
  2. Sample run of program:
    Enter a number positive number: > -4 Invalid input! Enter a positive number: > 7 1 -2 3 -4 5 -6 7

  3. Write a complete C++ program that asks the user to type a positive integer n. Validate the input. It should then ask the user to enter n more numbers and print out how many of these numbers were odd.
  4. Sample run of program:
    Enter a number positive number: > -2 Invalid input! Enter a positive number: > 4 Now enter 4 more integers: > 6 7 8 9 2 were odd

    Another sample run of program:
    Enter a number positive number: > 5 Now enter 5 more integers: > 1 3 5 7 9 5 were odd

  5. Write a complete C++ program that asks the user to type two positive integers. Validate the input. It should show a horizontal bar of X symbols whose length is given by the shorter of the two integers. (If the two integers are equal, either can be used as the shorter.)
  6. Sample run of program:
    Enter two positive integers: > 4 2 XX

    Another sample run of program:
    Enter two positive integers: > 4 5 XXXX
  7. (Variation of the FizzBuzz Test programming question.) Write a complete C++ program that does the following:
  8. Sample run of program:
    Enter positive integer greater than 10: 9 Invalid input! Try again: 16 1 2 Fuzzy Cat 5 Fuzzy 7 Cat Fuzzy 10 11 FuzzyCat 13 14 Fuzzy Cat
  9. Write a complete C++ program that does the following:
  10. Sample run of program:
    Enter two integers. The second must be at least 20 larger than the first: 4 18 Invalid input! Try again: 4 28 The numbers between 4 and 28 that are evenly divisible by 2 but not by 3 are: 4 8 10 14 16 20 22 26 28

    Another sample run of the program:
    Enter two integers. The second must be at least 20 larger than the first: 5 19 Invalid input! Try again: -5 19 The numbers between -5 and 19 that are evenly divisible by 2 but not by 3 are: -4 -2 2 4 8 10 14 16