Pre-Lab - Lab (10)



1) By now you know how to write a C++ program to find the minimum and the maximum of a given set of numbers that are either read from a file or are entered from the keyboard.  In this case, you do not need to remember all the numbers and you can read the numbers one-by-one and compare each one with the max or min and replace the min and/or max with the number in hand, if needed, until the last number is read.  But there are cases where you need to keep track of numbers that are entered or read.  For example, think of these questions.

How do you write a set of 4 numbers in the reverse order?
How will you write a set of 4 numbers in ascending or descending order?
How do you find out how many occurrences of a number you have had in a list?
 
 
 

As you may immediately realize, now you have to remember all the numbers in order to be able to write them in a specific order.

2) Suppose your were asked to write a C++ program to read 4 integer values from the keyboard then find the largest (max) and to display the list of all numbers on one column and their difference with the max on the second column.

Here is an example:

Input: 3 4 5 8
Output:
Max = 8

Num    Diff_from_Max
3            5
4            4
5            3
8            0

How would you do this?
 

3. Suppose I tell you today that you can declare 4 integers x[0], x[1], x[2], and x[3] using:
int x[4];

The above statement will create x[0], x[1], x[2], and x[3].  Use these instead of a,b,c, and d (or any other variables that you have used in problem 2) to solve the problem.
 

3. Take a guess,  how do we define a set of 10 characters using the same method?