Next: Exercises Up: The switch statement Previous: Multiple Choice Questions

Review Questions

  1. A student is given a grade from `A' to `F' in a test. So averages can be calculated it is required to assign marks to these grades as follows, `A' is 10, `B' is 8, `C' is 6, `D' is 4, `E' is 2 and `F' is 0. In C++ what two methods are there of doing this? Which of these two methods would be better in this case? Write the appropriate statement for the method you have chosen.
  2. A student has a percentage mark for an examination, these marks are to be converted to grades as follows:
         >=70   `A'
         60-69  `B'
         50-59  `C'
         40-49  `D'
         30-39  `E'
         <30    `F'
    

    Could a switch statement be used to directly assign the appropriate grade given a percentage mark? If not how could you do this? Write a statement to carry out the assignment of grades.

  3. Write a switch statement to assign grades as described in the previous question. Use the fact that mark/10 gives the first digit of the mark.



Next: Exercises Up: The switch statement Previous: Multiple Choice Questions