Preview

comp sci info

Satisfactory Essays
Open Document
Open Document
601 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
comp sci info
CSP2104-5107: Object-Oriented
Programming in C++
Lecture 03
Making Decisions
Prof. A. Taleb-Bendiab
Room 13.213
a.taleb-bendiab@ecu.edu.au
Blackboard

Prof. A. Taleb-Bendiab, Unit: Object-Oriented Programming in C++, Code: CSP2104-5107, Lecture: 03, Date: 05/03/2013, Page: 1

Unit Review: Module 03


So far …





This Lecture











Lecture 1: Introduction to OO
Lecture 2: Evaluating C++ Expressions
Use the if and if-else statements
Use nested if statements
Avoid common pitfalls with if statements
Use the switch statement
Use the conditional operator
Use the logical AND and the logical OR
Make decisions with structure fields

Book:


Object-Oriented Programming Using C++, Fourth Edition

Prof. A. Taleb-Bendiab, Unit: Object-Oriented Programming in C++, Code: CSP2104-5107, Lecture: 03, Date: 05/03/2013, Page: 2

Using the if Statement #1


C++ supports all standard control structures:



if statement if-else statement switch statement



Conditional operators









You can combine decisions using the logical AND and OR operators
The Single-Alternative if




if: primary C++ selection structure statement used to perform a single-alternative selection
Syntax:


if (Boolean expression)
 {action if true}
 else { expression};

Prof. A. Taleb-Bendiab, Unit: Object-Oriented Programming in C++, Code: CSP2104-5107, Lecture: 03, Date: 05/03/2013, Page: 3

Using the if Statement #2

Prof. A. Taleb-Bendiab, Unit: Object-Oriented Programming in C++, Code: CSP2104-5107, Lecture: 03, Date: 05/03/2013, Page: 4

The Single-Alternative if #3


Note the difference between the following


Example 1:

Execute as



Example 2:

Execute as

Prof. A. Taleb-Bendiab, Unit: Object-Oriented Programming in C++, Code: CSP2104-5107, Lecture: 03, Date: 05/03/2013, Page: 5

The Dual-Alternative if


if-else structure





Syntax
if

You May Also Find These Documents Helpful