Structured Programming with C++

using namespace std; which indicates to the system where the standard library is. • Insert the following statement as the last statement in your programs: cin.get(); which makes the program stop and you will get an opportunity to view the console window with the displayed output. Sometimes two cin.get() –statements are ...
5MB Sizes 5 Downloads 508 Views


Kjell Bäckman

Structured Programming with C++

2 Download free eBooks at bookboon.com



Structured Programming with C++ © 2012 Kjell Bäckman & bookboon.com ISBN 978-87-403-0099-4

3 Download free eBooks at bookboon.com

Structured Programming with C++



Contents

About the Book and the Course

11

1

Introduction to Programming

13

1.1

What Does It Mean to Program

13

1.2 Coding

15

1.3

Compiling and linking

16

1.4

The First Steps with Visual C++

17

2 Variables

24

2.1 Introduction

24

2.2

Why Variables

24

2.3

Declaring Variables

2.4 Assignment 2.5

Initiating Variables

2.6 Constants

360° thinking

.

25 25 26 26

2.7

More about Assignment of Values

2.8

The main function

2.9

Input and Output

29

2.10

An Entry Program

31

360° thinking

.

27 28

360° thinking

.

Discover the truth at www.deloitte.ca/careers

© Deloitte & Touche LLP and affiliated entities.

Discover the truth at www.deloitte.ca/careers

© Deloitte & Touche LLP and affiliated entities.

© Deloitte & Touche LLP and affiliated entities.

Discover the truth4at www.deloitte.ca/careers Click on the ad to read more Download free eBooks at bookboon.com

© Deloitte & Touche LLP and affiliated entities.

D

Structured Programming with C++



2.11

Formatted Output

33

2.12

Invoice Program

35

2.13

Time Conversion Program

37

2.14

Type Conversion

39

2.15

The Random Number Generator

40

2.16

Game Program

41

2.17 Summary

42

2.18 Exercises

42

3

45

Selections and Loops

3.1 Introduction

45

3.2 Selection

45

3.3

if statement

45

3.4

Price Calculation Program

3.5

Comparison Operators

3.6

Even or Odd

3.7

else if

3.8

and (&&), or (||)

50

3.9

Conditional Input

51

3.10

The switch statement

52

3.11

Menu Program

52

TMP PRODUCTION

6x4

gl/rv/rv/baf

NY026057B

4

46

12/13/2013 PSTANKIE

48

ACCCTR0

49

Bookboon Ad Creative

49

3.12 Loops

55 All rights reserved.

© 2013 Accenture.

Bring your talent and passion to a global organization at the forefront of business, technology and innovation. Discover how great you can be. Visit accenture.com/bookboon

5 Download free eBooks at bookboon.com

Click on the ad to read more

Structured Programming with C++



3.13

The while Loop

57

3.14

The for Loop

57

3.15

Addition