C++ Programming: From Problem Analysis To Program Design: Fifth Edition
C++ Programming: From Problem Analysis To Program Design: Fifth Edition
• Learn how to use preprocessor directives and why they are necessary
• Learn how to debug syntax errors
• Explore how to properly structure a program, including using
comments to document a program
• Learn how to write a C++ program
• Computer program
– Sequence of statements whose objective is to accomplish a task
• Programming
– Process of planning and creating a program
+
- ?
* ,
/ <=
.
!=
;
==
>=
• Examples:
-6728
0
78
+763
• bool type
– Two values: true and false
– Manipulate logical (Boolean) expressions
• true and false
– Logical values
• bool, true, and false
– Reserved words
• Mixed expression:
– Has operands of different data types
– Contains integers and floating-point
• Examples of mixed expressions:
2 + 3.5
6 / 4 + 3.9
5.4 * 2 – 13.6 + 18 / 2
• For example:
#include <iostream>
– Causes the preprocessor to include the header file iostream in the
program
y = w + x; //Line 4: error
• In C++, you use one or more blanks to separate numbers when data is
input
– Used to separate reserved words and identifiers from each other and from
other symbols
– Must never appear within a reserved word or identifier
• Possible to remove all syntax errors in a program and still not have it
run
• Even if it runs, it may still not do what you meant it to do
• For example,
2 + 3 * 5 and (2 + 3) * 5
are both syntactically correct expressions, but have different meanings
x *= y;
The numbers you entered are 15 for feet and 7 for inches.
The total number of inches = 187
The number of centimeters = 474.98
• Use cin and stream extraction operator >> to input from the standard
input device
• Use cout and stream insertion operator << to output to the standard
output device
• Preprocessor commands are processed before the program goes
through the compiler
• A file containing a C++ program usually ends with the extension
.cpp