LAB 7 - // post: result == a <= b and b <= c) void...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
LAB 7 - Functions II The purpose of this lab is to reinforce the use of functions in the C++ programming language. In this lab you will develop five functions that, given three integers, say, A,B, and C, 1. find the smallest value among them, 2. find the largest value among them, 3. find the median (middle value) among them, 4. decide whether they are in ascending order (i.e., A<=B<=C), and 5. rearranging them so that they are in ascending order. Part 1 -- Implementing the functions Develop these functions, assuming the following headings and specifications are given: int Smallest (int a, int b, int c) // pre: a, b, c are integers // post: result = Min(a,b,c) int Largest (int a, int b, int c) // pre: a, b, c are integers // post: result = Max(a,b,c) int Median (int a, int b, int c) // pre: a, b, c are integers // post: result = a,b, or c && Min(a,b,c) <= result <= Max(a,b,c) int InOrder (int a, int b, int c) // pre: a, b, c are integers
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // post: result == a <= b and b <= c) void Sort (int &a, int &b, int &c) // pre: a, b, c are integers // post: the value of a,b, and c are rearranged so that a <= b and b <= c Part 2 -- Drive your functions Develop a driver program for your functions. The driver should allow you to test its correctness for a variety of initial arrangements of the values of three integers (x,y, and z) Questions 1. Using just 1's, 2's, and 3's, list all the different ways of rearranging these values that would provide distinct tests for these functions. 2. Consider the entire range of integers that can possibly be supplied to these functions, how many different cases would there be if you were to make an exhaustive test for correctness? Is such an exhaustive test necessary to assure that the functions satisfy their specifications? Explain. 3. Can the function Sort be equivalently rewritten as a "function"? Explain. You're done!...
View Full Document

This note was uploaded on 03/31/2010 for the course CPSC 1301 taught by Professor Khan,s during the Spring '08 term at Columbus State University.

Ask a homework question - tutors are online