CS1112
Review Questions for Prelim 1

  1. Be sure to review all the lecture examples, section/lab exercises, and homework problems!

  2. M exercises:   You should complete the exercises in Insight labelled M at the end of each section. These exercises are variations on the main example in each section and help make sure that you actually understand the examples.

  3. The income tax code in Timbuktu works as follows: the first $30,000 of income is taxed at 25%, the next $30,000 at 30%, and any amount above $60,000 at 40%. Write a program that accepts as input an income amount and computes and prints the correct tax amount to be paid in Timbuktu.

  4. Questions from Insight:

  5. Given integers nBig and nSm where nBig > nSm, write a program fragment that lists the integers in decreasing order and annotates the integers that are prime numbers. Only print functions and rem are allowed. Assume nBig,nSm > 1. Example output for nBig=6 and nSm=3 is
            6
            5 is prime
            4
            3 is prime
          

  6. [Tough problem]   A mode is the number in a sequence that appears the most number of times. A user is prompted to enter a sequence of non-negative numbers in non-decreasing order one-by-one. The user indicates the end of the sequence by entering a negative number. Write a script to obtain such user input and determine the mode of the sequence. If there are multiple modes, you may report any one of them as the mode. *Do not use arrays.* Below is an example run:
          Determine mode of a set of nonnegative integers.
          Use a negative number to quit.
          Give me a number:  70
          Another number not smaller than the previous: 71
          Another number not smaller than the previous: 80
          Another number not smaller than the previous: 80
          Another number not smaller than the previous: 80
          Another number not smaller than the previous: 91
          Another number not smaller than the previous: 93
          Another number not smaller than the previous: -1
          Mode is 80.
        
  7. Part A: Write a function hms2s that converts a time expressed in hours, minutes, seconds to a time expressed in seconds. Function hms2s returns one variable seconds and takes three input arguments: hours (h), minutes (m), and seconds (s).
    Part B: Write a function s2hms that performs the opposite operation. Function s2hms takes one input argument seconds and returns three variables: h, m, and s.
    Part C: Write two function calls to the above functions (in a script). Use input values of your choice.

  8. Questions from Insight: