Programming!: Beginners To Advance
Programming!: Beginners To Advance
Programming!
Beginners to Advance
www.genial-code.com
Objectives
3
Objectives (continued)
4
The Basics of a C++ Program
• Multiple line
/*
You can include comments that can
occupy several lines.
*/
6
Special Symbols
• Special symbols
+ ?
- ,
* <=
/ !=
. ==
; >=
7
Reserved Words (Keywords)
8
Identifiers
10
Whitespaces
11
Data Types
12
Simple Data Types
13
Simple Data Types (continued)
• Examples:
-6728
0
78
+763
• Positive integers do not need a + sign
• No commas are used within an integer
• Commas are used for separating items in a list
C++ Programming: From Problem Analysis to Program Design, Fourth Edition 16
bool Data Type
• bool type
• Two values: true and false
• Manipulate logical (Boolean) expressions
• true and false are called logical values
• bool, true, and false are 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
• Evaluation rules:
• If operator has same types of operands
• Evaluated according to the type of the operands
• If operator has both types of operands
• Integer is changed to floating-point
• Operator is evaluated
• Result is floating-point
• Entire expression is evaluated according to precedence
rules
C++ Programming: From Problem Analysis to Program Design, Fourth Edition 26
Type Conversion (Casting)
• For example:
#include <iostream>
y = w + x; //Line 4: error
• Named Constant
const double CENTIMETERS_PER_INCH = 2.54;
The numbers you entered are 15 for feet and 7 for inches.
The total number of inches = 187
The number of centimeters = 474.98