CSCI 261 - Programming Concepts - Spring 2022

Lab 3A - Array Min/Max

This lab is due by Thursday, March 03, 2022, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.


Instructions


With arrays, we need to specify the size of our array at compile time - and that size cannot change. Therefore, we need to think of the max number of items we may store. We could always use less than the allotted array size, but we can't use more.

Create a program that prompts the user for up to fifteen non-zero whole numbers. The user can either:

The values entered by the user need to be stored in an array. When the user is done entering values, print out the contents of the array. An example interaction follows:

Enter up to 15 non-zero numbers.  Enter zero to signal the end of data or enter all 15 items:
Number 1: 8
Number 2: 6
Number 3: 7
Number 4: 5
Number 5: 3
Number 6: 2
Number 7: 4
Number 8: 1
Number 9: 3
Number 10: 13
Number 11: 32
Number 12: 14
Number 13: 25
Number 14: 51
Number 15: 9
The numbers are: 8 6 7 5 3 2 4 1 3 13 32 14 25 51 9
Have a nice day!

Another example is below:

Enter up to 15 non-zero numbers.  Enter zero to signal the end of data or enter all 15 items:
Number 1: 8
Number 2: 6
Number 3: 7
Number 4: 5
Number 5: 3
Number 6: 2
Number 7: 4
Number 8: 1
Number 9: 0
The numbers are: 8 6 7 5 3 2 4 1
Have a nice day!

Note for the second example that only 8 values are printed back. Therefore we need to keep track of both the capacity of the array (the max size) AND the used size of the array.

If you are unsure how to get started, here are the suggested steps:

  1. Declare an array of fifteen integers (which you access with 0 to 14).
  2. Using a for loop, prompt the user for each number and then assign the entered number to the ith value in the array.
  3. Using a 2nd for loop, output the ith value in the array.

Now, we are going to find the largest and smallest values in the array. After you have printed out the values within the array, iterate through the array searching for the largest value in the array. Then print this value. (There are hints below if you need a starting point.) Then repeat the same process to find the minimum value in the array. An example interaction follows:

Enter up to 15 non-zero numbers.  Enter zero to signal the end of data or enter all 15 items:
Number 1: 8
Number 2: 6
Number 3: 7
Number 4: 5
Number 5: 3
Number 6: 2
Number 7: 4
Number 8: 1
Number 9: 3
Number 10: 13
Number 11: 32
Number 12: 14
Number 13: 25
Number 14: 51
Number 15: 9
The numbers are: 8 6 7 5 3 2 4 1 3 13 32 14 25 51 9
The maximum value is: 51
The minimum value is: 1
Have a nice day!

Another example is below:

Enter up to 15 non-zero numbers.  Enter zero to signal the end of data or enter all 15 items:
Number 1: -8
Number 2: -6
Number 3: -7
Number 4: -5
Number 5: -3
Number 6: -2
Number 7: -4
Number 8: -1
Number 9: 0
The numbers are: -8 -6 -7 -5 -3 -2 -4 -1
The maximum value is: -1
The minimum value is: -8
Have a nice day!

If you are unsure how to get started, here are the suggested steps:

  1. Declare a variable for the largest number, and initialize it to be the 1st value in the array.
  2. Using a for loop, read each array value and update the largest number variable (if appropriate). Think carefully about which two values you need to compare.
  3. Print the largest number.

Functional Requirements



Lab Submission


Submit your main.cpp file(s).

You will submit your solution to this lab with the rest of Set3. Detailed instructions for doing this are posted in Assignment 3.


This lab is due by Thursday, March 03, 2022, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.