100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
COS132 Chapter 5 summary $5.07   Add to cart

Summary

COS132 Chapter 5 summary

 15 views  0 purchase
  • Course
  • Institution
  • Book

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

Preview 2 out of 14  pages

  • Yes
  • April 20, 2022
  • 14
  • 2021/2022
  • Summary
avatar-seller
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

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller jennamortonx. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $5.07. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

75759 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$5.07
  • (0)
  Add to cart