Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/337136941

How to Program in C++ With 100 Examples (Volume-II)

Book · January 2020

CITATIONS READS

0 9,259

1 author:

Zeeshan Ashraf
University of Lahore
10 PUBLICATIONS   22 CITATIONS   

SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Challanges and thier mitigation during co-existance of IPv4-IPv6 View project

Challenges and Mitigation Strategies for Transition from IPv4 Network to Virtualized Next Generation Network View project

All content following this page was uploaded by Zeeshan Ashraf on 06 January 2020.

The user has requested enhancement of the downloaded file.


Table of Contents
Chapter 1 Introduction
1.0 Introduction of C++............................................................................... 2
1.1 History of C++ .................................................................................. 2
1.2 Dev-C++ Compiler ........................................................................... 3
1.3 How to Install & Run Dev-C++ Compiler .................................... 3
1.3.1 Step 1: Download Dev-C++......................................................... 3
1.3.2 Step 2: Start Installation ............................................................... 3
1.3.3 Step 3: Select Language ............................................................... 4
1.3.4 Step 4: License Agreement .......................................................... 4
1.3.5 Step 5: Choose Components ........................................................ 5
1.3.6 Step 6: Installation Location ........................................................ 5
1.3.7 Step 7: Installing Process ............................................................. 6
1.3.8 Step 8: Installation Complete ....................................................... 6
1.3.9 Step 9: Configuration Option ....................................................... 7
1.3.10 Step 10: Select Display Theme .................................................... 7
1.3.11 Step 11: Configuration Completed .............................................. 8
1.3.12 Step 12: Display Interface ............................................................ 8
1.4 How to Run a Program in Dev-C++.............................................. 9
1.4.1 Step 1: Create a new Project. ....................................................... 9
1.4.2 Step 2: Pick Console Application Mode ...................................... 9
1.4.3 Step 3: Add Library for Sound ................................................... 10
1.4.4 Step 4: Compile & Run .............................................................. 10
1.4.5 Step 5: Display Screen ............................................................... 11
1.5 How to Enable Graphics in Dev-C++ ......................................... 11
1.5.1 Step 1: Download Graphics Files............................................... 11
1.5.2 Step 2: Copy Console Graphics Files ........................................ 12
1.5.3 Step 3: Copy Graphics Header Files .......................................... 12
1.5.4 Step 4: Copy Library File........................................................... 13
1.5.5 Step 5: Create a new Graphics Project ....................................... 13
1.5.6 Step 6: Choose Graphics Console Mode ................................... 14
1.5.7 Step 7: Link Graphics Libraries ................................................. 14
1.5.8 Step 8: Choose Graphics Mode .................................................. 15
1.5.9 Step 9: Compile & Run .............................................................. 15
1.5.10 Step 10: Graphics Window ........................................................ 16
1.6 How to Run Win32 Application in Dev-C++ ............................ 16
1.6.1 Step 1: Create a new Project. ..................................................... 16
1.6.2 Step 2: Choose Windows Application Mode ............................. 17
1.6.3 Step 3: Compile & Run .............................................................. 17
1.6.4 Step 4: Display Window ............................................................ 18
1.7 How to Change Compiler Mode in Dev-C++ (Optional)......... 18
1.7.1 Step 1: Compiler Option ............................................................ 18
1.7.2 Step 2: Set Compiler Mode as C++11 ....................................... 19
Chapter 2 Classes
2.0 Classes ................................................................................................... 21
Program # 2.1: Simple Class ............................................................... 22
Program # 2.2: Simple Arithmetic Operation................................. 23
Program # 2.3: Input Statement & Conditional Operator ............ 24
Program # 2.4: Multiple Arithmetic Operations ............................ 25
Program # 2.5: Multiple Functions (Operations) .......................... 27
Program # 2.6: Constructor/Destructor .......................................... 30
Program # 2.7: Pass by Values & Return Result............................. 31
Program # 2.8: Prime Factors ............................................................ 33
Program # 2.9: Preprocessor Directive ........................................... 35
Program # 2.10: Hollow Square ........................................................ 37
Program # 2.11: Checkerboard Pattern with Asterisks ............... 39
Program # 2.12: Diamond Pattern with Asterisks ........................ 41
Program # 2.13: Letter Pyramid ....................................................... 43
Program # 2.14: Pass by Reference .................................................. 45
Program # 2.15: Pass by Reference with Pointer Argument ....... 47
Program # 2.16: Pass an Object by Value ........................................ 48
Program # 2.17: Object Pass by Reference & Friend Class .......... 50
Program # 2.18: Friend Function ...................................................... 52
Program # 2.19: Perfect Number ...................................................... 54
Program # 2.20: Greatest Common Divisor (GCD) ........................ 56
Chapter 3 Arrays
3.0 Arrays .................................................................................................... 59
Program # 3.1: Simple Arrays ............................................................ 60
Program # 3.2: Even/Odd Number ................................................... 62
Program # 3.3: Rectangle with ASCII Characters ........................... 64
Program # 3.4: Grid with ASCII Characters ..................................... 66
Program # 3.5: Passing an Array by Reference .............................. 68
Program # 3.6: Smaller Number........................................................ 69
Program # 3.7: Hexadecimal Numbers ............................................ 71
Program # 3.8: Binary Search ............................................................ 73
Program # 3.9: Quick Sort with Recursion...................................... 75
Program # 3.10: Passing an Array Value ......................................... 77
Chapter 4 String
4.0 String ..................................................................................................... 79
Program # 4.1: Simple String ............................................................. 80
Program # 4.2: Get & Put String ........................................................ 82
Program # 4.3: Counting String’s Characters ................................. 83
Program # 4.4: Find out Vowels ........................................................ 85
Program # 4.5: String Operations ..................................................... 87
Program # 4.6: String Comparison ................................................... 89
Program # 4.7: String Swapping ........................................................ 91
Program # 4.8: Encryption/Decryption by using ROT13............. 92
Program # 4.9: Encryption/Decryption by using Vigenere ......... 94
Program # 4.10: Enumerated Data Type ......................................... 97
Chapter 5 Inheritance
5.0 Inheritance ........................................................................................... 99
Program # 5.1: Single Inheritance .................................................. 100
Program # 5.2: Derive Constructor with Multi Inheritance ...... 101
Program # 5.3: Multi-Level Inheritance ........................................ 103
Chapter 6 Polymorphism
6.0 Polymorphism ................................................................................... 107
Program # 6.1: Function Overriding .............................................. 108
Program # 6.2: Overriding Function & Call by Reference .......... 109
Program # 6.3: Virtual Function...................................................... 111
Program # 6.4: Sub-Continent ASIA ................................................ 112
Program # 6.5: Pure Virtual Function ............................................ 115
Program # 6.6: Derived Destructor ................................................ 117
Program # 6.7: Virtual Destructor .................................................. 119
Chapter 7 Templates
7.0 Templates ........................................................................................... 122
Program # 7.1: Functions without Template................................ 123
Program # 7.2: Simple Function Template ................................... 125
Program # 7.3: Passing Multiple Template Arguments ............. 126
Program # 7.4: Function Template Overloading ......................... 129
Program # 7.5: Stack Operations (Push/POP) ............................. 131
Chapter 8 Exception Handling
8.0 Exception Handling .......................................................................... 136
Program # 8.1: Simple Exception Handling .................................. 137
Program # 8.2: Single Exception Handling.................................... 139
Program # 8.3: Multiple Exception Handling ............................... 142
Program # 8.4: Exception with Arguments Pass .......................... 145
Program # 8.5: Double Link List ...................................................... 148
Chapter 9 File Handling
9.0 File Handling ...................................................................................... 153
Program # 9.1: Simple Text File Handling .................................... 154
Program # 9.2: Get/Put Lines .......................................................... 156
Program # 9.3: Arithmetic Operator Overloading ...................... 158
Program # 9.4: File Encryption........................................................ 161
Program # 9.5: File Decryption ....................................................... 163
Program # 9.6: Binary Mode Write ................................................. 165
Program # 9.7: Binary Mode Read .................................................. 167
Program # 9.8: Search Record ......................................................... 169
Program # 9.9: Update Record ........................................................ 171
Program # 9.10: Delete Record ....................................................... 174
Chapter 10 Standard Template Library
10.0 Standard Template Library ......................................................... 177
Program # 10.1: Simple Vector ........................................................ 178
Program # 10.2: Stack Operations (Push/Pop) ........................... 180
Program # 10.3: Queue Operations (Insert/Delete) ................... 183
Program # 10.4: Array Operations with Vector ........................... 186
Program # 10.5: Simple List ............................................................. 190
Program # 10.6: Merge Lists & Pass by Reference ...................... 194
Program # 10.7: Link List Operations ............................................ 196
Program # 10.8: Simple Double Ended Queue (DQueue) .......... 201
Program # 10.9: Simple Finding Algorithm .................................. 205
Program # 10.10: Counting & Sorting Algorithm ........................ 207
Program # 10.11: Simple Iterator ................................................... 209
Program # 10.12: Passing Iterator & Vector References ........... 211
Program # 10.13: Reverse Iterator................................................. 213
Program # 10.14: Simple Set ............................................................ 215
Program # 10.15: Simple Map ......................................................... 217
Program # 10.16: Heap Sort ............................................................. 219
Program # 10.17: Vector Template ................................................ 221
Program # 10.18: Iterator Template .............................................. 223
Program # 10.19: Simple Stack Container .................................... 225
Program # 10.20: Function as an Argument ................................. 227
Chapter 11 Graphics
11.0 Graphics ........................................................................................... 230
Program # 11.1: Simple Graphic Shapes ....................................... 231
Program # 11.2: Drawing (Bowl over a Book) ............................. 234
Program # 11.3: Colorful Graphic Shapes ..................................... 237
Program # 11.4: Moving Car............................................................. 241
Program # 11.5: Load Bitmap Image File ...................................... 244
Chapter 12 System Handling
12.0 System Handling ............................................................................ 247
Program # 12.1: System Time & Text at Specific Position ......... 248
Program # 12.2: Opening Window Applications ......................... 250
Program # 12.3: Play Sound ............................................................. 253
Program # 12.4: Creating a Folder and Display Directories ..... 254
Program # 12.5: Mouse Handling (Game) ..................................... 255
References.................................................................................................... 262
References

[1] P. Deitel and H. Deitel, "C++ how to Program", Pearson, 2016.


[2] Stroustrup, Bjarne (7 March 2010). "Bjarne Stroustrup's FAQ: When was C++
invented?", stroustrup.com, Retrieved 16 September, 2010.
[3] Stroustrup, Bjarne. "The C++ Programming Language" (First ed.), Retrieved
16 September, 2010.
[4] Stroustrup, Bjarne. "The C++ Programming Language" (Second ed.),
Retrieved 16 September, 2010.
[5] "ISO/IEC 14882:1998", International Organization for Standardization.
[6] "ISO/IEC 14882:2003", International Organization for Standardization.
[7] "ISO/IEC 14882:2011", International Organization for Standardization
[8] "ISO/IEC 14882:2014", International Organization for Standardization.
[9] “ISO/IEC 14882:2017”, International Organization for Standardization
[10] https://nae.edu/Activities/Projects/Awards/DraperPrize/DraperWinners/
2018/ Draper/177032.aspx
[11] Lafore, Robert, “Object Oriented Programming in C++”, Sams Publishing,
2002.
[12] Kanetkar, Yashavant P., “Let us C++”, BPB publications, 2010.
[13] Balagurusamy, Entrepreneurial, “Object Oriented Programming with C++”,
6e. Tata McGraw-Hill Education, 2013.
[14] Z. Ashraf, “Data Structure in C++ Graphically”, GlobeEdit On-Demand,
LLC, 2017.
[15] Z. Ashraf, “How to Program in C++ With 100 Examples”, LAP Lambert
Academic Pub., 2016.
[16] Dr. Quinn, “Hands-On System Programming with C++”, Packt Publishing,
2018.

View publication stats

You might also like