Showing 1 to 27 of 27

PIC 10A
Lecture 23: Pointers
Pointers
Recall that while we think of variables by their names
like:
int numbers;
Computer likes to think of variables by their memory
address:
0012FED4
A pointer is a variable that stores the address of
another variable.
Mem

PIC 10A
Lecture 9: while loop
Lets get loopy
Often we want to repeat a lines of code over and
over again. We could rewrite the lines a few times if
they are short. But what about when we want to
repeat the code hundreds or millions of times?
We need an ea

PIC 10A
Lecture 8: if statement
if
int a,b;
cin > a > b;
if (a >= b)
cfw_
cout > "First number is bigger";
If the expression in parenthesis is true then the code block under if gets
executed. Otherwise we skip over it.
if - else
int a,b;
int max;
cin > a

PIC 10A
Lecture 10: do while and for
loops
do - while
Syntax:
do
cfw_
Semicolon!
/* code */
while( boolean expression);
Main difference between while and do loop is that
the do loop runs always at least once.
The condition is checked after the code is ru

PIC 10A
Lecture 6: Graphics
Why are we studying graphics?
For some time we are going to be using graphics libraries created by the
authors of our book.
The books way of creating graphics is not the standard way.
Ok so why do we bother to study it?
Its fun

PIC 10A
Lecture 7: Graphics II and intro
to the if statement
Setting up a coordinate system
By default the viewing window has a coordinate system already set up for
you
10
-10
10
-10
The origin is in the middle of the screen
-10 < x < 10
-10 < y < 10
Sett

PIC 10A
Lecture 4: String class
String literals
A string literal is just some text in quotes eg:
Homer Simpson
We have already used string literals in our code with cout
cout < "Homer Simpson";
string variables
We would like to have variables that store s

PIC 10A
Lecture 5: Using Classes
More about the string class
We have already seen the length and substr member function of
the string class. Let us look at some others.
insert
my_string.insert(location,some_string);
Inserts string some_string into string

PIC 10A
Lecture 3: More About
Variables, Arithmetic, Casting,
Assignment
Assigning values to variables
Our variables last time did not seem very variable. They always had the
same value!
Variables stores a value.
This value can be changed.
int x=7;
cout <

PIC 10A
Lecture 1: Hello World!
The Very Basics
W hat is a computer?
Seriously?
What is a computer program?
Series of commands that the computer interprets and
executes.
For a program to accomplish a task the commands
must be put together in a meaningf

PIC 10A
Lecture 2: Variables, Data
types, I/O
Data types
In C+ programs we will deal with different types of data, such as integers,
doubles (also called floating-point numbers) as well as strings and booleans.
There are many reasons to label data with ty

PIC 10A
Lecture 11: Functions
What is a function
In mathematics a function is a recipe for constructing
an output for a given input.
eg.
f(x) = x2+2x+7
We put in a number for x and get out a new number.
In computer science, function often behaves in same

PIC 10A
Review for Midterm I
Midterm I
Monday, Oct 28, 11.00am-11.50am.
Try to show up 5 min early so we can start on time.
Exam will cover all material up to and including todays lecture.
How to study for the exam
Read the slides.
Work through as many

PIC 10A
Lecture 15: User Defined
Classes
Intro to classes
We have already had some practice with classes.
Employee
Time
Point
Line
Recall that a class is like a souped up variable that can store data, but it also
comes with member functions.
Object name
P

PIC 10A
Lecture 25: Pointers and Arrays
Arrays and pointers
Consider an an array
int numbers[5];
/Lets assume numbers array gets filled somehow
Earlier we noted that you cannot output an array by
cout < numbers;
But if you try you will not get an error. O

PIC 10A
Lecture 21: File I/O
Reading and Writing to Files
Good news! If you understand cin/cout you are
already halfway to understanding reading and writing
to files.
cin and cout are examples of stream objects that read
and write to the console.
We will

PIC 10A
Lecture 24: The real point of
pointers
Why use pointers?
Using pointers to manipulate values of int variables may be neat, but
it is not what pointers were created for.
Pointers are ideally suited for creating and keeping track of
relationships be

PIC 10A
Lecture 20: Arrays
What are arrays?
Arrays are much like vectors in the sense that they hold data of a
same type stored sequentially.
Like vectors elements of the arrays are accessed using an index.
Arrays are a more primitive C+ construct than ve

PIC 10A
Review for Midterm II
Midterm II
Monday, November 18, 11.00am-11.50am
Try to show up at least 5 min early so we can start on time.
The exam will focus on the material covered since Exam 1.
Ch. 3: Random numbers
Ch. 5: Classes, overloading
Ch. 6:

PIC 10A
Lecture 18: Vectors
Vectors
You may have wished at some point during your
programming that you could have tens or hundreds of
variables that you could keep saving data in.
Maybe you needed a variable number of variables.
Perhaps in a loop a user i

PIC 10A
Lecture 19: More about Vectors
Passing vectors to functions
We have already seen how to pass vectors to
functions. However, the method we have used has
some disadvatages.
We have passed vectors by value in all previous
examples.
What if the vector

PIC 10A
Lecture 17: Classes III,
overloading
Function overloading
Having multiple constructors with same name is example of something called
function overloading.
You are allowed to have functions with same names provided that:
1) They have different numb