• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 14 pages
Summary

COS132 Chapter 5 summary

Document preview thumbnail
Preview 2 out of 14 pages

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

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

Connected book
 image
Tony Gaddis Starting Out with C++
Publisher: Unknown ISBN: 9780132926867 Edition: Unknown

Document information

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

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

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
3.5
(2)
Sold
30
Followers
1
Items
74
Last sold
1 month ago




Why students choose Stuvia

Created by fellow students, verified by reviews

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

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

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

Student with book image

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

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions