CIS 22B - Notes for Monday, 10/1

Announcements and Reminders

  • Assignment 1 is due now
  • Check attendance sheet
  • Online time:  Tuesday 7:00-8:15 pm ConferZoom Web Page 
  • Class TA, Fawzan Khan, is available Tuesday and Thursday 11:30 - 3:45 in the ATC lab 

Comments on Assignment 1

  • Use of variable length arrays
  • Add your OS to the comments at the top of your program
  • What the + or - means
  • Excessive inclusion of header files
  • Watch variable initialization (especially on a Mac)
  • Turn on all warnings on your compiler

Review Topics


What is an array? 

one variable, multiple parts, contiguous memory
pass entire array to a function
traverse an array
sort, search it

How to ...

  • Declaration
How big is an array?
An array's address
  • Indexing
Segmentation fault
  • Traversing an array
Using a for loop
  •  Passing an array to a function
How big is an array?
Passing an array as a const
  • Passing an array element to a function
Swapping array elements


  1. Calculate the sum of an array
  2. Calculate the average of an array
  3. Calculate the maximum of an array


Lab Exercise #2

Put your name, the compiler used, and Lab Exercise #2 in a comment at the top of your program. Email only your source code.

The file below contains first and last names and the radii of circles.  You'll need to cut and paste the data into a text file.  Write a program to read the file and store the first names and the radii in two arrays.  You'll need an array of type string and an another array of some numeric type.  The arrays should each hold 12 elements.  Then, print out the first names and the circle areas, each in a column of width 11.  Make sure you match the implied output format and that you check for a successful file open.  Include a function to calculate of the circle area, using the formula:

Circumference = 2 * PI * radius

For PI, use a named constant equal to 3.1416

Input data - copy to a text file and make sure there is a newline at the end of the last line in the file.

LoriBeth Allen      79
Chachi Arcola      125
Richie Cunningham  171
Howard Cunningham  255
Marion Cunningham  252
Joanie Cunningham  234
Al Delvecchio      122
Arthur Fonzarelli  255
Ralph Malph        165
Roger Phillips      61
Jenny Piccalo       55
Potsie Weber       210

Program Output

LoriBeth      19606.73
Chachi        49087.50
Richie        91863.53
Howard       204282.54
Marion       199504.17
Joanie       172021.45
Al            46759.57

Happy Days