COMP2003 - Lecture 3 - Expressions
COMP2003 - Lecture 3 - Expressions
Introduction to
Computer Programming
Lecture 3
Expressions, Type Conversion, and string
1
Mathematical Expressions
evaluate
evaluate evaluate third
second first
Order of Operations
Use of Parenthesis to override the order
m = (y2-y1) /(x2-x1);
Algebraic Expressions
Activity 5
• Create a program temperature.cpp to take a Celsius value from user
input and convert it to equivalent Fahrenheit value.
int x, y, z;
x = y = z = 5;
sum = sum + 1;
Continued…
More Stream Manipulators in Program 3-17
Activity 6
• Modify your Activity 5 program to display the Fahrenheit value only for 2
decimal places.
• Using cin with the >> operator to input strings can cause
problems:
• It passes over and ignores any leading whitespace characters
(spaces, tabs, or line breaks)
• To work around this problem, you can use a C++ function
named getline.
Using getline in Program
string Member Functions and Operators
Q & A Session?
31