Chapter 6: Programming Exercises

Programming Exercises: p. 325-327: (Assign the programs and provide additional instructions for all. Make sure you write down anything you don’t understand.)

812367

Programming Exercise 8 (SMALL PROGRAM – 5 points)

  • Create an application that contains a loop to be used for input validation. Valid entries are between 10 and 50. Test your program with values both less than and greater than the acceptable range.

Programming Exercise 1 (SMALLER PROGRAM – 10 points)

  • Write a program that generates 100 random numbers between 0 and 1000. Display the number of even values generated as well as the smallest, the largest, and the range of values. Output should be displayed in a Console Window (*text says: Windows message box).
  • Put the counter next to each random number when displaying.
  • Put each set of numbers on a new line.
  • Use modulus operator to find out if a number is even or not.
  • Use the random number generator in the class notes to generate a random number.
  • After displaying all random numbers, then display the smallest, largest and range.
  • No methods need to be written (but you can if you choose). Focus on the loop and conditional statements.

Programming Exercise 2 (SMALLER PROGRAM – 10 points)

  • Prompt the user for the length of three line segments as integers. If the three lines could form a triangle, print the integers and a message indicating they form a triangle. Recall that the sum of the lengths of any two sides must be greater than the length of the third side to form a triangle. For example, 20, 5, and 10 cannot be the lengths of the sides of a triangle because 5 + 10 is not greater than 20. For line segments that do not form a triangle, print the integers and an appropriate message indicating no triangle can be created. Use a state-controlled loop to allow users to enter as many different combinations as they want.
  • Using If…Else statements you have the flexibility to write the logic many different ways.
  • Logic: How to determine if a side is the largest or not. If it is, then check the other 2 sides to see if the triangle is valid.
  • Use at least 1 method.
  • How is your logic going to handle if all 3 sides are the same? Or if 2 are the largest?

Programming Exercise 3 (SMALLER PROGRAM – 10 points)

  • Write a program to calculate the average of all scores entered between 0 and 100. Use a sentinel-controlled loop variable to terminate the loop. After values are entered and the average calculated, test the average to determine whether an A, B, C, D, or F should be recorded. The scoring rubric is as follows: A: 90-100; B: 80-89; C: 70-79; D: 60-69; F < 60.
  • Use a method to get user input.
  • Use a sentinel controlled loop.

Programming Exercise 6 (SMALL PROGRAM – 5 points)

  • People sometimes give their telephone number using one or more alphabetic characters. Write a program that accepts a 10-digit telephone number that may contain one or more alphabetic characters. Display the corresponding number using numerals.
  • Use the same program from Chapter 5 (Program 10).
  • Modify it by adding a loop to make the program much smaller.

Programming Exercise 7(SMALL PROGRAM – *Modified from that in the textbook – 5 points)

  • New instructions:
  • Make a 10 by 10 multiplication table. Use a nested loop. Proper spacing for your results is essential.
  • HINT: This is a short program.

Sample output below: