The Usual Suspects

This class is pretty much just about typical operations using arrays. For the moment we won't worry about putting these operations in functions!

Statistical Operations

You may want the files data.txt and numbers.txt.
  1. min & max
  2. average
  3. standard deviation

Other Array Problems

  1. Start with the program:
    
    #include <iostream>
    using namespace std;
    
    int main()
    {
      // read size n, allocate array of n doubles, read values into array
      int n;
      cin >> n;
      double * A = new double[n];
      for(int i = 0; i < n; i++)
        cin >> A[i];
    
      // Now what?
    
      return 0;
    }
    
    ... and add code after the "Now what?" comment to solve one of the problems below for the array A of n elements created in the first part of the code.
    1. Print out the index of the minimum element in the array. So, for example:
      ~/$ ./ex1a
      4
      34 12 8 29
      minimum element is A[2] = 8.
      Solution: TE7a.cpp
    2. Print elements of the array, separated by commas. So, for example:
      ~/$ ./ex1b
      4
      34 12 8 29
      A = [34, 12, 8, 29]
      Solution: TE7b.cpp
    3. Create and print array of the "partial differences" of consecutive elements in the array. Here's an example of a sequence of four numbers along with the sequence of partial differences (note that there are only three elements in that sequence).
      3  7   8   5
      \_/ \_/ \_/
       2   1  -3
      A run of your program should look like this:
      ~/$ ./ex1c
      4
      14 16 8 29
      2 -8 21
      Solution: TE7c.cpp
    4. Split positive and negative. I actually want you to create two new arrays, one containing the positive elements of A, and one containing the negative elements of A. Zero's in A should be ignored. These arrays should be exactly the right size (no extra cells), and you program should print each array out. A run of your program should look like this:
      ~/$ ./ex1d
      10
      0 1 2 -3 4 -5 -6 7 8 9
      negative: -3 -5 -6
      positive: 1 2 4 7 8 9
      Solution: TE7d.cpp
  2. histograms (arrays of counters)
  3. masks (i.e. an array of bools), for example to implement a simple hangman game.