Location via proxy:
[ UP ]
[Report a bug]
[Manage cookies]
No cookies
No scripts
No ads
No referrer
Show this form
Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
38 views
f8486976 Learn Professional Programming Skill in C Programming Language
Uploaded by
Khadim Ndiaye Mbaye
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save f8486976 Learn Professional Programming Skill in C... For Later
Download
Save
Save f8486976 Learn Professional Programming Skill in C... For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
38 views
f8486976 Learn Professional Programming Skill in C Programming Language
Uploaded by
Khadim Ndiaye Mbaye
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save f8486976 Learn Professional Programming Skill in C... For Later
Carousel Previous
Carousel Next
Save
Save f8486976 Learn Professional Programming Skill in C... For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 814
Search
Fullscreen
Learn Professional o) Programming Skill in Programmin Gc C++ Language 3 Adalat Khan ~LEARN PROFESSIONAL PROGRAMMING SKILL IN » oo —_»> rr LANGUAGE ADALAT KHAN Bachelor of Computer Sciences (BCS) from CECOS University Peshawar and Master of Information Techmalogy (MIT) from GOMAL University Dera Iumail Khan. For all the students, teachers and programmers who want to get professional programming methodology and advanced programming proficiency_‘Copyright © 2013 by Adalat Khan Library of Congress Control Number: 2013912338 ISBN: ‘Hardcover 978-1 -4836-6653-2 ‘Softcover 978-1-4836-6052-5 Ebook STE-14836-6654-9 All rights reserved. No part of this book may be reproduced or ransmitted in any form or by any means, electronic or mechanical, including photocopying, recording. or by any information storage and retrieval system, without permission im writing from the copyright owner Edditiom: 1st Rev. date: 08/5/2013 ‘To order additional copies of this book, contact: Xlibris LLC 1-800-455-039 www. xlibnis.comsan Orders@ixlibris com anTABLE OF CONTENTS 2 29 3 4 5 5 5 6 High Level Languages 6 ‘Types of High Level Languages 7 ‘Translator and its types 7 8 =F 8 10 10 10 u i Data Representation in Computer System ul The Data of Programming Languages .....scsccsesseeseeeceesseereneed2 Numeric Data i Alphabetic Data B ah ane tee Introduction to C++ Programming Language. 13 The History of C++ Programming Language ......cecceecceeeeed3Se ae CSE ae DEERE 15 Turbo C++. rere np eer epee NE Borland cH. 16 Microsoft Visual G1 17 ‘The Microsoft Visual Studio. NET 17 Rules for writing C++ Programs... one tl The Structure or Layout of a C++ Program — 22 Writing, Compiling, and Executing the C++ Programs. The C++ Programs using the Turbo C++ Compiler... The C++ am ey Visual C++.NET 2010 30 31 32 2. Introduction to Variables, Data Types, and Basic Elements of C++ Programming Canguage CHAPTER CONTENTS Variables. Data Type Data Types in C++ Programming Language. Declaration of Variables ‘The Variables Naming Conventions. Memory Representation of Integer Variables .. Memory Representation of Unsigned Short Integer ba ‘Constants and its Declaration. 31 ‘The typedef Declaration. The Scopes of Variables. Local Variables ‘Global Variables... Sn ot ‘The Storage Classes int. 53 ‘The auto Storage Class... ‘The register Storage Class ‘The static Storage Class.Expressions 55 Expression Precedence....sce:ccsscecssesiestnsstnseesstessenneeneent Header Files The tem Fitacion and insrion Opis The cout stream Object The Preprocessor Directives The #include Preprocessor Directives ‘The #ifdef and #else Directives .. The #endif Directive .. ‘The #ifndef Directive.Postfix Increment/Decrement onda 95 The typeid Operator 98 Comma Operator () 103 ‘Tie Sipe esciebon Opresie 104 Bitwise Operators... eeveeeeetevesessnseseeeseseeetensetennsaseeseseeeee OS Bitwise Logical Operators . 105 Bitwise AND Operator. Bitwise OR Operator... Bitwise Exclusive OR (XOR): Bitwise 1’s Complement Operator. ‘The static_cast Operator .. The dynamic_cast Operator. ‘The const_cast Operator .. 4. ‘The Flow Controls Statements in C++ Programming Language CHAPTER CONTENTS The Flow Control Statements ........sesseececsnsenecstereeseeseeneeel 21 ‘The Sequence Statements 121 The Selection Statements. ‘The If Statement.............. ‘The if-else Statement ‘The Switch Statement 133‘Types of the Loops 138 The Counted Loops....ecjcsscesssessessneeenseusstseeneeneeneeineed 3B The for Loop 138 The Uncounted Loops....escccciocesisccsssssnseesseiesetneeneeneesneeied 43 The do-while loop 144 Seer ene a eee 151 The break Statement _ The continue Statement. The goto Statement..... The limitations of goto Statement. Logical programs using Loops and Nested Loops.. A Program that adds the first 10 Natural Numbers. A Program that adds Even Numbers from 0 to 20 using while loop... eevee GI A Program that Prints the Series of Natural Numbers | and their Square ... A Program that determines the Factorial of any Number A Program that Prints the Factorial Series from 1 to 10. A Program that Prints the Prime Numbers from 1 to 100. ‘The Series of Natural Numbers, one Positive and one Negative . 164 ‘The Series of Natural Numbers, two Positive and two Negative 164 The Series of Natural Numbers. Three Positive and three Negative ... eveeneeee cen 5 ‘The Series of Squares of any Number . 166 The Series of Natural Numbers and their Factorials...............166 A program that prints Armstrong Numbers between 1 and 500. 167 A program that prints Composite Numbers ...00...00.00--0.-....--168 Different verities of Triangular Series 169 177 A Program that Draws a Rectangle of Asterisks......00.0.0......178 A Program that prints the Fibonacci Series 179 Atop aa as determines the Sum of the anne: ofJ. The Procedures and Procedural Programming in C++ Programming Canguage CHAPTER CONTENTS Procedures 184 ‘The Benefits of Procedures 186 Parts of Procedures 186 ‘Types of Procedures 188 Functions... aE Parts of a Function in C++ Programming Language 189 Function Prototype 190 Function Call. Function Definition Actual and Formal Arguments . Rules for declaring User-defined Functions . ‘The retum Statement Passing Variables to a Function ... Passing Variables by Value Passing Variables by Reference ... Retuming Pointers from Functions. a ee re Gatling Cae Convention. Change the C+ Calling C Convention to to Fescel Calling Accessing unspecified Parameters List of a Function Built-in Functions ... “ ‘The Variables Scopes and. Lifetime. Local Variables. ‘Global Variables Static Variables... Function Overloading . Function Templates Adding User-defined Functions to the Built-in Library. The tlib.exe Utility How to inchide User-6. The Pointers, Arrays, Structures and Unions in C++ Programming Canguage CHAPTER CONTENTS Pointers 225 Declaration of Pointer Variables 225 Assigning addresses to Pointers variables 296 Pointer-to-Pointer Variables 228 Function Pointers ................. pe EM Invoke or call a Function using Function Pointer. 331 Void Pointers 235 Initialization of Single Dimensional Arrays “339 Multiple Dimensional Arrays, Initialization of Two Dimensi Three Dimensional Arrays... Initialization of Three Dimensional Arrays. Passing Array elements to a Function Read and Display Array Elements from keyboard . Largest Value in an Anay............ First Largest and Second Largest Values I an ray Sorting of Array using the Bubble Sort Algorithm... Sorting of Array using the Selection Sort Al Sorting of Array using the Insertion Sort Algorithm . A Program that converts Digits into Word Format . A Program that Restricts the Duplication m Armay . A Program that Removes an Element from an Array A Program that Removes all the occurrences of an Element from an Array. senesseneenneeneee DGD ‘APisgracd that taseis ea ELT SE Specified Location 264A Program that finds the Union of Two Arrays 265 A Program that finds the Intersection of Two Amays .............268 Logical Programs using Two Dimensional Arrays 271 A Program that Adds 3*3 Matrices ee 7) ‘A Program that finds the Transpose of a Matrix. 273 A Program that checks the Matrix either it is Symmetric or not... 274 A Program that finds the sum of the Diagonals ofa 3*3 Matrix. Structures ... Why we use Structures? 277 Object Oriented Programming .....0...cc:ccscseessseseeecessseeeeeensee ‘Classes. ‘The private Access Modifier .... The protected Access Modifier ‘The public Access ModifierThe Declaration of Classes. 307 Objects ... seceensetnaserseerseesattneetnsetnnerneeenoB12 Accessing the Overridden Function of Base Class from Denved Class 333 “Virtual Function 337 Friend Function 340 Operator Overloading .. eeeseeeeneseseteennaseseremeseseseeene SAD Unary Operators Overloading 343 Binary Operators Overloading... See aS Programming Examples of Operators Overloading 346& The Study of Header Files and Cibrary Functions in C++ Programming Language CHAPTER CONTENTS ‘The CONIO.H Header File 352 ‘The gotoxy() Function 353 The clreol( } Function 354 ‘The getch( } Function. 354 The getchet } Function... cseessseseesstesseeeenssterseettnseeenneenend 54 ‘The cprint{ } Function. 355 ‘The ungetch( ) Function. 355 The getpass( } Function. 2! ‘The putch( ) Function. The textcolor( ) Function............. ‘The textbackground( ) Function... ‘The textattr( } Function The _setcursortypet ) FUmction......ceccssceessevestecnesttrsneeenesee ‘The dellinet ) Function. ‘The insline{ ) Function. ‘The kbhit( ) Function .. = ‘The wherex( ) and wherey( } Functions 361 The window() Function. 8s 2! The cgets() and cputs( ) Functions. The MATH.H Header File ‘The abs( ) Function... The sin{ }, cos(), and tan( ) Functions. The sinl(), cosi(), and tanl() Functions. The sinh( ), coshf ), and tanh ) Functions... ‘The log( }, and log10{ ) Functions ‘The pow? ), and sqri( ) Functions. The STRING.H Header File ‘The streat( ), stmcat( ), strchr(), and strebr{ ) Functions ‘The strstr( ), stremp(), stempi(). and strcmp) Functions. 366-367 Tee) Se Speer), melee) Functions. sooo 367-369ae eee strrev( ). Seer) eet eerie) venseeee . 369-370 ere STDLIB H Header File. 374 The atoi(), atol(), atof), and _atold( ) Functions.......... 374-375 The itoa(}, Itoa(}, gevtf ), and ultoa{ } Functions 376-377 The strtod( ), strtal(), strtoul( }, and qsort( ) Functions. 377 The rundomize( ), random), rand), and lsearcht) ee Teste Ties ae Poierneiu iio Functions... . The delay(), disable(), getdfree( etme), al stone) The getdate(), setdate(), sound), fd nosound)” Functions... 9. The Stream Classes, Input/output Formatting, and File Handling CHAPTER CONTENTS Introduction to Stream Classes 393 Whe 10s base Class ‘The ios Class ‘The istream Class... The ostream Class .. ‘The iostream Class. 428‘The File Stream Classes. 429 The ifstream Class... seoneseneeentennesnneeneessneeseee en 4D) Member Functions of ifstream Class 430 The ofstream Class... citeecioeteectarceectarsee tet AR Member Functions of ofstream Class 432 10, The Memory Models and Dynamic Memory Allocation in. C++ Programming Canguage CHAPTER CONTENTS Memory 437 Dynamic Memory Allocation - 439 Heap... Allocation of Memory Space The Details of ALLOC H Header File. The malloct } Function... The farmalloc( )} Function ‘The calloct ) Function...... ‘The farcalloc( } Function - ‘The realloct ) Function. ‘The farfree{ ) Function... Allocation of Memory using the DOS, H Header File The allocmemf ) Functions Allocation of Memory using the C++ Operators ‘The new Operator ... The delete Operator.Ii. The Graphics Programming in C++ using the Borland Graphics Interface (BGI) CHAPTER CONTENTS Computer Graphics 453 Display Screen The initgraph Function. 455 ‘The graphresult Function 456 The grapherrormsg Frmction.......ccsoccssseessteseeeneeneeseesnersh 36 The closegraph Function 457 The restorecrtmode Function 458 The getgraphmode Function .... ‘The getmaxx and getmaxy Functions 461 The getx and gety Functions... The moveto Function. The outtext Function... The outtextxy Function The settextstyle Function The textheight and textwidth Functions. The settextjustify Function .. The line and lmeto Functions. The circle and rectangle Functions - The setlinestyle Function............ The setviewpart and clearviewport Functions ‘The are and ellipse Functions ... The bar and bar3d Functions. The setcolor and getmaxcolor Functions ‘The setfillstyle and floodfill Functions... ‘The getimage and putimage Functions .. The imagesize Function12, The System and Terminate Stay Resident Programming CHAPTER CONTENTS Introduction to System Programming 499 Microprocessor 500 The CPU Registers. 501 General Purpose Registers 502 Segment Registers... ...ccccccscsessseseevsseevseseevesseveeseeeeeeeeeesee SO Index registers Pointer Registers The FLAGS Registers. Interrupt Service Routine (ISR)... Programmable Interrupt Controller Executing Interrupt Vector Table (IVT) The List of useful Interrupts Mouse Handling Programming Interrupt 33h Listing .............. Disk Management using BIOS Functions......... Disk Management using C++ Library Functions Files and Folders Management Using the BIOS Functions ....... Using the C++ Library Functions ... The 10H Header FileThe DIR_H Header File. 552 Printer Management... esseneeeneennerneese SSG Printer Management using BIOS Functions 556 Printer Management using Library Fumctioms ......-.c:ecc:s00557 Keyboard Management 560 Keyboard Management using BIOS Functions 560 Keyboard Management using Library Functions ..............-...563 Accessing the Interrupt Vector Table(IVT) 367 ‘The petit and Setrect Fimetions ; : Interrupt Functions.. sa Interrupt Function Pointer. Accessing an Interrupt from IVT through its 13, The Number System and Number System Conversion ‘CHAPTER CONTENTS Number System. S77 The Number System Conversion using Programming 579 A Program to Converts the Decumal Number into Binary Number 579 The Fraction part of Decimal Number into Binary Number._.581 Decimal Number into Octal Number 582 The Fraction part of Decimal Number into Octal Number ___583 Decimal Number into Hexadecimal Number 584 Hexadecimal Number into Decimal Number 586 The Fraction Part of a Hexadecimal Number into Decimal Binary Number into Decimal Number 589 ‘The Fraction Part of a Bmary Number intoBimary Numbers Anthmetic 591 A Program to add two Binary Numbers........ccseceesceseeesneee 592 A Program to subtract two Binary Numbers 593 Programming of Applied Mathematics........:cc:e.c:cseseeeene-596 A Program to Simplify a Fraction 597 A Program to Determine L.C_M between two Values. 598 A Program to Determine the Square Root of a Number..........599 A Program to check whether a Number is a Perfect Square 601 14, The Errors and Exception Handling in C++ Programming Canguage 15. The Standard Templates Library in C++ Programming Conguage CHAPTER CONTENTS ‘The Standard Template Library Containers Stack Container... ‘Queue Container .16. a ‘CHAPTER CONTENTS ‘The Win3? Applications ‘The windows h Header File ‘The Built-in Typedefs im Win32 API Library . Hungarian Notation... The Wind? Applications using Visual C++ NET 2010 ‘The Entry Point of Win32 Applications. 684 The WinMain Function 686 ‘The CreateWimdow( ) FUMCHiOn .....--cseeceseneceesseerenecees seen 8B The Show Window( ) Function. 695 ‘The Update Window( ) Function 696 The Windows Classes 696 The WNDCLASS Structure 697 The WNDCLASSEX Structie 697 ‘The RegisterClass(} Function 701 ‘The RegisterClassEx( ) Function 702 The MessageBox() Fumction....ceccsossesossssmeseesnseseeentenaneeinesee The LoadStnne{ ) Function 702 The LoadIcon(} Function 703 The LoadCursor Function 704 ‘The LoadImage( ) Function 705 The MAKEINTRESOURCE( ) Macro...........cccecccseceeeeesees TOR‘The Windows Messages. 708 The Types of Window Messages ......cscsccccssccesseewsesneesnee TO The Queued Messages 710 The Non-queued Messages ....co:iccssccesseessssseteseeeneineeeneeee TO The Messages Handling 71 The GetMessage( ) Function. 712 The TranslateMessage( ) Function _ 714 The DispatchMessage( ) Function .. ‘The Message Loop Body or Structure ‘The Window Procedure The Body of Window Procedure... The DefWindowProc() Function The PostQuitMessage( ) Function .. Explanation of some Important Windows Messages. The LOWORD( Macro. The HIWORDO Macro... The GET_X_LPARAM( Macro. The GET_Y_LPARAMO Macro... 17, The GDI Graphics Programming in Visual C++. NET using the Win32 Applications CHAPTER CONTENTS The Graphics Device Interface The Device Contest ............. The Graphics Objects or Tools. The WM_PAINT Message... The Graphics Device Interface Functions. 742LineToO Function SelectObject() Function DrawText() Function SetBkColor) Function. SetTextColor() FUumction. .....e.scsscsseeesseesesseenssteeesseenseeeensone GetDCO Function GetClientRect() Function..... The MoveToEx() Function .. The POINT Structure 18 Advanced Graphics and Games Programming in ‘Visual C++ NET using OpenGL Graphics Library CHAPTER CONTENTS Install and set OpenGL Using MS Visual Studio. NET 2010...764 Writing and Compiling the OpenGL Program : The Basic Structure of OpenGL Program. The Header Files Declaration Section The Global Declaration Section... The Dnver Function Declaration Section. The Initialization Section... giClearColor0 Function Function .. giLoadldentityQ) Function... Initialization of GLUT Library. Initialization of Display ModeSet the Window Size Set the Window Position on the Screen. Main Create see oan erent peor ee 776 TTS 778 780 781Jn the nama of Allah who is merciful and mighty DEDICATION I dedicate this effort to my beloved parents whose cordial prayers, guidance and encouragement helped me success in my goal.About The Author The author of this Book Mr. Adalat Khan is a resident of Koza Bandai district Swat Khyber Pakhtnkhwa Pakistan. He has passed his Intermediate (F Sc Pre Engineenng) from Government Jehanzeb College Saidu Shanf Swat and his Bachelor Depree “Bachelor of / Computer Sciences (BCS)" from CECOS : University of IT and Emerging Sciences } Peshawar Pakistan and Master Degree “Master of Information Technology (MIT)” from GOMAL University Dera Ismail Khan Pakistan. The author has worked in the field of C++ (Borland Turbo C++, ANSI standard of C++, Visual C++, Visual C++NET) and other programming languages such as Visual Basic, Visual Basic NET, C# NET, ASP. NET, SQL Server Database, Java, Java Script, VB Script, HTML, and DHTML. Note for the Readers: This book contains several logical programs. If you face any problem or ambiguity about any program or any step, you cam send your questions directly to the author by using the following Email address: Email Address: adalatkn@jgmail.com Suggestions and Comments If there is amy error or technical mistakes anywhere in this book please feel free to send your suggestions and comments by using the above email address.PREFACE First of all I am grateful to almighty Allah for granting the great chance of utlizmg my knowledge and experience. No man or his knowledge is utterly perfect. Rather everybody in this word tries his best to attempt solving problems to the maximum extent. I have only tried my best to provide due guidance and step-wise solution of programming in C++. The main purpose of writing this book is to provide professional programming logics and deep concepts of programming. This book covers the basic programming fundamentals, the professional programming logics and deep concepts of professional programming in C++ such as the flow control statements in C++ programming language. the basic programming techniques, the procedures and procedural programming concepts, the arrays, pointers, structures, and unions, the logical programs using loops, the object oriented programming. the study of header files, the file handling in C++ programming, the Graphics programming using the Borland Graphics Interface (BGD, the System programming, the Terminate and Stay Resident programming, the Number System and Number System Conversion, the Errors and Exceptions handling in C++ programming, the Standard Template Library in C++ programming, the Win32 Console Applications im Visual C++ NET, the Win32 Projects in Visual C++. NET, the Advanced Graphics Programming using the GDI (Graphics Device Interface) im Visual C++.NET, the Advanced Graphics Frogramming and Games programming in Visual C++ NET using the OpenGL graphics library, and the Programming of Applied Mathematical Formulas etc. This book covered the above-mentioned topics in details in a very simple way. It also contains various advanced logical programs. Each topic in this book is explained with suitable programming examples. The programs in this book are error free and fully tested and executed using the Turbo C++ version 3.0, the Turbo C++ version 4.5, and the Visual C++.NET of Microsoft Visual Studio.NET 2010 professional.Preface This book provides deep programming techniques and knowledge from beginning level to the higher level and it is efficient for all those students, teachers. and researchers who want to get professional programming logics and become professional programmers The Book Organization This book contaims 18 Chapters. Following is the details of these Chapters Chapter #1 This chapter explains the basic concepts of C++ programming language, the history and evolution of C++ programming the C++ program structure, the different compilers and Integrated Development Environments (IDEs) used to write, compile. and execute the C++ programs. This Chapter explains how to ran the C++ programs using the old compilers of C++ such as Turbo C++ etc and using the modem compilers and Integrated Development Environments such as Microsoft Visual StudioNET 2010 Professional. Chapter #2 This Chapter explams Vanables, types of vanables, Constants. the variables naming conventions, the limitation of variables, the memory representation of different types of variables, the Scope of vanables, the Storage classes. Expressions, Header Files, the Typedef declaration, the input and output in C++ programming, the Escape Sequences. the Preprocessor Directives, Comments, Typecasting, Namespaces, the keywords in C++ and some other basic elements and requirements of C++ programming. Chapter #3 This Chapter explains Operator and its types available in C++ programming language such as Arithmetic Operators, Arithmetic Assignment Operators, Compound Assignment Operators,Preface Relational Operators, Logical Operators, Increment and Decrements Operators, the Prefix Increment and Decrement Operators, the Postfix Increment and Decrement Operators, the Convention of Expression Solutions, the sizeof Operators, the typeid Operators, the Conditional Operator, the Comma Operator, the Scope Resolution Operator, the Bitwise Operators and its various types, and the typecasting and its different Operators. Chapter #4 This Chapter explains the flow control statements im C++ programming language such as the Sequence statements, the Selection statements ie. the “if statement”, the ifelse statements. the nested if-else statements, and the switch statement, the Iterative statements ie. the Counted loops (for loop) and the Uncounted Loops (the while loop, and do-while loop). This Chapter also explains the break statement, the contimue statement, and the goto statement. This Chapter also contains 49 logical programs. ‘Chapter #5 This Chapter explains Procedures and Procedural programming, Functions, parts of Functions, Functions declarations, passing Parameters or Arguments to the Functions, passing parameters by value, passing Parameters by reference, the Function parameters passing Calling Convention, the Variables Scopes and Lifetimes. Function Overloading, adding the user-defined Functions to the built-in library of C++ programming language. Chapter #6 This chapter explains pointers, pointer types, declaration of pomters. pomters to Functions, Function pomters, Arrays, types of arrays, Arrays declarations, Arrays Initializations, the Memory Representations of Arrays, Structures, the declaration of Structures, the declaration of Structure variables, the memory representation of Structures, Unions. and Recursion. This Chapter also contams various logical programs using a single dimensional and two dimensional arrays.Preface Chapter #7 This Chapter explains the Object Oriented programming in details. It explains the Classes, the declaration of Classes, the Objects and Objects declarations. the Encapsulation and Data hiding. the Constructors and Destructors, the Inheritance and its different types, the Access Modifiers, the Friend Functions, the Virtual Functions, the Functions Overriding, and Operators Overloading. Chapter #8 This Chapter explains the header files and built-in library functions in details. In this chapter each library fimction is explained with a programming example. Chapter #9 This Chapter explains the different types of Stream classes, the Input/output formatting, Manipulators, and File handling in C++ programming language. Chapter # 10 This Chapter explains Memory Model, the different types of Memory Models, Dynamic memory allocation and deallocation, and various built-in functions used to allocate and deallocate the memory space in C++ programming language. Chapter #01 This Chapter explains the Graphics Programming in C++ using the Borland Graphics Interface (BGD. Chapter # 12 This Chapter explains the System programming, the Terminate and Stay Resident (TSR) programming, and Mouse handling programming in details. ‘Chapter # 13 This Chapter explains the Number System, the different types of Number system such as the Binary Number system, the Decimal Number system, the Octal Number system, and the Hexadecimal Number system, the Conversions of one Number System to anotherPreface Number System, the Addition and Subtraction of bmary numbers. and programming of some applied mathematical formulas. Chapter #14 This chapter explains Exceptions, Errors, types of Errors and Exception Handling mechanism. Chapter #15 This chapter explains the Standard Templates Library (STL) and the various Containers of the STL library such as vectors, lists, queues, deques, stacks, set, multiset, map, nmultimap, hash, hash map, and hash nmltimap. Chapter #16 This Chapter explains the Win32 Applications in details. This Chapter also explains the different Typedef used in Win32 Applications and various Windows messages that occur in the response of the users different operations. Chapter #17 This Chapter explains the Advanced Graphics programming in Visual C++ NET using the Graphics Device Interface (GDI). Chapter #18 This Chapter explains the Advanced Graphics and Games programming in Visual C++NET using the OpenGL Graphics Library. Adalat Khan 29% June 2013CHAPTER, # 1 if = = Zz ° ve ae fe & <= = Oo Computer Programming Structure Programming Object Oriented Programming Programming Languages Low Level Languazes Machine Language Assembly Language High Level Languages Types of High Level Languages Translator and its types Data and its Types Introduction to C++ Programming Language The History of C++ Programming Language The different Compilers and IDEs of C++ Rules for writing C++ Programs The Structure or Layout of a C++ Program ‘Whiting, Compiling, and Executing the C++ ProgramsIntroduction to C++ Programming Language > Computer Programming ‘Computer programming is the process of designing, writing, testing, debugging. and maintaining the source code of a computer program. The source code of a program can be written in any computer programming language. A computer program is a set of mstructions ‘or statements written in a sequence in any computer programming language to perform a specific task. The computer programming is a way through which we send the set of instructions or statements to the computer system to perform specific operations or to solve a specific problem or algorithm When we write a program in any computer programming language then it is called source code of the program The source code of a program is normally in the form of human readable form The computer system does not understand the source code of a program or human readable languages. The computer system only understands machine language. The binary language or the language of zero and one is called machine language. When we write a computer program using any programming language. the translator of that programming language converts source code of the program into machine code and then converts into an executable file. The executable file is in the form of machine readable form or mm binary form and it is ready for execution. The central processing unit of computer system then executes the executable file or binary file of the computer program and performs a specific task or achieves a desire goal. Types of Computer Programming The computer programming is generally categorized into the following two types: «Structure Programming + Object Oriented Programming Structure Programming Structure Programming is also known as modular programming or procedural programming. The structure programming uses the top-down approach that executes a computer program in a linear form from top to the bottom line by line The structure programmingIntroduction to C++ Programming Language 3 uses the basic program flow control statements such as the decision statements, the repeating statements, and the selection statements. The decision statement makes decision between the two statements and executes a single statement at a time according to a specified condition. The repeating statements are also called loops that execute a single statement again and again until a specified condition becomes true. A selection statement contains a single check and multiple choices and it allows us to execute a specified statement according to our choice by providing the choice value of the selection statement. A program that is based on structure programming methodology may also contain small blocks of codes that are called procedures or functions. A function is a small block of codes that is executed to perform a specific task. Object Oriented Programming The object onented programming is a programming methodology that allows us to define user-defined data types that are called object oriented data types. The object oriented data types are similar to the ordmary data types like integer data type, float data type, double data type, character data type etc but the main difference between the ordinary data types and the object oriented data types is that an ordinary data type is used to declare a variable that holds a single value at a time and a single ordinary variable can hold a single type value for example, if we want to store an integer value in a variable then we will declare an integer variable for that value, similarly if we want to store a double value in a variable then we will declare a double vanable for that value and so on while an object onented data type is the combination of different ordinary data types and procedures or functions that is called class. A class is an object onented data type that contains one or more ordimary variables and one or more function. The ordinary variables of a class are called member data of that class and fumctions of a class are called member functions of that class. A class allows us to declare variables. When we declare variables from a class then they are called objects of that class. When we declare an object from a class then all the ordinary variables or member data and all the member functions of that class are inherited into the declared object. A single object of a class canIntroduction to C++ Programming Language 4 aceess all the ordmary variables or member data and all the member functions of a class at the same time. Programming Languages A programming language is an artificial language designed to communicate with the computer system. A programming language provides an interface and allows us to send instructions to the computer system to perform a specific task or to achieve a desire goal. The programming languages allow us to develop a set of instructions or statements that constitute a computer program. A computer program is a set of instructions or statements written in any programming language to achieve a specific task. The programming languages provide builtin libraries that contain thousands of different built-in objects such as variables, constants, operators, structures, decision statements, iteration statements, procedures, interfaces, delegates, threads. graphics objects, database connection objects and so on for different tasks and goals. When we design an application or a program using any programming language then we use the built-m objects of that programmimg language and achieve a desire result or a goal. We can also create user-defined objects in any programming language to achieve a specific task Each programming language has its own procedures and structure to develop applications or programs. When we write a program or an application using any programming language then the translator of that programming language compile our program or an application and perform different checks for errors. If there is any error in the program, the translator of the programming language does not execute the program until we Temove all errors from the program. Some programming languages indexed all the errors of a program im a list with some description. When we remove all errors from a program and the program becomes error free then translator converts the program source code into machine language code. The source code of a program is always in human readable form and computer system does not understand the human readable languages. The computer system understands only machine language. Therefore. the translator of a programming language converts source code of a program into machine code which is called executable file. The executable file is alwaysIntroduction to C++ Programming Language 5 in the form of binary language ie. in the form of zero or one. The central processing unit of a computer system then executes the executable file of the program and performs our desire goals. Types of Programming Languages The computer programming languages are basically divided into the following two types: + Low Level Languages + High Level Languages Low Level Languages The low-level computer programming languages are machine codes. The computer system cannot understand instructions given in the form of high-level languages or human languages. The computer system can only understand and execute mstructions given m the form of machine language. The binary language or the language of zero and one is called machine language. The low level programming languages directly interact with the computer hardware. Therefore, the low level programming languages require more experience and knowledge about computer hardware, CPU registers, and interrupt interfaces. A program written in a low level language requires small memory and executes very quickly as compare to a program written in a high level language. The programs written in high level languages require more memory and executes slowly. The low level programming languages are divided into the following two types: « Machine Language. « Assembly Language. Machine Language It is a programming language in which the set of instructions or statements are written in the form of machine code. The machine language is also called binary language or the language of zero and one. The computer system only understands machine language or binary language. A manufacturer designs a computer to understand only machine language. The machine language is representedIntroduction to C++ Programming Language 6 inside in the computer by a string of binary digits (0 and 1). The symbol 0 stands for the absence of an electric pulse and 1 stands for the presence of an electric pulse. When the sequence of code or a set of instructions is given to the computer system using machine language, the computer recognizes the codes and converts it into electrical signals and executes directly without any translation. The machine language does not use any translator because the program or the set of instructions are written in a machine language is already in the form of machine language or in binary form. When we give any instructions or set of instructions to the computer system in the form of machine language, the computer system directly executes the instructions very quickly without any translation. Therefore, machine language is a very fast language because no translator program is required for the central processing unit of computer system. Assembly Language A low-level programming language im which operation codes and operands are given m the form of alphamameric symbols stead of 0's and 1's is called assembly language. In assembly language the set of symbols and letters combines with each other In a simple word we can say that assembly language is the symbolic representation of machine code which also allows symbolic designation of memory locations. For example, ADD for addition, SUB for subtraction etc. The assembly language requires a translator to translate the assembly language code into machine language code because the assembly language code is not in the form of machine language, it is in the form of symbols. The translator of assembly language converts the assembly language code to the machine code. The translator of assembly language is called assembler. High Level Languages The high level languages are also called symbolic languages that use English words and Mathematical symbols for example, +. age 2 pie. They kar viny cle: to the ime becgeapes: Wn wn pits ha injuein of cod. or-a‘eotad inchartons'te the cooler system using any high level programming language then the highIntroduction to C++ Programming Language z level programming language first converts the source code of the set of instructions into machine language code and then executed by the central processing unit and achieves the desire goals. The high level languages are actually designed to solve the particular problems of mathematics, general logical problems, general applications, and business accounts problems etc and therefore the high level languages are called problem oriented languages. For example, the programming language COBOL (Common Business Oriented Language) is designed for business purposes, the programming language FORTRAN (Formmila Translation) is designed for mathematical formula orientation and calculation and so on Types of High Level Languages There are different types of high-level programming languages. The different high level programming languages are developed for different purposes and goals. Some of these programming languages are BASIC, C, C++, JAVA, COBOL, FOTRAN, Pascal, C#, Visual Basic, Oracle. and Prolog etc. These programming languages are similar with each other in some characteristics while in some other characteristics they are different from each other for example, the Oracle language is developed for the database designing and development, the Prolog is developed for logical problems such as to develop Robots, Expert system etc. The COBOL is developed for business purposes, the BASIC and FORTRAN languages are developed for Algebraic formula processing, and C, C++, Java, and Visual Basic are designed for the general application programming. Translator It is a computer program that translates a program written in one language into an equivalent another language depending on the type of the translator. There are the following three types of translators: «+ Assembler Compiler InterpreterIntroduction to C++ Programming Language g Assembler Itis a translator program that translates the source code a program written in assembly language into machine code. ‘Compiler It is a translator program that translates the source code of a program written in a high-level language into machine language code. The machine language code is also called object code. When compiler translates the source code of a program into machine language code then it links the machine language code and creates an executable file. The executable file is then directly executed by the central processing unit of computer system The compiler reads source code of a program and translates the whole program into machine language code at once. If there is any error occurs in the source program, the compiler prompts an error message and if there are more errors in the program, the compiler indexes all the errors in a list. When we remove errors from the source code of a program then the compiler translates the source program into machine language code and creates an executable file. The executable file is then executed by the central processing unit at the same time. The compiler first copies the whole program into memory and then directly executes by the central processing unit. Therefore, the compiler is very fast and directly executes the entire program at one time but it consumes more memory space because compiler copies the entire program into the memory. The debugging process is also very difficult in compiler because one error can produce many other unauthentic errors. Interpreter It is a translator program that translates the source code of a program written in a high-level language into machine language code. The interpreter translates the source code of the program into machine language code instruction by instruction or line by line and at the same time executes the program line by line by the central processing unit. During translation if there is any error occurs in the source code of the program, the interpreter stops translation andIntroduction to C++ Programming Language 2 displays the error report. When we remove error. the interpreter starts translation again and translates rest of the program line by line. The interpreter is a slow process because it translates the program line by line. In interpreter the debugging process is very easy. Each line of code is analyzed and checked before being executed. The i requires less memory space because interpreter loads one line in the memory at a time. When one line is checked, translated into machine code and successfully executed by the central processing unit then interpreter loads another line of the source code of a program and on this way it executes the entire program. Data The collection of facts and figures about a particular task is called data. The particular task may be analysis, measurement, survey, research and so on. The facts and figures are always in the form of characters, symbols, alphabets, numbers, constants, text, graphs, diagrams, charts, pictures, images, audio/video clips, audio/video conferencing, questioners, interview questions, survey, observation, and analysis etc. The facts and figures are also called raw materials. In other words we can say that when we collect different raw materials or facts and figures about a particular object or task then the collected materials or facts and figures about that particular object or task is called data For example, if we are doing a research on any animal then we study that animal deeply and collect different facts and figures or materials about that animal. These facts and figures or materials may be the animal weight, height, shape. body structure, color of the body, color of the eyes. sleeping hours, method of eating. behavior, activities, and attitude etc. The collection of all these facts and figures is called data about a specified animal Sumuilarly. if we are domg a survey on commumity health condition then we collect different facts and figures such as how many people are sick in a specified area, how many of them are male, how many of them are female and children, how many of them have critical condition and how many of them have small infection, how many of them are under treatment and how many of them are admitted into hospital and so on. The collection of ail these facts and figures is called data about a specified disease.Introduction to C++ Programming Language 10 Types of Data The data is categorized into the following two general types. + Qualitative Data + Quantitative Data Qualitative Data It is the type of data that describes the quality of a specified object or a task. The qualitative data of an object or a task cannot be measured and counted but it can only be observed. The possible qualitative data of an object is color, shape or structure, texture, smells, location, gender, beauty, qualification, designation, physical appearance, thinking, behavior, physical fitness, knowledge, skills or experience, health condition, relationship and so on. For example, the knowledge. experience and skills of an employee, the taste of a mango, the texture of a leaf, the personal behavior and attitude of a person, the beauty. color, and smell of a flower, the gender, marital status, location, and nationality of a person and so on. Quantitative Data Tt is the type of data that describes the quantity of a specified object or a task. The quantitative data is numerical data that can be measured and counted. The possible quantitative data of an object is weight, height, length, depth, width, speed, time, body temperature, size, the number of relatives, the number of friends, marks, percentage. area, volume. costs or expenses, ages and so on. For example, marks, percentage, and CGPA of a student, monthly salary and bonus of an employee, the number of kids of a person, the numbers of teachers m a school, the number of legs of a dog. the number of players in a team and so on. The quantitative data is further divided into the following two types: « Discreet Data « Continuous DataIntroduction to C++ Programming Language n Discreet Data It is that type of quantitative data which we can count but cannot measure for example, the number of kids of a person, the marks and percentage of a student, the mumber of teachers in a school, the mumber of players in a team and so on. Continuous Data It is that type of quantitative data which we can measure but cannot count for example. the height and weight of a person, the speed of a car, the temperature of a body and so on. Data Representation in Computer System The computer system does not understand the human readable languages or high level languages. The computer is designed is such a way that it only understands and processes data in the form of machine code. The machine code is also called binary form of data or binary language. The binary language is a mathematical mumber system that contains only two digits or alphabets 0 and 1 These alphabets are also called bits. The computer system transfers and processes machine code or binary language in the form of electric signals. The bit 0 represents the absence of an electric pulse and the bit 1 represents the presence of an electric pulse. When we give data to a computer system in the form of human readable language or in the form of a high level language, the computer system converts that data into machine code or binary language and processes that data in the form of 0 and 1. A bit means binary digits and it represents the memory space of data. It is the smallest and basic unit of data that have a single bimary value either 0 or 1. The data is stored in the computer storage devices in the form of binary language that is in the form of 0 and 1. In a computer system and other telecommunication devices the data transfer rate is measured in the form of number of bits transferred im one second of time for example, if 500 bits are transferred m one second then we can say that the data transfer rate is 300 bits per second and so on. The other unit of data is called byte and it is bigger than bit. The eight bits memory space is equal to one byte.Introduction to C++ Programming Language R The Data of Programming Languages We give data to a computer system by using a program written in any programming language. The data exists in different forms for example, in the form of characters, symbols, alphabets, mumbers, constants, graphs, diagrams. charts, pictures, images, audio/video clips, audio/video conferencing, questioner, interview questions, survey, observation, and analysis etc. The programming languages take data m the form of mumbers, letters, and other special characters. According to computer programming languages the data can be divided into the following three types: + Numeric Data + Alphabetic Data + Alphanumeric Data Numeric Data When data contains only decimal numbers from 0 to 9 and a decimal point notation then it is called numeric data. For example, 23, 90, 100, 12.13, 2.5, 100.5 and so on are numeric data. The mumenic data is further divided into the following type: «Integer Numeric Data Real Numeric Data Integer Numeric Data When numeric data only contains the decimal numbers from 0 to 9 and does not contain any decimal point notation then the data is called integer numeric data. For example, 23, 90, 100 etc are integer numeric data. Real Numeric Data When numeric data contains the decimal numbers from 0 to 9 along with a decimal pomt notation then the data is called real numeric data. For example, 12.13, 2.5, 100.5 etc are real numeric data.Introduction to C++ Programming Language 13 Alphabetic Data When data contains only English alphabets from capital A to capital Z or from small a to small z is called alphabetic data. For example “Asad”, ‘Sajad” etc are alphabetic data_ Alphanumeric Data The alphanumeric data is also called text. When numeric data, alphabetic data, and some other special characters combine with each other then it forms alphanumeric data. For example, House#-13, Registration mumber = 577-ICIT-2003 etc. Introduction to C++ Programming Language The C++ programming language is a powerful computer programming language that provides comprehensively support for multiple programming styles such as procedural programming, data abstraction, object-oriented programming, and generic programming mechanism It is a general-purpose high level computer programming language that is used to develop any type of computer programs. The C++ programming language provides basic programming controls statements, Loops, Amays, Structures, Unions, Files handling techniques, Mouse Programming, Graphics Programming, Mathematical and Trigonometric fumctions, Network Programming. System Programming, Terminate and Stay Resident Pinna! eat Object Gnaaiel Praga ae The C+ programming language also supports various advanced graphics libraries as OpenGL (Open Graphics Library), DirectX. Allegro, ore (Simple Directmedia Layer) etc to design mages, geometric objects, 2-dimensional and 3-dimensional graphics images, and games programming etc. The C++ programming language runs on multiple platforms such as Microsoft Windows operating system, Mac OS, and different versions of UNIX. The History of CH Programming Language The C++ programming language is derived from C programming language that developed from the two previous programming languages BCPL and B. The BCPL programming language was developed in 1967 by Martin Richards and the B programmingIntroduction to C++ Programming Language 14 language was developed in 1970. The BCPL and B both programming languages were type less languages ie. every data item occupied one word in memory. The Dennis Ritchie at Bell Laboratories developed the C programming language from B programming language in 1972. The C programming language initially became widely known as the development language of the UNIX operating system but now the major operating systems written in C and C++ programming languages. The Bjame Stroustrup at Bell Laboratories then developed the C++ programming language from C programming language in 1980. The C++ was initially mained °C with, Claites” dus ts the‘object ecieuted. futees “ind then it was renamed from “C with Classes” to C++ in 1983 and new advanced features of the object oriented were added such as Virtual Functions, Operator Overloading etc. The new version of the C++ programming language was then released in 1991 with the addition of some advanced object oriented features such as Multiple Inheritance, Abstract Classes, Static Member Functions, and Protected Members etc. The American National Standard Institute (ANSI) and the Intemational Standard Organization (SO) committee then standardized the C++ programming language in 1998 and published an imtemational standard ISO/IEC14882:1998 for the C++ programming language that is known as C++98_ According to this standard C++ is a portable programming language. The standardized committee also added some advanced features to the C++ programming language. These features include some keywords, namespaces. conversion operators, and data types. The major C++ compiler supports the ANSI/ISO standard. The latest version of the C++ programming language is C++11. The C++11 was initially named as C++0x. The C++ 11 is an updated version of the standard C++ programming language approved by ISO on August 2011 and released m September 2011_ The C++ 11 included various advanced features to the core standard C++ programming language and extended the standard library by addimg various ords, statements, classes, and fimctions. The main features of the C++11 are Multithreaded programming mechanism, Generic programming, the Lambda fimction, Automatic type deduction ofIntroduction to C++ Programming Language 1s objects, Uniform initialization, delegating constructors, deleting and defaulted functions, the nullptr keyword, the range-based for loop, the override and final, the rvalue references, the strongly type enum, the smart pointers such as unique_ptr, shared_ptr, weak_ptr, the Unicode characters and strings, the Template aliases, the Hash tables, Regular expression, and the non member begin() and end) etc. The Microsoft Corporation then modified the C++ programming language in order to support the visual applications using the Microsoft Visual C++. The different Compilers and IDEs of C++ There are various compilers and Integrated Development Environments (IDEs) available for the C++ programming language that are used to write, debug, and execute the C++ applications or programs. Each IDE provides a text editor that is used to write the source code of C++ applications or programs. There are two types of C++ compilers and IDEs such as Microsoft DOS based and Microsoft Windows based. The DOS based compilers and IDEs work only im Microsoft DOS operating system and they compile and execute all the C++ programs in the DOS environment. The DOS based compilers and IDEs are old C++ compilers and IDEs and now a day they are used very rarely. The Windows based C++ compilers and IDEs are modern compilers and IDEs and they are usually used to develop the modern applications and programs for Microsoft Windows operating system. The Windows based C++ compilers and IDEs are used to develop various Windows based applications for Microsoft Windows operating system such as the Windows Forms applications, the Console applications, the Class Library applications. the Win3? applications, the Graphical Device Interface (GDI) applications, the GDI+ applications etc. Followmg are some popular and most useful compilers of the C++ programming language: Turbo C++ Borland C++ The Dev C++ Microsoft Visual C++ The Microsoft Visual Studio.NETIntroduction to C++ Programming Language 16 Turbo C++ The Turbo C++ is a C++ compiler and an Integrated Development Environment (IDE) was originally designed by Borland International for Microsoft Disk Operating System (MS-DOS). The Turbo C++ is widely used C++ compiler in MS-DOS and it is a 16 bit application. The Borland designed Turbo C++ for programming in MS-DOS operating system. The first version of the Turbo C++ Version 1.0 was released in May 1990 for Microsoft Disk Operating System (MS-DOS) and then it was upgraded to Version 1.01 in February 1991. The new Version of C++ Version 3.0 was released in November 1991 and when Microsoft released the Windows operating Microsoft Windows 3.0 then Borland upgraded the Turbo C++ to support the Microsoft Windows Application The Turbo C++ Version 3.0 was then upgraded to Turbo C++ Version 3.lamd then upgraded to Turbo C++ Version 4.5 to support the Microsoft Windows operating system After the Telease of Turbo C++ 3.0, Borland divided the C++ compiler m two parts such as Turbo C++ and Borland C++. The Borland added some advanced features to the Borland C++ compiler to accomplish the professional application development needed. Borland C++ The Borland C++ is a compiler and an Integrated Development Environment (IDE) was designed by Borland for MS-DOS and Windows operating system. The Borland C++ is a successor or an advanced fonm of the Turbo C++ in which some advanced features are included. There are various versions of the Borland C++ that were released time to time. The first version of the Borland C++ was Borland C++ Version 2.0 was released in 1991 for MS-DOS operating system. The second version of the Borland C++ Version 3.0 was released in 1991 for Microsoft Windows applications. The Borland C++ Version 3.0 was then upgraded to Version 3.1 im 1992 and then upgraded to Version 4.0 in 1993 and then to Version 4.02 n 1994 and in 1995 a new version of Borland C++ Version 4.52 was teleased for Windows 95. The Borland released Borland C++ IDE Version 5.02 in 1997 to support the MS-DOS and Windows NT 4.0.Introduction to C++ Programming Language iy The Dey C++ It is a free compiler and an Integrated Development Environment (IDE) that is used to write, debug. and execute the C and C++ or programs. The Dev C++ was developed by Bloodshed software for Microsoft Windows and it is also called Bloodshed Dev C++. The Dev C++ allows us to develop different types of applications or programs such as Windows Applications, Console Applications, Static Library applications, and Dynamic Link Library (DLL) applications. Microsoft Visual C++ The Microsoft Visual C++ is a compiler and am Inteprated Development Environment (DE) developed by Microsoft Corporation for C, C++, and C++/CLI programming languages. The Microsoft Visual C++ IDE is used to wote, compile, and execute the C++ code and developed the C++ applications. The Microsoft Visual C++ provides a graphical user interface and allows us to develop the Console Applications, the Windows based applications, the NET based applications, the Web applications, and the XML web services apphcations etc. The Microsoft Visual C++ is one of the core programming languages of the Microsoft Visual Studio. NET. The Microsoft Visual Studio.NET is a package of different computer programming languages that contains Visual Basic, Visual C#, Visual C++, and Visual F# etc. The Microsoft Visual Studio. NET The Microsoft Visual Studio.NET is an Integrated Development Environment (IDE) designed by Microsoft Corporation. It is used to develop Console Applications and Graphical User Interface Applications using the Windows forms and other graphical objects of Windows Forms, ASP Web applications, ASP Web services applications, XML web services applications, Windows services applications, and Mobile applications. The Microsoft Visual Studio. NET is used to write the native code and managed code supported by Microsoft Windows. The Microsoft Visual Studio NET is designed for the NET framework. The NET framework provides different features for Microsoft Visual Studio NET, for example the CommonIntroduction to C++ Programming Language 18 Language Runtime (CLR), the Common Language Infrastructure (CLD, the NET Framework Class Library that contains a huge amount of classes, interfaces, delegates, enumerations. structures, and value types. The Microsoft Visual Studio.NET provides different types of programming languages to work and rm on the same visual environment and access the same resources of the NET Framework. These programming languages are Visual C#, Visual Basic NET, Visual C++.NET, ASPNET, and Visual J#NET. The NET Framework also provides multiple language interoperability. The multiple language interoperability means each language of the Microsoft Visual Studio NET can use the programming codes written in other language. The programming languages of Visual Studio NET use the same common .NET Framework Class Library and designed different applications using the same common Integrated Development Environment (IDE). The .NET Framework provides the Common Language Infrastructure (CLI) that ensures all the programming languages of Microsoft Visual Studio.NET use the same common or combined resources of the NET Framework for example, the common NET Framework Class Library, a single common Integrated Development Environment (IDE), and a single common execution environment and so on. The CLI provides a common execution environment which is called Common Intermediate Language (CIL). The source code of a program written in any high level programming language of Visual Studio.NET is compiled by the compiler of that NET programming language and it is translated into Common Intermediate Language (CIL) code and stores into an assembly. The translated source code of a program imto CIL code is called byte-code. The byte-code is then translated into machine code and then executed by the central processing unit of computer system. The Microsoft Visual Studio NET provides the followme different features to the programmers and developers for software designing and developments: The Microsoft Visual Studio.NET Code Editor The code editor is a blank page or a document like a Microsoft Word document blank page that allows us to write the codes ofIntroduction to C++ Programming Language 19 our programs or applications. The code editor is used to write the source code of a program or an application using any programming language supported by Microsoft Visual Studio.NET. The code editor of Microsoft Visual Studio works as an intelligent detector by using the IntelliSense system that detect and sense when we write a program codes. The IntelliSense is a Microsoft implementation of auto completion system, It works like a sensor or detector. When we try to write any built-in keyword, variable, function, method. class, structure, delegate. enumeration, thread, the flow control statements, and any other built-in statement of any programming language supported by Visual Studio then the IntelliSense system detect and sense that built-in keyword or statement and completes it before we type the complete word. Therefore. this facility of Visual Studio saves our time and we can write a very large program in less time. The code editor of Visual Studio. NET uses another feature that is called Syntax Highlighting. The Syntax Highlighting aranges the built-in keywords and statements used in an application or in a program in different colors and fonts according to different categories of the keywords and statements. The same category keywords and statements are arranged im the same colors and fonts. This feature of code editor makes the program code very simple, user friendly, arranges in different categories that enable us to find out errors in the program very easily and quickly. The Microsoft Visual Studio.NET code editor provides us another facility to set bookmarks in our applications or programs codes. A bookmark is a mark or a sign used to mark or specify a line, or a place im a program code to retrieve or navigate that line, or place later im the future quickly. The Microsoft Visual Studio.NET code editor also provides background compilation of the application or program When we are writing a program code then the Visual Studio NET code editor compiles the codes and provides the feedback about the program codes. If we make the syntaxes and keywords mistakes then the Visual Studio code editor underline the incomect syntaxes or keywords using the red line. The background compilation is not the program translation but it just compiles theIntroduction to C++ Programming Language 20 program code to find out our program syntaxes and keywords mistakes. The Microsoft Visual Studio. NET Debugger A Debugger is a computer program that is used to test and find the errors in other programs or applications. The debugger program is usually used in computer programming languages and it is the part of computer programming languages. When we writes a program or an application using any programming language. the debugger program. of that programming language tests the source code of that program and finds the errors if occured im the program. The Microsoft Visual Studio.NET provides a debugger program that works both as a source level debugger and as a machine level debugger and supports both types of codes such as managed code and machine or native code. The debugger of Microsoft Visual Studio.NET is a common debugger program that is used to debug a program or an application The Microsoft Visual Studio.NET Debugger allows us to set breakpoints and stop the debugging of the program at any specified point of the program execution. The breakpoints are normally used to analyze the program code step by step or line by line to check the execution process of the program or to detect errors im the program codes. The breakpoints are also used with condition. When we use breakpoints and perform different conditions on the breakpoints and when a program is executing and during execution if a certain condition is satisfied then it triggers the breakpoints The Microsoft Visual Studio.NET Designer The Microsoft Visual Studio.NET provides different types of designer tools to the programming languages supported by Microsoft Visual Studio NET and allows us to design different applications or programs using the Visual Stdio NET Designers. The Microsoft Visual Studio.NET provides Windows Forms Designer, Web Designer, Class Designer, Data Designer. WPF Designer, Mapping Designer, and Silverlight Designer etc. Each Designer hasIntroduction to C++ Programming Language 21 its own environment for designing applications or programs. These designers are used to design different applications or programs such as Windows Forms applications, Web applications, Console Applications, Class Library Applications, Windows Control Library applications, Crystal Reports applications, and Device applications programs etc. Some designers such as Windows Forms Designer, WPF Designer, Web Designer etc provides Windows Forms and different Controls Objects for Windows Forms while some other designers such as Console Applications, Class Library applications do not provide Windows Forms and Controls Objects. A Windows Form is a container that has a visual graphical appearance and normally displays on the computer desktop. It is actually a visual frame or a container for the Controls Objects. The Controls Objects are placed on the Windows Forms and design the Windows applications. The Windows application starts from Windows Forms and it contains one or more Windows Forms. The Control Objects are graphical controls that are used on the Windows Forms. Each Control Object provides an entry point and allows a user to interact with the application or program in a graphical user mterface. The Controls Objects are designed for Windows applications programs and they are categorized into different groups according to the same functionality and nature and placed im a toolbox. A toolbox is a container that holds the Controls Objects. Each control is itself a class and they are placed inside im the System Windows Forms namespace. The groups of these controls objects are Commands controls, Containers controls, Menus and Toolbars controls, Data controls, Components controls, Printing controls, Dialog controls, and Crystal Reports controls. Each group of the controls objects has the same fimctionality controls objects. For example, the Commands control group contains the Command Buttons and text related controls objects such as Command Buttons, Textboxes, Labels, Radio buttons, Check Boxes, Combo Boxes, and List Boxes etc similarly, the Container controls contain different types of controls objects that are used to group or arrange other controls objects on the window Form These controls objects are Panel, FlowlayoutPanel, GroupBox, SplitContamer, and TabControl.Introduction to C++ Programming Language 22 Rules for writing C++ Programs Each programming language provides some fimdamentals and miles for writing computer applications or programs. Following are some basic fundamentals and rules for writing computer applications or programs in C++ programming language: + Each executable statement of the C++ program must be ended or terminated with a semicolon (.). A semicolon is the ending point of each executable statement of the C++ programming language. + The block of codes or statements must be enclosed within a pair of curly braces. » Each C++ Program must start from the preprocessor directives. The preprocessor directives are used to include header files that contam the built-m functions, keywords, and statements. Each header file contains various functions, keywords, and statements that are used for particular tasks. Each header file contains the same fimctionality functions, keywords, and statements. » The C++ programming language is a case sensitive programming language that understand only small letters and we cannot use any capital letter in the built-in fimctions, keywords, or statements. The Structure or Layout of a C++ Program The structure of C++ program means how to start and write a C++ program and how to use the built-in fimctions, keywords, and statements of C++ programming language. The structure of a C++ program contains different sections in which some sections are mandatory and some sections are optional. The mandatory sections cannot be omitted while the optional sections can be omitted and it depends on the nature of a C++ program. Each section has its own purpose and task. The sections of a C++ program are not physical sections and they don’t have physical shapes or physical locations but they are just logical specifications of a program to arrange a program im a better way. The structure of a C++ program usually confains the following five sections:Intreduction to C++ Programming Language 23 The Header Files Declaration Section The Namespace std Declaration Section The Global Declaration Section The Main or Driver Function Section The user-defined Function Definition Section The Header Files Declaration Section The C++ program always starts from the header files declaration section. This is the first section of a C++ program in which we include specific header files in our C++ program. The C++ programming language contains thousands of built-in procedures that are called functions. A function is a small block of codes that is designed to perform a specific task. The built-in fimctions are categorized into different files according to their similar nature and properties, for example String fimctions, Input/output fimctions, Math functions, Graphics fimetions. Memory Allocation and Deallocation functions, Containers Classes fimctions, Disk Input and Output functions, Data ‘Conversion fumctions etc. These files are called header files. The fimetions im each header file have the same nature and ‘The header files are permanently stored in the built-in library of C++ programming language. When we write a C++ program then we must start our program from the header files section and we must include specific header files in our C++ program. If we want to use a specific built-in function in our C++ program then we must include the header file of that built-in function. The header files are included in a C++ program from C++ library using the preprocessor directives ‘The preprocessor directives always begin with a hash (#) sign and semicolon is not written after the preprocessor directives because they are not executable statements. There are various types of preprocessor directives m C++ programming language. A preprocessor directive that is used to include header files is called “mclude” preprocessor directive. The “include” preprocessor directive is used to include header files in C++ programs. The header files declaration provides the prototype declaration for the built-in functions we want to use in our C++ program. Following is the general syntax to include header files in C++ programs: #include~Header_file_ name> or #include “Header_file_ name”Introduction to C++ Programming Language 24 The above both syntaxes are used to include header files m C++ programs. The header files and the preprocessor directives will be covered in details in Chapter # 2 The namespace std Declaration Section When we include specific header files in our C++ program then the next section of a C++ program is a namespace std declaration section. The C++ standard library is defined within the namespace std. Therefore, we must either prefix all references to the Objects of (C++ with the std:: or include “using namespace std:” at the top of the program after the header files declaration section. The Global Declaration Section The third section of a C++ program is the Global Declaration Section. This section of a C++ program is used to declare global variables and prototypes of the user-defined functions. The global variables are variables that are declared in the program to store values during the program executions. The scope of a global variable is global fo the entire program and we can access a global variable anywhere in any section of the program Each user-defined function in a C++ program has a prototype that is declared before the definition of a function The fimction prototype is also called function declaration The fimction prototype is actually a building block or a model of a fimction that describes the overall structure of a fimction. The fimction prototype defines the function name. the function retum type, and the number of arguments or parameters of a function and provides all these information to the compiler before the function body declaration. This section of a C++ program structure is optional and we can omit this section if we are not using the global variables and user-defined fimction in our program. If we are using user-defined functions in our program then we mmst declare the prototypes for those fimctions in this section of the program similarly, if we are using global variables in our program then we must declare all the global variables in this section of the program. In this section of a C++ program we can also declare Classes, Structures. and Unions. TheIntroduction to C++ Programming Language 25 global variables will be covered in details in Chapter # 2 and the user-defined functions will be covered in details in Chapter # 5. The Main or Driver Function Section The fourth section of a C++ program is the main or driver function section. This section is very important in all C++ programs because in this section we declare a main or driver function of the C++ programming language. The main fiction is a function that executes the C++ programs. The C++ programming language provides a built-in function that is called main function. The main function is a built-in function that executes the C++ programs automatically. A C+ program always starts execution from the main fimction because it is an entry point of a C++ program The main fimction is also called driver function because it controls and executes the entire C++ program. The main function contains a block of curly braces and all the executable codes are placed mside m the curly braces. The space or area between the two curly braces of the main fimction is called body of the main fiction Each C++ program has a single main function. When we execute a C++ program then the main function automatically calls and the program control comes to the body of the mam function and starts execution from first lme of the mam function and executes body of the main function hne by lme from top to the bottom. The main function does not need any initialization or any other extemal source for execution because it starts execution automatically when we mm a program. Therefore, the main function ofa C++ program is a controller that controls the entire C++ program during the program execution. The entire contents of a C++ program such as functions, classes, structures, unions etc can be controlled and execute from the main fimction The C++ programming language provides the followme four prototypes of the main fimction: int main(void) int main() int main(int arge, char **argv) int main(int arge, char *argv{])Introduction to C++ Programming Language 26 The first two prototypes of the main function do not take any parameters or arguments while the last two prototypes of the main fimction take two parameters or arguments. The first argument arge means argument counts. It is an integer variable that counts the mumber of arguments entered on the command line. The second argument argv means argument vector. It is an array that stores the munber of arguments entered on the command line. The arguments arge and argy are user-defined variables and we can give any name to these arguments according to the variables naming convention. The main function returns an integer value to the operating system. The above all prototypes of the main fimction retum integer value to the operating system. The return statement is used to retum value from the main function. The retum is a built-in keyword that is used to terminate or retum value from a main function. When we are writing a C++ program then in the main or driver function section we must use one of the above prototype of the main fumetion and will declare body of the main function. Following is the general declaration of the main fimction ma C++ program: Parameter-less main Functions int main(void) int main)Introduction to C++ Programming Language 27 Parameterized main Functions int main(int arge, char **argv) | mt main(int arge. char *argv{]) { { on Body of the main function Asingle C++ program has always a single main fimction. The above four prototypes of the maim function are different venities of the main function. We can use the above any one prototype of the main fimction in our C++ program If we want to get the command line arguments entered to the argument argv of the main function then we use one of the last two prototypes of the main function otherwise, if-we do not want to get the command line arguments entered to the argv argument then we use one of the first two prototypes of the main fimetion. The user-defined Function Definition Section This is the fifth and last section of a C++ program. This section usually starts after the closing brace of the main function of a C++ program. This section is related with the user-defined functions. If we are using the user-defined fimctions in our program then we use this section and define the bodies of all the user-defined fimctions we are using in our program. If we are not using the user-defined functions in our program then we omit this section. A Function is a procedure used in C++ programming language. It is a block of statements or codes which is executed to perform a specific task. The block of statements or codes is enclosed within curly braces { }. The first curly brace “{” indicates the starting point of a Function and the second curly brace “}” indicates the ending point of a Function.
You might also like
Chapter 2 Basic Elements of C++
PDF
No ratings yet
Chapter 2 Basic Elements of C++
32 pages
0bd513037fb9873f0177b79748356840
PDF
No ratings yet
0bd513037fb9873f0177b79748356840
8 pages
C++ ClassI
PDF
No ratings yet
C++ ClassI
48 pages
Introduction To Fundamentals of Programming
PDF
No ratings yet
Introduction To Fundamentals of Programming
65 pages
C++ - Lecures - Compressed Google-Over View
PDF
No ratings yet
C++ - Lecures - Compressed Google-Over View
42 pages
Characteristics of C++
PDF
No ratings yet
Characteristics of C++
13 pages
PF Lab Manual
PDF
No ratings yet
PF Lab Manual
72 pages
Computer Science I
PDF
No ratings yet
Computer Science I
6 pages
COSC1101 - Programming Fundamentals Lec 11-12-13
PDF
No ratings yet
COSC1101 - Programming Fundamentals Lec 11-12-13
74 pages
OOP1 N
PDF
No ratings yet
OOP1 N
90 pages
Derek Capper (Auth.) - Introducing C++ For Scientists, Engineers and Mathematicians-Springer London (2001) PDF
PDF
No ratings yet
Derek Capper (Auth.) - Introducing C++ For Scientists, Engineers and Mathematicians-Springer London (2001) PDF
551 pages
StMat Computer SC
PDF
No ratings yet
StMat Computer SC
45 pages
Computer Is A Device Capable of Performing Computations and Making
PDF
No ratings yet
Computer Is A Device Capable of Performing Computations and Making
47 pages
CP - Unit 1 - 2
PDF
No ratings yet
CP - Unit 1 - 2
43 pages
C02
PDF
No ratings yet
C02
82 pages
2 PDF
PDF
No ratings yet
2 PDF
75 pages
C++_Basics
PDF
No ratings yet
C++_Basics
4 pages
PraList C++
PDF
No ratings yet
PraList C++
5 pages
PG C++
PDF
0% (1)
PG C++
267 pages
C and OOPs
PDF
No ratings yet
C and OOPs
220 pages
Downloadable Doc 1 PDF
PDF
No ratings yet
Downloadable Doc 1 PDF
151 pages
Chapter - 3
PDF
No ratings yet
Chapter - 3
92 pages
C Through Examples Alex Vasilev PDF
PDF
No ratings yet
C Through Examples Alex Vasilev PDF
335 pages
The Basic Structure of The C/C++ Language: I. Objectives
PDF
No ratings yet
The Basic Structure of The C/C++ Language: I. Objectives
8 pages
C++ notes
PDF
No ratings yet
C++ notes
6 pages
Week 4
PDF
No ratings yet
Week 4
82 pages
C++ Short Notes
PDF
No ratings yet
C++ Short Notes
45 pages
C++ Notes
PDF
No ratings yet
C++ Notes
46 pages
C++ Notes by Girish Iyer
PDF
No ratings yet
C++ Notes by Girish Iyer
233 pages
XII C++ Jul 2023
PDF
No ratings yet
XII C++ Jul 2023
217 pages
By: Engr. M.C. Sicat
PDF
No ratings yet
By: Engr. M.C. Sicat
72 pages
Apply OOPL Skill
PDF
No ratings yet
Apply OOPL Skill
109 pages
Object Oriented Programming: Unit - I Overview of C++
PDF
No ratings yet
Object Oriented Programming: Unit - I Overview of C++
81 pages
Basics of C++ Programming Language: Ahmad Idrees
PDF
No ratings yet
Basics of C++ Programming Language: Ahmad Idrees
78 pages
Variables and Operators-1
PDF
No ratings yet
Variables and Operators-1
19 pages
Variables and Operators-1
PDF
No ratings yet
Variables and Operators-1
19 pages
II. Basic elements of C++
PDF
No ratings yet
II. Basic elements of C++
79 pages
Topic 3 - Basic Elements of A Computer Program
PDF
No ratings yet
Topic 3 - Basic Elements of A Computer Program
68 pages
Kendriya Vidyalaya Sangathan: Study Material (Computer Science) Class-Xii 2014-15
PDF
No ratings yet
Kendriya Vidyalaya Sangathan: Study Material (Computer Science) Class-Xii 2014-15
177 pages
CP 2 - Part 1
PDF
No ratings yet
CP 2 - Part 1
37 pages
295151512xii Computer Science
PDF
No ratings yet
295151512xii Computer Science
169 pages
note2-CPP Programming Review
PDF
No ratings yet
note2-CPP Programming Review
74 pages
Module - I Introduction To C++ Programming: 08.402 Computer Programming & Numerical Methods
PDF
No ratings yet
Module - I Introduction To C++ Programming: 08.402 Computer Programming & Numerical Methods
8 pages
Introduction To C++ Programming Language
PDF
No ratings yet
Introduction To C++ Programming Language
47 pages
Introduction To: The ++ Language
PDF
No ratings yet
Introduction To: The ++ Language
51 pages
CH 2
PDF
No ratings yet
CH 2
47 pages
BSC C++ Unit I
PDF
No ratings yet
BSC C++ Unit I
31 pages
Lesson2 - Intro To C
PDF
No ratings yet
Lesson2 - Intro To C
68 pages
Conceptofcdatatypes 090925045031 Phpapp02
PDF
No ratings yet
Conceptofcdatatypes 090925045031 Phpapp02
30 pages
C++ Basics
PDF
No ratings yet
C++ Basics
26 pages
Introduction To C++
PDF
No ratings yet
Introduction To C++
204 pages
Grade11 Short Note
PDF
No ratings yet
Grade11 Short Note
48 pages
C Lectures
PDF
No ratings yet
C Lectures
484 pages
PFE Chapter 2 PDF
PDF
No ratings yet
PFE Chapter 2 PDF
59 pages
OOPs 1
PDF
No ratings yet
OOPs 1
267 pages
1 Programming in C
PDF
0% (2)
1 Programming in C
554 pages
C++ Class PDF
PDF
No ratings yet
C++ Class PDF
110 pages
Basic Elements of C++
PDF
No ratings yet
Basic Elements of C++
49 pages
Related titles
Click to expand Related Titles
Carousel Previous
Carousel Next
Chapter 2 Basic Elements of C++
PDF
Chapter 2 Basic Elements of C++
0bd513037fb9873f0177b79748356840
PDF
0bd513037fb9873f0177b79748356840
C++ ClassI
PDF
C++ ClassI
Introduction To Fundamentals of Programming
PDF
Introduction To Fundamentals of Programming
C++ - Lecures - Compressed Google-Over View
PDF
C++ - Lecures - Compressed Google-Over View
Characteristics of C++
PDF
Characteristics of C++
PF Lab Manual
PDF
PF Lab Manual
Computer Science I
PDF
Computer Science I
COSC1101 - Programming Fundamentals Lec 11-12-13
PDF
COSC1101 - Programming Fundamentals Lec 11-12-13
OOP1 N
PDF
OOP1 N
Derek Capper (Auth.) - Introducing C++ For Scientists, Engineers and Mathematicians-Springer London (2001) PDF
PDF
Derek Capper (Auth.) - Introducing C++ For Scientists, Engineers and Mathematicians-Springer London (2001) PDF
StMat Computer SC
PDF
StMat Computer SC
Computer Is A Device Capable of Performing Computations and Making
PDF
Computer Is A Device Capable of Performing Computations and Making
CP - Unit 1 - 2
PDF
CP - Unit 1 - 2
C02
PDF
C02
2 PDF
PDF
2 PDF
C++_Basics
PDF
C++_Basics
PraList C++
PDF
PraList C++
PG C++
PDF
PG C++
C and OOPs
PDF
C and OOPs
Downloadable Doc 1 PDF
PDF
Downloadable Doc 1 PDF
Chapter - 3
PDF
Chapter - 3
C Through Examples Alex Vasilev PDF
PDF
C Through Examples Alex Vasilev PDF
The Basic Structure of The C/C++ Language: I. Objectives
PDF
The Basic Structure of The C/C++ Language: I. Objectives
C++ notes
PDF
C++ notes
Week 4
PDF
Week 4
C++ Short Notes
PDF
C++ Short Notes
C++ Notes
PDF
C++ Notes
C++ Notes by Girish Iyer
PDF
C++ Notes by Girish Iyer
XII C++ Jul 2023
PDF
XII C++ Jul 2023
By: Engr. M.C. Sicat
PDF
By: Engr. M.C. Sicat
Apply OOPL Skill
PDF
Apply OOPL Skill
Object Oriented Programming: Unit - I Overview of C++
PDF
Object Oriented Programming: Unit - I Overview of C++
Basics of C++ Programming Language: Ahmad Idrees
PDF
Basics of C++ Programming Language: Ahmad Idrees
Variables and Operators-1
PDF
Variables and Operators-1
Variables and Operators-1
PDF
Variables and Operators-1
II. Basic elements of C++
PDF
II. Basic elements of C++
Topic 3 - Basic Elements of A Computer Program
PDF
Topic 3 - Basic Elements of A Computer Program
Kendriya Vidyalaya Sangathan: Study Material (Computer Science) Class-Xii 2014-15
PDF
Kendriya Vidyalaya Sangathan: Study Material (Computer Science) Class-Xii 2014-15
CP 2 - Part 1
PDF
CP 2 - Part 1
295151512xii Computer Science
PDF
295151512xii Computer Science
note2-CPP Programming Review
PDF
note2-CPP Programming Review
Module - I Introduction To C++ Programming: 08.402 Computer Programming & Numerical Methods
PDF
Module - I Introduction To C++ Programming: 08.402 Computer Programming & Numerical Methods
Introduction To C++ Programming Language
PDF
Introduction To C++ Programming Language
Introduction To: The ++ Language
PDF
Introduction To: The ++ Language
CH 2
PDF
CH 2
BSC C++ Unit I
PDF
BSC C++ Unit I
Lesson2 - Intro To C
PDF
Lesson2 - Intro To C
Conceptofcdatatypes 090925045031 Phpapp02
PDF
Conceptofcdatatypes 090925045031 Phpapp02
C++ Basics
PDF
C++ Basics
Introduction To C++
PDF
Introduction To C++
Grade11 Short Note
PDF
Grade11 Short Note
C Lectures
PDF
C Lectures
PFE Chapter 2 PDF
PDF
PFE Chapter 2 PDF
OOPs 1
PDF
OOPs 1
1 Programming in C
PDF
1 Programming in C
C++ Class PDF
PDF
C++ Class PDF
Basic Elements of C++
PDF
Basic Elements of C++