100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Summary

COS132 Chapter 4 Summary

Rating
-
Sold
-
Pages
9
Uploaded on
20-04-2022
Written in
2021/2022

Summary study book Starting Out with C++ of Tony Gaddis - ISBN: 9789332536661 (Detailed summary)










Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Summarized whole book?
Yes
Uploaded on
April 20, 2022
Number of pages
9
Written in
2021/2022
Type
Summary

Content preview

COS132 Chapter 4



COS 132
CHAPTER 4 – MAKING DECISIONS
UNIT 4.1- RELATIONAL OPERATORS

Relational operators allow you to compare numeric and char values and determine whether one is greater than, less
than, equal to, or not equal to another.




All of the relational operators are binary, which means they use two operands. Statements such as x > y is called a
relational expression.


THE VALUE OF A RELATIONSHIP
Relational expressions are also known as Boolean expressions, which means their value can be true or false.


WHAT IS TRUTH?
How does a comp store true and false in memory? It converts these two abstract states to numbers, true is represented
by the number 1 and false is represented by the number 0.

UNIT 4.2 – THE IF STATEMENT

The if statement can cause other statements to execute only under certain conditions. The if statement falls under the
category of a decision structure.

An action is only performed if a certain criteria is met/true, the action is conditionally executed bc it is performed only
when a certain condition exists.


BE CAREFUL W SEMICOLONS
If you place a semicolon after the if(expression) statement, the compiler will assume you are placing a null statement
there, the null statement is an empty statement that does nothing, this will terminate the if statement.




1|P a g e

, COS132 Chapter 4

PROGRAMMING STYLE AND THE IF STATEMENT
There are two important style rules:

 The conditionally executed statement should appear on the line after the if statement.
 The conditionally executed statement should be indented one ‘level’ from the if statement


COMPARING FLOATING-POINT NUMBERS
Because of the way floating-point numbers are stored in memory, rounding errors sometimes occur. This is because
some fractional numbers cannot be exactly represented using binary. To prevent round-off errors from causing this type
of problem, you should stick w greater than and less than comparisons w floating-point numbers.


AND NOW, BACK TO TRUTH
0 is still considered false, but values other than 0 are considered true, this means that any value, even a negative
number represents true.

Summary of rules we have looked at so far:

- When a relational expression is true – has the value of 1
- When a relational expression is false – has the value of 0
- Any expression that has the value of 0 is false, and vise versa
- Any expression that has the value of 1 is true, and visa versa

If (value)

Cout << “it is true!”

This if statement tests the contents of a variable, if the variable contains any number other than 0 the message will be
displayed.

UNIT 4.3 – EXPANDING THE IF STATEMENT

The if statement can conditionally execute a block of statements enclosed in brackets.

If (expression)
{
Statements; //block of code
Statements;
}




2|P a g e

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
jennamortonx IIE Varsity College
View profile
Follow You need to be logged in order to follow users or courses
Sold
18
Member since
3 year
Number of followers
1
Documents
49
Last sold
5 months ago

4,0

1 reviews

5
0
4
1
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card or EFT and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions