Lecture 3
Lecture 3
By
Anam Javaid
Pseudo code
Flow Chart
Identifiers
Variables
14
15
Numerical Data Types
Name Range Storage Size
bool values
true false
19
What is a Variable?
• A variable is a memory address where data can be stored and
changed.
• Declaring a variable means specifying both its name and its data type.
What Does a Variable Declaration Do?
• A declaration tells the compiler to allocate enough memory to hold a
value of this data type, and to associate the identifier with this
location.
• int ageOfDog;→
• char middleInitial; →
• float taxRate;→
Variable Declaration
• All variables must declared before use.
• At the top of the program
• Just before use.
• Commas are used to separate identifiers of the same
type.
int count, age;
• Variables can be initialized to a starting value when
they are declared
int count = 0;
int age, count = 0;
Trace a Program Execution
#include <iostream> allocate memory
using namespace std; for radius
5
Trace a Program Execution
#include <iostream> memory
using namespace std;
radius no value
int main() { area no value
double radius;
double area;
allocate memory
// Step 1: Read in radius for area
radius = 20;
system("PAUSE");
return 0;
}
10
Reading Multiple Input in One Statement
Example : #include <iostream>
Compute average
int main()
of three numbers. {
double x1, x2, x3, average;
system("PAUSE");
return 0;
}
11
What is an Expression in C++?
• An expression is a valid arrangement of variables, constants, and
operators.
• In C++, each expression can be evaluated to compute a value of a
given type
• int ageOfDog;→
• char middleInitial; →
• float taxRate;→
Variable Declaration
• All variables must declared before use.
• At the top of the program
• Just before use.
• Commas are used to separate identifiers of the same
type.
int count, age;
• Variables can be initialized to a starting value when
they are declared
int count = 0;
int age, count = 0;
What is an Expression in C++?
• An expression is a valid arrangement of variables, constants, and
operators.
• In C++, each expression can be evaluated to compute a value of a
given type
Operators
Evaluating Mathematical Expression