Lecture 23: Pointers
Recall that while we think of variables by their names
Computer likes to think of variables by their memory
A pointer is a variable that stores the address of
Lecture 12: Functions II
functions calling other functions
It is quite common for a function to call another function.
double calculate_money(int checking_num, int savings_num)
double checking_amount = checking(checking_num);
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
Lecture 8: if statement
cin > a > b;
if (a >= b)
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
cin > a
Lecture 10: do while and for
do - while
/* 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
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?
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
The origin is in the middle of the screen
-10 < x < 10
-10 < y < 10
Lecture 4: String class
A string literal is just some text in quotes eg:
We have already used string literals in our code with cout
cout < "Homer Simpson";
We would like to have variables that store s
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.
Inserts string some_string into string
Lecture 3: More About
Variables, Arithmetic, Casting,
Assigning values to variables
Our variables last time did not seem very variable. They always had the
Variables stores a value.
This value can be changed.
Lecture 1: Hello World!
The Very Basics
W hat is a computer?
What is a computer program?
Series of commands that the computer interprets and
For a program to accomplish a task the commands
must be put together in a meaningf
Lecture 2: Variables, Data
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
Lecture 11: Functions
What is a function
In mathematics a function is a recipe for constructing
an output for a given input.
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
Review for 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
Lecture 15: User Defined
Intro to classes
We have already had some practice with classes.
Recall that a class is like a souped up variable that can store data, but it also
comes with member functions.
Lecture 25: Pointers and Arrays
Arrays and pointers
Consider an an array
/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
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
cin and cout are examples of stream objects that read
and write to the console.
Lecture 24: The real point of
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
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
Wednesday, December 11, 2013 8:00 AM - 11:00 AM
MS 5200. In our usual class room. (Verify on my.ucla.edu!)
The final exam is worth 30% of your grade, same weight as 2
midterms. Could be 50% if grading option 2 turns out b
Review for 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
Lecture 18: 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
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
We have passed vectors by value in all previous
What if the vector
Lecture 16: Classes II
using namespace std;
Point(double new_x, double new_y)
Lecture 17: Classes III,
Having multiple constructors with same name is example of something called
You are allowed to have functions with same names provided that:
1) They have different numb
Lecture 14: More About Scope,
Variables scope is the section of code where it lives.
If a variable is declared inside a function it only exists inside that function.
void foo (int b)
cout < "Value of b is: " < b <
Introduction to Programming
Lecturer : Jukka Virtanen
TA: Yi-Ping Lai
Thu 13:00-14:00, F