# Lab 9

```Lab 9
 Exercises
Exercise 1
Write a function called letter_grade() that has type int and
input parameter points and returns through an output
straight scale (90-100) is an A, 80-89 is a B, and so on.
Return through a second output parameter just_missedp
an indication of whether the student just missed the next
higher grade (true for 89, 79, and so on).
Exercise 2
Write a program to model a simple calculator. Each data line should
consist of the next operation to be performed from the list of below and
the right operand. Assume the left operand is the accumulator value
(initial value of 0). You need a function scan_data with two output
parameters that return the operator and the right operand scanned
from a data line. You need a function do_next_op that performs the
required operation. Do_next_op has two input parameters (the
operator and the operand) and one input/output parameter (the
accumulator). The valid operations are:
- subtract
* multiply
/ divide
** power (raise left operand to power of right operand)
q quit
 Your program should also use a function print_error_message() To
output error messages if the operation read from the user is not valid.
 Your calculator should display the accumulator value after each
operation. A sample output follows.
+ 5.0
result so far is 5.0
** 2
result so far is 25.0
/ 2.0
result so far is 12.5
q0
the final result is 12.5
Exercise 3
We want to write a program that allows the user enter a time value
indicating hours, minutes and seconds in this format H M S and
convert them to seconds.
A sample execution would be:
**********************************
* This program converts a time of day into seconds
* Enter a valid Day time in this format: hours minutes seconds
* To exit enter 0 0 0
**********************************
40 5 --------- 13205 seconds
10 0 ---------- 15000 seconds
70 0 ---------- error
0 0 0---------- Bye bye !!!
 Functions with no arguments
should be printed at the beginning (see above).
 Functions with input arguments and a return value
Write a function in_seconds that takes three arguments hours,
minutes, and seconds and that returns the corresponding value in
seconds. A prototype of this function would be:
int in_seconds(int hours, int minutes, int seconds).
 Function with input and output parameters (Call by reference vs
Call by value)
Modify the function in_seconds so that it checks for errors. If one of the
input values is invalid it should return a 0, otherwise it should return a
1. The corresponding values in seconds should be returned in an
output argument. The prototype for the modified version could be:
int in_seconds(int hours, int minutes, int seconds, int *total)
STYLE
Before the definition of each function you should have comments that describe
what the function does. Look at the sample comment below for the function
in_seconds()
/*****************************************************
* Function Name
: in_seconds
* Function Arguments
:
*seconds of type int (number of seconds)
*minutes of type int (number of minutes)
*hours of type int (number of hours)
* *total of type int*(the total in seconds)
* Return Value
: 0 or 1
* Purpose
: Converts the time into seconds
*****************************************************/
```

39 Cards

Pastoralists

20 Cards