Lecture Notes for Introduction to Computer Science II
22 May 2001 - Review and Extensions
- types, values, and operators
- review
- every value has a type
- a value's type determines which operations are legal
- some of the basic types are
char
, int
, double
- also known as the primitive, atomic, built-in, or pre-defined types
- some types are related to other types - a
char
is an int
is
a double
- extensions
- arrays
- review
- an array is a collection of identically typed values
- the values are known as elements; the values' type is known as the
element type or the array base type
- almost any type can be an array base type, even another array type
- an array's size is the number of values it can hold.
- an array's size is fixed, it can not easily be changed
- elements in an array are named by an integer called the array index
- legal index values run from 0 to n - 1
- the square bracket operator
[]
access array elements
- what kind of value is an array
- extensions
- functions and parameters
- review
- a function acts like its mathematical counterpart
- it accepts input values and returns an output value
- the input values are known as arguments or parameters
- the output value is known as the return value, the function value, or
the function return value
- the function body is responsible for turning the arguments into the
return value
- extensions
- i-o
- review
- i-o moves data into and out of a program
- c++ i-o is complex
- i-o streams are the simplest way of doing i-o
- the stream insertion operator
<<
and stream extraction operator
>>
insert and remove values into and out of i-o streams
- i-o stream operators can fail
- extensions
- records
- review
- a record is a collection of differently typed values
- the values are known as fields; a value's type is known as the
field type
- almost any type can be a field type, even another record type
- a record in c++ is called a
struct
or a class
- we'll stick
with struct
for the moment
- each field in a
struct
is given a name called the field name or
tag
- each field name in a
struct
must be unique
- the dot operator
.
access struct
fields
- what kind of value is a
struct
- extensions
This page last modified on 21 May 2001.