Thursday, October 20, 2011

Exam #1 programming problems

I strongly suggest that each student develop a C++ solution to the following problems in preparation for the coding portion of the first exam. While I do not promise that the practical part of the exam will be *exactly* the same as any one of these problems, the actual test question will at least be very similar to one or more of these practice problems.

  1. Write a program that prompts the user to input an integer. The program should then output a message to the user stating whether the number provided was positive, negative, or zero.

    This is the output from a run of my own code:



  2. You learned in geometry class that the sum of the squares of the two legs of a right triangle is equal to the square of its hypotenuse. In mathematical terms,


    Write a program that accepts as its input the lengths of the sides of a triangle and determines whether or not the triangle is a right triangle.

    Sample Input
    Right triangle: 3, 4, 5
    Equilateral triangle: 3, 3, 3
    Isosceles triangle: 2, 2, 1

    This is the output from sample runs of my own code:

  3. Right triangle
    input 3, 4, 5

    Equilateral triangle
    input 3, 3, 3

    Isosceles triangle
    input 2, 2, 1

  4. Girl Scouts sell their signature cookies once a year. Each scout receives an order form and badgers everyone they know sells cookies. When order forms are collected by the Cookie Coordinator, she adds up all the individual box counts and places the troop order with the local council. The council only sells full cases of cookies so the Cookie Coordinator must round up the order if the troop has not sold an exact order of cases.

    Write a program that accepts as its input the number of boxes of cookies sold by each scout (a scout might sell zero boxes). The program should add up all the individual orders and then determine how many cases the Cookie Coordinator needs to order. Terminate input with the sentinel value -1.

    A case of cookies holds 12 boxes.

    This is the output from a run of my own code:

  5. GS cookie order output

  6. Write a program that implements the algorithm given in example 103 (pp 18-20 of textbook), which determines the monthly wages of a salesperson.

    You get the pretty right alignment by using the setw() function.

    This is the output from a run of my own code:

  7. Calculate Salary output


  8. Write a program to find the smallest integer such that its square is strictly greater than 1994. You must implement your solution using a while loop and you must provide proof that your calculation is correct.

    This is the output from a run of my own code using 1762 as the threshold value (don't want to give you the answer!):

  9. Smallest n squared output