CS35 Lab1: Introduction to C++

Due 11:59pm Wednesday, January 25

The goal of this lab is to gain more comfort with C++ functions and arrays. We will practice using arrays to process a list of numbers in various ways. A skeleton version the program will appear in your cs35/labs/01 directory when you run update35. The program handin35 will only submit files in this directory. In later labs you may have the opportunity to work with a partner, but for this lab you should work on your own.

Introduction

For this lab you will prompt the user to enter a series of integers in a given range. Then you will perform some statistical analyses on the data and report the results. The most common statistical measure is the mean, which is simply the average. Another useful measure is the standard deviation, which provides an indication of how much the individual values in the data differ from the mean. A small standard deviation indicates that the data is tightly clustered. A large standard deviation indicates that the data is widespread. Finally, a histogram is a graphical way of summarizing the data by dividing it into separate ranges and then indicating how many data values fall into each range. Here is a sample run of a program that performs these three statistical analyses:

This program calculates statistics on a set of given data.
It calculates the mean, standard deviation, and prints a 
histogram of the values.

Enter integers in the range 0-100 to be stored, -1 to end.
> 90
> 89
> 97
> 95
> 123
Invalid value, try again.
> 84
> 71
> 78
> 88
> 82
> 100
> 55
> -1
Read in 11 valid values.

Mean: 84.455

Standard deviation: 12.324

Histogram:
   0 -    9: 
  10 -   19: 
  20 -   29: 
  30 -   39: 
  40 -   49: 
  50 -   59: *
  60 -   69: 
  70 -   79: **
  80 -   89: ****
  90 -   99: ***
 100 -  100: *
Program Requirements
Develop your program incrementally. Create a main function first. Declare the array that will hold the data here and pass it to the functions for processing. The capacity of your array should be at least 50. Add the required functions one at a time, testing each one by calling it from main. Remember that you will need to declare the functions above main and then define them below main. Once you are convinced that a function is correct, move on to the next required function.
Extra Challenges
You should not attempt to solve these problems until you solve the rest of the lab. This will not earn any extra credit, but is a good way to challenge your understanding of the concepts. While it won't help your score, it will give you major street cred.

First, try to think of implementation of your data array that does not have a capacity for user input. That is, no matter how many values the user enters, your array does not need to grow. The array size should still be small, e.g., a capacity of 200 that can still handle 500 values of user-input.

If you've figured that one out, try adding any additional function to print out a stem-and-leaf display - a statistics display similar to a histogram but without any lost information. See here for details. For the sample run above, your stem-and-leaf plot will look as follows:

Stem-leaf plot: 
   0 -    9: 
  10 -   19: 
  20 -   29: 
  30 -   39: 
  40 -   49: 
  50 -   59: 5
  60 -   69: 
  70 -   79: 18
  80 -   89: 2489
  90 -   99: 057
 100 -  100: 0
Notice that each * in the histogram was replaced by the actual singles digit in the data. Also, each row of values is sorted and may contain duplicates.
Submit
Once you are satisfied with your code, hand it in by typing handin35. This will copy the code from your cs35/labs/01 to my grading directory. You may run handin35 as many times as you like, and only the most recent submission will be recorded.