CIS 22B - Notes for Tuesday, 9/29

Announcements and Reminders

  • Assignment 1 is due now
  • Attendance using Zoom "waiting room"
  • Virtual Club Day:  Thursday, October 1st, 12:00 - 3:00 pm
  • Tomorrow's online session will be held at 1:30 pm

Review Topics

Recording

Examples

Array Example 1
Array Example 2
Array Example 3

Arrays

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?

Initialization

An array's address

Example 1-9 - How is an array stored in memory?
  • Indexing
Segmentation fault
  • Traversing an array
Using a for loop
  •  Passing an array to a function
How big is an array?

Example

Passing an array as a const
  • Passing an array element to a function
Swapping array elements

Examples

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

Videos

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 last names and the radii in two arrays.  You'll need an array of type string and another array of some numeric type.  The arrays should each hold 14 elements.  Then, print out the last names and the circle areas, each in a column of width 12.  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:

Area = PI * radius * radius

For PI, use a named constant equal to 3.14159265

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
Ashley Pfister      19
Roger Phillips      61
Jenny Piccalo       55
Mitsumo Takahashi   26
Potsie Weber       210

Program Output

Allen          19606.680
Arcola         49087.385
Cunningham     91863.311
Cunningham    204282.062
Cunningham    199503.700
Cunningham    172021.047
Delvecchio     46759.465

...



Happy Days