The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.

Full list of contents in C++ Programming for Beginners.

Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by tengsaw, 2022-10-04 01:54:19

C++ Programming for Beginners

Full list of contents in C++ Programming for Beginners.

Contents

Dedication iii
Preface iv
Acknowledgements v
Contents vi
MAXUNION PUBLICATION
Chapter 1 INTRODUCTION TO COMPUTER PROGRAMS 1

1.0 Introduction 1

1.1 Overview of Computers 2

1.1.1 A Brief Overview of The History of Computers 2
1.1.2 Definition of Computer 2

1.1.3 Categories of Computer 3
1.1.4 The Basic Operations of a Computer 4
1.1.5 Computer System 5

1.2 Computers and Programming Languages 8

1.2.1 The Language of a Computer 8
1.2.2 Types of Programming Languages 10

1.3 Introduction to Programming 11

1.3.1 Differences Between Software, Programs and Programming 11
1.3.2 The Importance of Computer Programming 12
1.3.3 The Importance of Writing a Good Program 12

1.3.4 C++ Relationship Between Programs, Compiler, Interpreter and
Assembler 14

1.4 Program Development Life Cycle 15

1.4.1 Analysis 15
1.4.2 Design 15
1.4.3 Implementation/Coding 24

1.4.4 Testing/Debugging 24
1.4.5 Maintenance 24

1.5 Conclusion 25

Summary 25
Exercises 26
Multiple-choice Questions 26
Short-answer Questions 27
Discussion Questions 30

MAXUNION PUBLICATIONChapter 2 BASIC ELEMENTS OF COMPUTER PROGRAMS 33

2.0 Introduction 33
2.1 C++ Program Stucture 33

2.1.1 Comments 36
2.1.2 Pre-processor directive 37
2.1.3 Functions 37

2.2 Variable, Identifiers, Constants and Reserved Words 38
2.3 Data Type In C++ 40

2.3.1 Numeric Data Types 41
2.3.2 Character Data Type 42
2.3.3 String Data Type 42
2.3.4 Logical Value Data Type 43

2.4 Variable And Constant Declaration 44

2.4.1 Variable Declaration 44
2.4.2 Constant Declaration 45

2.5 Arithmetic Expressions 47

2.5.1 Arithmetic Operators 47
2.5.2 Mixed Type Expressions 49
2.5.3 Assignment Statement 49
2.5.4 Precedence and Associativity 51
2.5.5 Increment and Decrement Operators (Postfix and Prefix Operators) 52
2.5.6 Unary and Binary Operators 55

2.6 Mathematical Library Functions 56
2.7 Input and Output Statements 58

2.7.1 Input Statement for Numeric and Character Variable 58
2.7.2 Input Statement for String 59
2.7.3 Output statement 60

2.8 Formatting Output Statements 61

2.8.1 Escape Sequence 61
2.8.2 Predefined Formatting Function 63

2.9 Errors in C++ Programming 66
2.10 Program Debugging and Error Handling 68
2.11 Conclusion 75

Summary 75
Exercises 77
Multiple-choice Questions 77
Short-answer Questions 78
Discussion Questions 84

Chapter 3 SELECTION CONTROL STRUCTURE 87

3.1 Boolean Expressions 88

3.1.1 Relational Operators 88
3.1.2 Logical Operators 92
3.1.3 Compound Boolean Expressions 94

3.2 Types of Selection Control Structures 95

3.2.1 if Statement 95
3.2.2 switch Statement 108

3.3 Nested Selection (Multi-Way Selection) 117
3.4 Conclusion 123

Summary 124
Exercises 125
Multiple-choice Questions 125
Short-answer Questions 127
Discussion Questions 131
MAXUNION PUBLICATION
Chapter 4 REPETITION CONTROL STRUCTURE 135
146
4.0 Introduction 135
4.1 Loop Control Variable (LCV) 137

4.1.1 Initialization 137
4.1.2 Evaluation 137
4.1.3 Updating 138

4.2 Repetition/Iteration Control Structure 139

4.2.1 Repetition using while loop 139
4.2.2 Repetition using do. . .while Statement 141
4.2.3 Repetition using for Statement 144

4.3 Ways of Writing a Repetition Control Structure

4.3.1 Counter-controlled Structure 146
4.3.2 Sentinel-controlled Structure 148
4.3.3 Flag-controlled Structure 150

4.4 Nested Loop 151
4.5 Using break and continue in Looping 154

4.5.1 break statement 154
4.5.2 continue statement 155

4.6 Conclusion 156

Summary 156
Exercises 158
Multiple-choice Questions 158
Short-answer Questions 160
Discussion Questions 163

MAXUNION PUBLICATIONChapter 5 FUNCTIONS 167

5.0 Introduction 167
5.1 Function Types 168

5.1.1 Predefined Functions 168
5.1.2 User-defined Functions 183
5.1.3 Types of Variable and Their Scope 190
5.1.4 Parameter Passing 193

5.2 Conclusion 204

Summary 204
Exercises 205
Multiple-choice Questions 205
Short-answer Questions 207
Discussion Questions 212

Chapter 6 ARRAYS 215

6.0 Introduction 215
6.1 One-Dimensional Arrays 217

6.1.1 Array Declaration 217
6.1.2 Array Initialization 218
6.1.3 Restrictions in Array Operation 220
6.1.4 Accessing Array Elements 221

6.2 Two-Dimensional Arrays 228

6.2.1 Accessing and Initialization for 2D Arrays Components 229

6.3 Array of Characters 233

6.3.1 Accessing and Initialization of String 233

6.4 Array Operations 235

6.4.1 Summation 236
6.4.2 Finding the Maximum 238
6.4.3 Finding the Minimum 240

6.5 Passing Array to Function 241
6.6 Conclusion 248

Summary 249
Exercises 250
Multiple-choice Questions 250
Short-answer Questions 252
Discussion Questions 254

Glossary 255
References 259
Index 260

C++ PROGRAMMING FOR BEGINNERS

This book is intended for engineering and computer science students pursuing basic courses on C++
programming. The aim of the book is to assist students in mastering the art of writing C++ programs,
enabling them to produce effectiveC++ programs. A comprehensive pedagogical approach is adopted for
this book, which includes extensive examples and figures, interspersed with review questions, programming
tips, keywords and end-of-chapter practices. The book opens with an introductory chapter on computers
and computer programs, followed by a detailed introduction toC++ programming. It then moves on to an
analysis of the various constructs inC++ such as the selection and repetition control structures, as well as
functions and arrays.

KEY FEATURES

• Presents programming topics in an accessible and engaging manner.
• Enables students to check their understanding through review questions interspersed

throughout the chapters.
• Assists students in applying programming techniques through the many examples

provided.
• Provides chapter snapshots via a summary section at the end of each chapter.
• Reinforces students' grasp of the topics through a variety of knowledge, comprehension and

application exercises.

NEW TO THIS EDITION

• Text amended and reorganized to assist students' understanding of the content.
• Revised examples and questions to include application-type programs to further facilitate

comprehension and demonstrate real-world applications ofC++ programming.
• Additional engineering-related examples to familiarize students with programming in the

engineering fields.

Wan Anisha Wan Mohammad is a senior lecturer at the Department ofComputer and Mathematical
Sciences, UiTM Cawangan Pulau Pinang. She holds a Master of Science in Information Technology.

Azlina Mohd Mydin is a senior lecturer at the Department ofComputer and Mathematical Sciences, UiTM
Cawangan Pulau Pinang. She holds a Master of Science in Computer Sciences, majoring in Software
Engineering.


Click to View FlipBook Version