Cmps1131 Program Set2
Cmps1131 Program Set2
You can work in groups of no more than 4 individuals. Each individual must participate in
the construction of the full program. Programs are to be submitted electronically, and MUST
compile. Each program must contain the names of all individuals, the date, the class and
section. It must also contain good comments/documentation, along with proper indentation
and line spacing (which you can find examples of from code samples in your notes). Ensure
that you submit what is expected of you by referring to the rubric at the end of your
course outline. If you have any questions, please feel free to come see me. Don’t leave this
for last minute. I am not available for help on the due date.
I have provided the driver program. Make sure that you test your code using my driver. Each
time you complete a function, uncomment the line in my driver that calls that function. This
way, you can systematically test whether your code is working.
The student then types the answer. Your function checks the student’s answer. If it is correct,
then your function should print ONE of the following possible responses:
Very good!
Excellent!
Nice Work!
Keep up the good work!
And then ask another multiplication question. Whenever a wrong answer is supplied, print one of
the following responses:
No. Please try again.
Wrong. Try once more.
Don’t give up!
No. Keep trying.
In the case of wrong answers, you must let the student try the same question again repeatedly
until the student finally gets it right. Hint: Use the random number generator to produce a
number from 1 to 4 to select an appropriate response to each answer. Then, use a switch
structure to issue a response based on the random number generated.
The function is to also count the number of correct and incorrect responses typed by a student.
After the student types 10 answers, your program should calculate the percentage of correct
responses. If the percentage is lower then 75 percent, your program should print “Please ask
your instructor for extra help” and then terminate. This function accepts nothing and returns
nothing.
The player then types a first guess. The function responds with one of the following:
1. Excellent! You guessed the number!
Would you like to play again (y or n)?
2. Too low. Try again.
3. Too high. Try again.
Your function must not stop asking for guesses until the user has provided a correct solution.
Your program should keep telling the player Too high or Too low to help them narrow down the
answer. Count the number of guesses the player makes. At the end when the user finally guesses
correctly, print Either you know the secret or you got lucky! if the number of guesses were 10
or less. If the player guesses the number in 10 tries, then print Ahah! You know the secret! If
the player makes more than 10 guesses, then print You should be able to do better!
3. Create a function called printSquare that has no parameters and returns nothing.
Function printSquare will ask the user for the size of the side of a square and then prints
a hollow square of that size out of asterisks and blanks. Your program should work for
squares of all side sizes between 1 and 20. As an example, if the user types a size of 5, it
should print
*****
* *
* *
* *
*****
4. Create a function called calculatePayroll. The rules that should be applied to this
function are as follows:
a. employees who are managers receive a fixed weekly salary,
b. hourly workers (receive a fixed hourly wage for up to the first 40 hours they work
and “time-and-a-half,” i.e. 1.5 times their hourly wage for overtime hours
c. commission workers ( receive $250 plus 5.7% of their gross weekly sales. So, you
need to find out what their weekly sales are)
d. pieceworkers (receive a fixed amount of money per item they produce – each
pieceworker works on only one type of item).
Your function should now compute the weekly pay for employees. Please note that you
will not know the number of employees in advance. The way your function will know
which type of employee to calculate payroll for is because each employee has a unique
pay code: Managers have paycode 1, hourly workers have code 2, commission
workers have code 3 and pieceworkers have code 4. Hint: Your function should have
a loop and within it, it should read a paycode which is then passed to a switch which will
determine what type of employee it is and then proceed to calculate the appropriate pay.
Of course, this means that depending on the type of paycode, you must prompt the user to
enter the information required to calculate that type of employee. Therefore, the type of
information you need to get from the user to do your calculation depends on the type of
employee. And the type of employee is based upon the paycode entered. This function
should quit when the user enters 5 for paycode. It also accepts nothing and returns
nothing.