CIS 22B - Notes for Thursday 2/8

  Announcements and Reminders

  • Assignment 5 is due Tuesday
  • Exercise 5 slips - due date is Saturday, 1:30 pm
  • Midterm is next Thursday
  • Class TA, Joshua Kuan, is available Wednesday 9:30-10:30 and Friday 2:30-3:30 in the lab
  • De Anza Women in CS club meeting next Wednesday, Feb 14 12:30-1:30 in the ATC 203 Lab

Structs

A struct is 
  • an abstract data type
  • a composite type
  • a user-defined type
  • almost the exact same thing as a class in C++ (but we'll get to that later)
Structs contain members, accessible through the . (dot) operator, and maybe through the -> (arrow) operator.

Example:

struct something        // struct declaration
{
   int a;               // members
   float b;
   char c;
};

...

something var;          // you can also say "struct something var;"

// assign the members of the something variable (object)
var.a = 19;
var.b = 3.14;
var.c = 'x';

cout << var.a << ' ' << var.b << ' ' << var.c;    // prints 19 3.14 x
...

something* ps;         // ps is a pointer to something
ps = &var;             // assign the address of a struct variable to a pointer

cout << (*ps).a;       // prints 19
cout << ps->a;         // prints 19

struct initialization

Arrays of structs

Structs with arrays

The tm struct

Example

Lab Exercise #5

Put your name, the compiler used, and Lab Exercise #5 in a comment at the top of your program. Email your source code. This lab exercise is due Saturday at 1:30pm.

Write a program to read the input file, shown below and write out the output file shown below.  Use only string objects and string functions to process the data.  Do not use c-string functions or stringstream (or istringstream or ostringstream) class objects for your solution.  

Input File
Cincinnati 27, Buffalo 24
Detroit 31, Cleveland 17
Kansas City 24, Oakland 7
Carolina 35, Minnesota 10
Pittsburgh 19, NY Jets 6
Philadelphia 31, Tampa Bay 20
Green Bay 19, Baltimore 17
St. Louis 38, Houston 13
Denver 35, Jacksonville 19
Seattle 20, Tennessee 13
New England 30, New Orleans 27
San Francisco 32, Arizona 20
Dallas 31, Washington 16


Output File
Cincinnati over Buffalo 27 to 24
Detroit over Cleveland 31 to 17
Kansas City over Oakland 24 to 7
Carolina over Minnesota 35 to 10
Pittsburgh over NY Jets 19 to 6
Philadelphia over Tampa Bay 31 to 20
Green Bay over Baltimore 19 to 17
St. Louis over Houston 38 to 13
Denver over Jacksonville 35 to 19
Seattle over Tennessee 20 to 13
New England over New Orleans 30 to 27
San Francisco over Arizona 32 to 20
Dallas over Washington 31 to 16