ebook img

Programming in C++: Object Oriented Features: 5 (Information and Computer Engineering) PDF

365 Pages·2019·6.833 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Programming in C++: Object Oriented Features: 5 (Information and Computer Engineering)

LaxmishaRai ProgramminginC++ Brought to you by | provisional account Unauthenticated Download Date | 1/8/20 12:48 PM Information and Computer Engineering Volume 5 Already published in the series Volume4 ShuqinLou,ChunlingYan,DigitalElectronicCircuits,2018 ISBN978-3-11-061466-4,e-ISBN978-3-11-061491-6,e-ISBN(EPUB)978-3-11-061493-0 Volume3 BaolongGuo,SignalsandSystems,2018 ISBN978-3-11-059541-3,e-ISBN978-3-11-059390-7,e-ISBN(EPUB)978-3-11-059296-2 Volume2 JieYang,CongfengLiu,RandomSignalAnalysis,2018 ISBN978-3-11-059536-9,e-ISBN978-3-11-059380-8,e-ISBN(EPUB)978-3-11-059297-9 Volume1 BeijaNing,AnalogElectronicCircuit,2018 ISBN978-3-11-059540-6,e-ISBN978-3-11-059386-0,e-ISBN(EPUB)978-3-11-059319-8 Brought to you by | provisional account Unauthenticated Download Date | 1/8/20 12:48 PM Laxmisha Rai Programming in C++ Object-Oriented Features Brought to you by | provisional account Unauthenticated Download Date | 1/8/20 12:48 PM Author LaxmishaRai CollegeofElectronicandInformationEngineering ShandongUniversityofScienceandTechnology, Qingdao,China. ISBN978-3-11-059539-0 e-ISBN(PDF)978-3-11-059384-6 e-ISBN(EPUB)978-3-11-059295-5 ISSN2570-1614 LibraryofCongressControlNumber:2018954463 BibliographicinformationpublishedbytheDeutscheNationalbibliothek TheDeutscheNationalbibliothekliststhispublicationintheDeutscheNationalbibliografie;detailed bibliographicdataareavailableontheInternetathttp://dnb.dnb.de. ©2019WalterdeGruyterGmbH,Berlin/Boston,SciencePress Typesetting:IntegraSoftwareServicesPvt.Ltd. Printingandbinding:CPIbooksGmbH,Leck Coverimage:Prill/iStock/GettyImagesPlus www.degruyter.com Brought to you by | provisional account Unauthenticated Download Date | 1/8/20 12:48 PM Preface Today, use of computers and application of software can be seen everywhere. The rapidprogressininformationtechnology(IT)haschangedourconventionalwaysof thinking. It is hard to imagine life without computers and software these days. Programming is an essential part of computing. Many programming languages weredevelopedovertheyears,however,veryfewofthemsurvivedintheITmarket. C++isonesuchprogramminglanguagethatcanrightlybecalledasasuccessortoC language.C++isageneral-purposeprogramminglanguagewitharichsetofobject- orientedprogramming(OOP)andgenericprogrammingfeatures.Thislanguagewas created by BjarneStroustrup, aDanish computer scientist, in1980s. Today,C++ is oneofthemostprominentandusefulOOPlanguages.Itisstudiedwidelybystudents andprogrammersalike.C++supportsanumberoffeatures,suchasclasses,objects, inheritance,constructors,andpolymorphismthatmakeitsouseful.Thisbookcovers all of these concepts along with the basics of programming, including selection statements,looping,arrays,strings,functionsorting,andsearchingalgorithms. The book is written by focusing programmers, both experienced and inexper- ienced,whowouldliketolearnC++withorwithoutanypriorprogrammingexperi- ence.ThemainobjectiveofthebookistopresentanoverviewofC++programming language with OOP concepts. The book is presented in simple English and easy examples. It can be used as a textbook for graduate or undergraduate programs. ThebookwillprovideeveryreaderanideatowriteandpracticeC++programsaswell asunderstandingvariouscomputersandprogrammingtermsinEnglish.Thereare manyfeaturesthatwillmakethisbookuniqueamongC++textbooks.Alargenumber ofexampleprogramsandillustrationswillbepresentedthroughoutthebook.Allof the programs are written with maximum care and attention. Many programming exercisesarealsoprovided,wherevernecessary.Wearesurethateveryreaderwill enjoyC++programmingwhilereadingthisbook. Thisbookcoversalmostallofthenecessaryfeaturesofobject-orientedprogram- mingwithC++.Thereareatotalof18chaptersinthebook.Eachchapterstartswitha briefintroductionaboutitscontentsandscope.Eachchapterhasasetofquestions forthereadertoanswerandthinkaboutpossibleanswersaswell.Thebookpresents over 180 complete programs with their respective input and output details. We suggesteveryreadertogothroughallofthechaptersstartingfrom1to18inorder tomasterC++programming.Thisbookcanbedividedintotwoparts.Thefirstpartis from Chapters 1 to 13, which covers the basics of C++ programming, or concepts whicharenotdirectlyrelatedOOP.Eventhoughthesechaptersusethetermsclasses andobjectshereandthere,thereisnoneedofexclusiveknowledgeofOOPconcepts. So,teacherswhoarewillingtotraintheirstudentsinthebasicsofC++maychoose thesechaptersasintroductorylessonsonC++programming.Thesecondpartisfrom Chapters 14 to 18. This part is about topics that are directly related to OOP. These chaptersprovidethereaderstheexclusivefeaturesofOOPinC++.So,thelearners https://doi.org/10.1515/9783110593846-201 Brought to you by | provisional account Unauthenticated Download Date | 1/8/20 12:50 PM VI Preface whoarefamiliarwiththebasicsofC++maystartfromChapter14tounderstandthe OOPconceptsdirectly.However,thebookiswritteninsuchawaythatthereadercan jumptoanychaptertoacquireexactinformationwithoutfollowingthesequenceof chapters. Inadditiontoallthesechapters,thebookpresentsfiveappendicesforsupport- ingthematerialspresentedinthisbook.AppendixAprovidesthelistofC++header filesandlibraryfunctions.Itisprovidedasa quickreferenceforlearnerstolocate severallibraryfunctionsprovidedbyC++.Thebriefdescriptionoftheseheaderfiles andrespectivelibraryfunctionsareprovidedinmultipletables.AppendicesBandC providealistofnon-OOPandOOPexercisesofC++,respectively.Thebookprovides twodifferentsections,sothattheinstructorsareabletodividetheexercisesonthe basis of the students’ ability and course requirements. In some universities or colleges, instructors prefer their students to learn object-oriented concepts of C++ only. In such cases, it is better to refer to the exercises shown in Appendix C. However,iftheinstructorismorefocusedonteachingfundamentalsofprogramming concepts through C++, then programming exercises listed in Appendix B are pref- erable.Inadditiontotheseprogrammingexercises,therearealsosomeprogramming exercisespresentedattheendofeachchapterinsection“ReviewQuestions.” AppendixDliststheDecimal-Binary-Octal-HexASCII(AmericanStandardCode for Information Interchange) conversion chart. It is very useful while writing pro- grams of especially related character data type. In addition, it is necessary for learners to understand how the numbers are represented in different formats. AppendixEprovidesBibliographyinformation. The book uses different fonts such as bold, and Inconsolata , to identify the variousconcepts.Forexample,theboldtextremindstheuserthatthesewordsare importantandcommonlyusedtermsinunderstandingconceptsofC++andOOP.All theprogramsshowninthebookareinInconsolata,sothatthereaderscaneasily identifythem.Moreover,wehavealsousedthisfontwithinthetextfordescribingthe concepts, to show the readers that these words may form a part of a program, or becloselyrelatedtoaprogram.Theoutputsofexampleprogramsarealsoprovidedso that the readers can easily guess that the results obtained after the execution of program. Wehopethatyoufindthisbookinteresting,enjoyable,andinformative.Wewish allthereaderseverysuccessinC++programming. HappyProgramming! LaxmishaRai Brought to you by | provisional account Unauthenticated Download Date | 1/8/20 12:50 PM Contents Preface V AbouttheAuthor XIII 1 IntroductiontoComputersandProgramming 1 1.1 Historyofcomputers 1 1.2 Introductiontocomputerandcomputerscience 1 1.3 Introductiontosoftware 3 1.4 Programminglanguages 6 1.5 Typesofprogramminglanguages 7 1.6 Reviewquestions 9 2 IntroductiontoObject-OrientedProgrammingandC++ 11 2.1 Introduction 11 2.2 Object-orientedconcepts 11 2.3 IntroductiontoC++ 13 2.4 VersionsofC++ 14 2.5 WritingthefirstC++program 14 2.6 CompilingandrunningC++Programs 17 2.7 RunningC++programsonline 18 2.8 RunningC++programsinvisualstudio2017 23 2.9 RunningC++programsinmicrosoftvisualC++ 28 2.10 RunningC++programsincodeblocksIDE 32 2.11 WritingthefirstC++programinCodeBlocksIDE 38 2.12 Comprehensiveunderstandingofobject-orientedconcepts inC++ 41 2.13 Reviewquestions 45 3 ProgrammingBasics 47 3.1 Introduction 47 3.2 Variablesandidentifiers 47 3.3 C++Keywords 48 3.4 Datatypes 49 3.5 C++Literalsandconstants 52 3.6 Typecasting 60 3.7 Inputandoutputmanipulators 62 3.8 Storagedurationandscope 63 3.9 Reviewquestions 69 Brought to you by | provisional account Unauthenticated Download Date | 1/8/20 12:50 PM VIII Contents 4 OperatorsandExpressions 71 4.1 Introduction 71 4.2 Relationalandequalityoperators 72 4.3 Arithmeticoperators 72 4.4 Bitwiseoperators 73 4.5 Assignmentoperators 77 4.6 Incrementanddecrementoperators 78 4.7 Logicaloperators 80 4.8 Conditionaloperator 80 4.9 Operatorprecedence 81 4.10 Reviewquestions 83 5 SelectionStatements 85 5.1 Introduction 85 5.2 Theifstatement 85 5.3 Theif-elsestatement 87 5.4 Theif-else-ifstatement 89 5.5 Nestedif-elsestatement 90 5.6 Theswitchstatement 93 5.7 Theternaryoperator 97 5.8 Reviewquestions 99 6 LoopingStatements 101 6.1 Introduction 101 6.2 Thewhileloop 101 6.3 Thedo-whileloop 104 6.4 Theforloop 107 6.5 Nestingofloops 111 6.6 Thebreakstatement 112 6.7 Thecontinuestatement 116 6.8 Reviewquestions 117 7 Arrays 121 7.1 Introduction 121 7.2 One-dimensionalarrays 122 7.3 Multidimensionalarrays 125 7.4 Applicationsoftwo-dimensionalarrays 127 7.5 Reviewquestions 135 Brought to you by | provisional account Unauthenticated Download Date | 1/8/20 12:50 PM Contents IX 8 StringsandPointers 137 8.1 Introduction 137 8.2 Stringlibraryfunctions 141 8.3 Arrayofstrings 143 8.4 Introductiontopointers 144 8.5 Pointertopointer 148 8.6 Pointersandarrays 150 8.7 Arrayofpointers 152 8.8 Reviewquestions 153 9 SearchingandSorting 155 9.1 Introduction 155 9.2 Searching 155 9.3 Linearsearch 155 9.4 Binarysearch 157 9.5 Sorting 159 9.6 Insertionsort 160 9.7 Selectionsort 162 9.8 Bubblesort 164 9.9 Sortingcharactersandstrings 167 9.10 Reviewquestions 172 10 Functions 173 10.1 Introduction 173 10.2 Definingafunction 174 10.3 Argumentsandparameters 177 10.4 Scopeoffunctionvariables 180 10.5 Staticvariables 183 10.6 Scoperesolutionoperator 185 10.7 Functionsandpointers 187 10.8 Recursivefunctions 190 10.9 Inlinefunctions 197 10.10 Built-infunctions 198 10.11 Reviewquestions 200 11 StructuresandUnions 203 11.1 Introduction 203 11.2 Definingstructures 204 11.3 Initializingstructures 205 11.4 Accessingstructuremembers 206 11.5 Usingtypedefkeyword 208 Brought to you by | provisional account Unauthenticated Download Date | 1/8/20 12:50 PM

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.