Introduction to Programming
with C+ (cont.)
Writing the Program
A simple C+ program
Here is the traditional first C+ program. We might
write it to a file named hello.cpp
/ This program displays Hello World!
Linked Lists - basic
Linked lists intro 1
As an introduction to writing your own classes, you will
implement a priority queue based on an underlying linked
list. But first we need to take a look at the linked list itself
In the first lecture on classes we used the pre-defined library
class string to introduce features of classes and how to use
them to create and manipulate objects.
We now look at the details of defini
Recursion what is it?
With functions we saw that a basic approach to problem
solving is to divide and conquer: break the problem
into sub-problems, solve the sub-problems and then
combine those solutions to create a solution
The string class
An int may be signed or unsigned. If neither is specified
the int is signed.
Signed int: range is from -231 to 231-1 inclusive for most 32bit platforms (-2,147,483,648 to 2,147,483,647).
Unsigned int: onl
the string class (pt. 1)
Intro to classes
Structs allow us to define data types with member
variables to handle compound data.
To go beyond this and add member functions as well,
we define a class.
The class allows us to
Multiple data items
When we call our functions, we can pass built-in types (int,
double, etc.) or type provided by the libraries (e.g string). We
can also pass arrays of a single type.
But what if we
Every variable is stored somewhere in memory.
As we saw in the array bounds demo, the memory
address of a variable can be found using the address-of
cout < &i < " " < &d;
Communicating with our programs
So far, all the data input to our programs has come
from the keyboard, and all the output has been to the
display using cin and cout, the standard input and
This is incon
Intro and Predefined Functions
Breaking a task into subtasks
So far, we've written our programs as a group of statements
in main() cfw_.
If we structured large programs like this, their code would be
very difficult to unders
The need for arrays
An array is used to process a collection of data
of the same type
A list of names
A list of a stocks daily closing price
A list of test scores
Why do we need arrays?
Why not just store each data item in a se
Flow of Control 2
Reminder: Control Structures
Almost all of our demo programs so far have taken this
form sequences of executable statements.
Where certain statements or sequences of statements
Flow of Control 1
More than 40 years ago, when structured programming was
dominant, it was proved that every program, regardless of
complexity, could be rewritten using only subunits of three
Data Types and
Recall from previous class
Main memory provides temporary storage for data and for
the program being executed.
A library used to be only a building with a lot of books and a very
quiet place to me. I had never wanted to enter a traditional library because
it was a boring place for a child. Since I became a senior high school
student, I have more homework