Monday, November 14, 2011

Exam #2 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 which requests from the user a student's semester average. The program should display the letter grade the student earned for the semester.

    You must write two functions:

       int getSemesterAverage()
       char assignLetterGrade(int score)


    Be sure to declare appropriate constants.

    Sample Output
    Here is a screenshot of my code running.

    Letter Lookup output


  2. Write a program that counts how many times the lowercase letter 'e' appears in a user-input string.

    You must write one function:

       int eCount(string input)

    Sample Output
    Here is a screenshot of my code running.

    e Count output


  3. Write a program that calculates



    if x is strictly greater than y,



    if y is strictly greater than x, and



    if x is exactly equal to y.

    You must write one function:

       void blackBox(int x, int y)

    Sample Output
    Here is a screenshot of my code running.

    Mystery Math output


  4. Write a program that requests the subtotal of a restaurant bill and the percentage the diner would like to tip. The program calculates the tip and the final total.

    You must write one function:

       void calculateTotal(double bill, double rate, double &tip, double &total)

    Sample Output
    Here is a screenshot of my code running.

    Tip Calculator output