CISC1600: Computer Science I Lab 8

Purpose: In this lab assignment of CIS1600, we will practice using array and functions to solve a problem.

Instruction: We will write a program that prompts the user to enter a sequence of positive integers (ending with -1), reports the smallest value among these integers, and then displays these integers and their difference from the smallest value. Please name your source code as lab8.cpp.

Your program works as follows. Note that you are not required to design and implement functions in this lab, you can write all the codes in the main():

  1. Declare an array of int type with capacity 50. Note, please declare a global named constant for 50.
  2. Prompt the user to enter positive integers, and using -1 to indicate the end of input.
  3. Read these integers into the array.
  4. Find the smallest value in this array.
  5. Find the largest value in this array.
  6. Display each of the array element, and its difference from the smallest value, and the largest value.

An example run of your program is as follows, where the user inputs are underlined, and the program output are shown in regular format:

$ ./a.out
Please enter up to 50 positive integers, ending with -1:32 30 12 3 100 29 1 42 80 90 -1
The smallest value is 1.
The largest value is 100.
All values and their difference from smallest and largest values are:
32 31 68
30 29 70
12 11 88
3 2 97
100 99 0
29 28 71
1 0 99
42 41 58
80 79 20
90 89 10
Structure Requirement:

Please write the following functions for this lab. You can introduce more functions, but minimally, you need to practice writing the following two functions, and call them in main.

Coding Style Requirement:
  1. Please indent your code in as required.
  2. Use descriptive names for variables
  3. Use blank lines to separate the code into appropriate blocks
  4. Be sure to include comments to help others understand your program, and help yourself think!

How to submit

Please submit your program (which has to be named lab8.cpp) to the following webpage:

Lab8 submission link.