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

COS132 Chapter 5 summary

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

Summary study book Starting Out with C++ of Tony Gaddis - ISBN: 9780132926867 (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
14
Written in
2021/2022
Type
Summary

Subjects

Content preview

COS132 Chapter 5



COS 132
CHAPTER 5 – LOOPS AND FILES

UNIT 5.1- THE INCREMENNT AND DECREMENT OPERATORS

++ and – are operators that add and subtract 1 from their operands.

The expression num++ is pronounced num plus plus and the expression num—is pronounced num minus minus.


THE DIFFFERENCE BETWEEN POSTFIX AND PREFIX MODES

Cout << num++; postfix mode

The above statement is doing two things, first it is displaying the value of num and then it is incrementing it.

Cout << ++num; prefix mode

In this statement, the increment will happen first.


USING ++ AND – IN MATHEMATICAL EXPRESSIONS

a = 2;

b = 5;

c = a * b++; // c is assigned the value of a times be which is 10, then the variable b is
incremented

Cout << a << “ “ << b << “ “ << c; //This will display 2 6 10

Using ++ and – in relational expressions

X = 10;

If(x++ > 10) // comparison happens first, then its incremented

Cout << “x is greater than 10. \n”; //will not execute




If(++x > 10) // increment happens first, then its compared
1|P a g e

, COS132 Chapter 5

Cout << “x is greater than 10. \n”; //will execute


UNIT 5.2 – INTO TO LOOPS: THE WHILE LOOP

A loop is part of a program that repeats.


THE WHILE LOOP

It has two important parts:

1. An expression that is tested for a true or false value
2. A statement or block that is repeated as long as the expression is true

While(expression) // loop header

Statement; // body of loop, considered a conditionally executed statement

Each repetition of a loop is known as an iteration.


THE WHILE LOOP IS A PRETEST LOOP

This means it tests its expression before each iteration.


INFINITE LOOPS

Continues to repeat the program until the program is interrupted. This can be accidentally created by placing a
semicolon after the first line of the while loop – as it is assumed to be a null statement and disconnects the while
statement from the block that comes after it.


PROGRAMMING STYLE AND THE WHILE LOOP

- If there is only one statement repeated by the loop it should appear on the line after the while statement and be
indented one additional level
- If the loop repeats a block, each line inside the braces should be indented.




UNIT 5.3 – USING THE WHILE LOOP FOR INPUT VALIDATION


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