COM 1100 Fall 2000 -- Prof. Futrelle -- Lab 8 Directions

Accessing files to answer queries

Lab date: Wednesday November 29th. Due Friday December 1st by 4pm.
These directions were posted Sunday, November 26th.

Goal of Lab #8:

This will be a very simple lab, and quick to do (not like Lab 7!). It will give you some basic experience with using arrays, including passing them to functions and sorting arrays. It will also give you a chance to use reference parameters, which allow you to alter variables passed as parameters so that the values of those variables in the calling program are changed.

What you are to do, including references to your textbook:

    The overall goal is to read values into an array, sort them and print out the result.

  1. Create a file, tenfloats.txt of ten floating point number by typing in the file and saving it.

  2. Read the values into a float array, tenFloats[], of size 10 (file input, Chap. 8; arrays, Chap. 9).

  3. Define the exchange() function for floats, pg. 442.

  4. Use the exchange() function in the sort function selSort(), pg. 457, to sort the array.

  5. Print out the sorted array.

Extra Credit

If the assignment above is just too simple for your tastes, try this:

Create a two-dimensional array of characters (Sec. 11.1) of size 20x20. Initially, place a blank character in each element, for a total of 400. Create a function that will "draw" a circle into the array by placing a '*' at points around the perimeter. You can do this using a function such as x = 10 + 8*cos(theta) and y = 10 + 8*sin(theta). Just put these two equations in a for loop and use x and y as the integer values of the index of the positions in which to put the '*'. The loop could gradually increase value of theta from 0 to 2*pi, in increments of pi/40 for example. When the array is filled, print it out on a sequence of 20 lines. See pg. 116 for sin and cos.