Structured Programming with C++

6 downloads 594 Views 5MB Size Report
using namespace std; which indicates to the system where the standard library is. • Insert the following statement as


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 Program

58

3.16

Double Loop

60

3.17

Roll Dice

61

3.18

Two Dice Roll

63

3.19

Breaking Entry with Ctrl-Z

64

3.20 Pools

65

3.21 Equation

67

3.22

69

Interrupting a Loop - break

3.23 Summary

70

3.24 Exercises

70

4 Arrays

73

4.1 Introduction

73

4.2

Why Arrays

73

4.3

Declaring an Array

74

4.4

Initiating an Array

75

4.5

Copying an Array

76

4.6

Comparing Arrays

76

4.7 Average

77

4.8

80

Sales Statistics

The Wake the only emission we want to leave behind

.QYURGGF'PIKPGU/GFKWOURGGF'PIKPGU6WTDQEJCTIGTU2TQRGNNGTU2TQRWNUKQP2CEMCIGU2TKOG5GTX 6JGFGUKIPQHGEQHTKGPFN[OCTKPGRQYGTCPFRTQRWNUKQPUQNWVKQPUKUETWEKCNHQT/#0&KGUGN6WTDQ 2QYGTEQORGVGPEKGUCTGQHHGTGFYKVJVJGYQTNFoUNCTIGUVGPIKPGRTQITCOOGsJCXKPIQWVRWVUURCPPKPI HTQOVQM9RGTGPIKPG)GVWRHTQPV (KPFQWVOQTGCVYYYOCPFKGUGNVWTDQEQO

6 Download free eBooks at bookboon.com

Click on the ad to read more

Structured Programming with C++



4.9

Product File, Search

85

4.10

Two-Dimensional Array

85

4.11 Sorting

87

4.12

90

Searching a Sorted Array

4.13 Summary

94

4.14 Exercises

94

5 Strings

96

5.1 Introduction

96

5.2

Quantity:

"