Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab 9 Exercises.

Similar presentations


Presentation on theme: "Lab 9 Exercises."— Presentation transcript:

1 Lab 9 Exercises

2 Exercise 1 Write a function called letter_grade() that has type int and input parameter points and returns through an output parameter gradep the appropriate letter grade using a straight scale (90-100) is an A, 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). Traditionally, geography has been seen as affection our natural environment (physical geography) and our human environment (human geography). However, more recently, geography has been viewed as an emerging hi-tech discipline, with such systems as Earth Observation, GPS and GIS. We will examine each of these more closely.

3 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: + add - subtract * multiply / divide ** power (raise left operand to power of right operand) q quit

4 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 q 0 the final result is 12.5

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 seconds seconds error Bye bye !!!

6 Functions with no arguments
Write a function called print_heading () that prints the heading that 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)

7 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 *****************************************************/


Download ppt "Lab 9 Exercises."

Similar presentations


Ads by Google