Introduction to C++ : 500+ Difficulty-Scaled Solved Programming Exercises. 1st Edition George S. Tselikis 2024 scribd download
Introduction to C++ : 500+ Difficulty-Scaled Solved Programming Exercises. 1st Edition George S. Tselikis 2024 scribd download
com
https://ebookmeta.com/product/introduction-
to-c-500-difficulty-scaled-solved-programming-exercises-1st-
edition-george-s-tselikis/
OR CLICK HERE
DOWLOAD NOW
https://ebookmeta.com/product/introduction-to-c-programming-2nd-
edition-purdue-univ/
ebookmeta.com
https://ebookmeta.com/product/an-introduction-to-c-gui-programming-
simon-long/
ebookmeta.com
https://ebookmeta.com/product/oaken-s-invention-disney-books/
ebookmeta.com
Mechanical and industrial measurements 3rd Edition R. K.
Jain
https://ebookmeta.com/product/mechanical-and-industrial-
measurements-3rd-edition-r-k-jain/
ebookmeta.com
https://ebookmeta.com/product/birth-of-a-white-nation-the-invention-
of-white-people-and-its-relevance-today-2nd-edition-jacqueline-
battalora/
ebookmeta.com
https://ebookmeta.com/product/specworld-folds-faults-and-fractures-in-
embedded-creator-industries-1st-edition-john-thornton-caldwell/
ebookmeta.com
https://ebookmeta.com/product/complementary-and-alternative-medicine-
sourcebook-7th-ed-7th-edition-james-chambers/
ebookmeta.com
https://ebookmeta.com/product/raising-a-humanist-conscious-parenting-
in-an-increasingly-fragmented-world-1st-edition-manisha-pathak-shelat/
ebookmeta.com
Introduction to C++
This book is primarily for students who are taking a course on the C++ language, for those who wish to
self-study the C++ language, and for programmers who have experience with C and want to advance to
C++. It could also prove useful to instructors of the C++ course who are looking for explanatory program-
ming examples to add in their lectures.
The focus of this book is to provide a solid introduction to the C++ language and programming knowledge
through a large number of practical examples and meaningful advice. It includes more than 500 exercises
and examples of progressive difficulty to aid the reader in understanding the C++ principles and to see
how concepts can materialize in code.
The examples are designed to be short, concrete, and substantial, quickly giving the reader the ability
to understand how to apply correctly and efficiently the features of the C++ language and to get a solid
programming know-how. Rest assured that if you are able to understand this book’s examples and solve
the exercises, you can safely go on to edit larger programs, you will be able to develop your own applica-
tions, and you will have certainly established a solid fundamental conceptual and practical background to
expand your knowledge and skills.
Introduction to C++
George S. Tselikis
First edition published 2023
by CRC Press
6000 Broken Sound Parkway NW, Suite 300, Boca Raton, FL 33487-2742
Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume
responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to trace
the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish
in this form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may
rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any
form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and
recording, or in any information storage or retrieval system, without written permission from the publishers.
For permission to photocopy or use material electronically from this work, access www.copyright.com or contact the Copyright
Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. For works that are not available on CCC
please contact [email protected]
Trademark Notice: Product or corporate names may be trademarks or registered trademarks and are used only for identification
and explanation without intent to infringe.
Typeset in Times
by KnowledgeWorks Global Ltd.
This book is dedicated to my family.
Contents
Preface ix
Acknowledgements xi
About the Author xiii
1 Introduction to C++ 1
3 Data Input/Output 31
4 Operators 45
5 Program Control 71
6 Loops 99
7 Arrays 133
8 Pointers 169
9 Characters 217
10 Strings 227
11 Functions 265
20 Inheritance 637
vii
viii Contents
22 Exceptions 717
24 Files 773
Epilogue 871
Annex A: Precedence Table 873
Annex B: ASCII Table 875
Annex C: Hexadecimal System 877
Bibliography 879
Index 881
Preface
This book is primarily addressed to students who are taking a course on the C++ language, to those who
wish to self-study the C++ language, as well as to programmers who have experience with C and want to
move on to C++. It could also prove useful to instructors of the C++ course, who are looking for explana-
tory programming examples to add in their lectures.
This book aims to introduce the reader to the basic principles of C++ and the philosophy of
object-oriented programming. It does not present all the technical and syntax details of the language,
but tries to present the fundamental concepts of the language in a simple and understandable way. So,
this book is not a reference book; its goal is to make the reader understand how to use a feature and
not to describe every syntax or technical detail of the feature. Understanding the technical details
comes with time and practice. After all, you don’t have to know all the details of C++ to write C++
programs.
Also, this book does not present in detail the services of the Standard Template Library (STL). It just
provides an overview of its most important features. A detailed presentation of STL would require an
entire book. However, because learning STL is an integral part of learning C++, you should, after read-
ing this book, read an STL reference book in order to get familiar with the numerous useful services and
tools that STL offers.
So what, exactly, differentiates this book from the others in the field? This book tests the skills of the
reader by providing a solid introduction to the C++ theory enriched with tips and advice accompanied by
a large number of difficulty-scaled examples and solved programming exercises showing how concepts
can materialize in code. When I first encountered the C++ language as a student, I needed a book that
would introduce me to in a smooth way to the fundamentals of the C++ language, to provide a robust
foundational understanding of its principles, a book with a focus on providing inside information and
programming knowledge through practical examples and meaningful advice. That is the spirit that this
book aims to capture.
It presents in a compact and substantial way the essentials of the C++ language and contains a large
number of explanatory examples and solved exercises of scaling difficulty. Through them, language pit-
falls are frequently discussed, in order for the reader to understand the little tweaks and hidden traps
which a programmer – especially novice but not only – usually bumps into. There are trap holes the reader
is lured to fall into. There are examples on how things that look normal can nevertheless go wrong. Be
sure that if you are able to understand the book's examples and solve the exercises, you can safely go on to
edit longer programs, you’ll be able to read more complex programs, and you’ll have certainly established
a solid fundamental conceptual and practical background to expand your knowledge. The source code of
the exercises is available at www.cplusplus.gr.
To the question if you need to know C or some other programming language to read this book, the
answer is no. This book introduces C++ from scratch. No prior programming experience is required.
Also, in the question if one needs to learn C before C++, my opinion is to start with C++. C++ is more
secure, very powerful, with much more expressive and technical capabilities. Is it an easy language? No,
it contains a lot of difficult concepts, which require lot of practice in order to understand them and apply
correctly and efficiently in your programs. C++ is not learned (if at all) in a week or in a year; it is an
intrinsically hard language to master and even at a later stage of the learning curve, there will always be
reasons to go back to the fundamentals. Therefore, even an advanced programmer, may get benefited to
browse this book from times to times.
ix
x Preface
For all of you who intend to deal with computer programming, a little bit of advice coming from my
experience may come in handy:
• Programming is a difficult task that among other things it requires clear mind, calmness,
patience, self-confidence, and luck as well. Don’t write code when you are in a bad mood
(e.g., certainly not if your favourite team lost the game), tired, or stressed.
• When coding, try to write in a simple and comprehensive way for your own benefit and for
those who are going to read your code. Always remember that the debug, maintenance, and
upgrade of a code written in a complex way is a painful process.
• Hands-on! To learn the features of any programming language, you must write your own pro-
grams and experiment with them.
• Programming is definitely a creative activity, but do not forget that there are plenty of creative,
pleasant, and less stressful activities in life. Do not waste your life in front of a computer
screen, searching for infinite loops, dangling pointers, thrown exceptions, buffer overflows,
and buggy conditions. Program for some time and then have some fun. Keep living and do not
keep programming.
Enjoy the C++ flight; it would be safe, with some turbulence, though.
Acknowledgements
I would like to thank S. Stamatiadis, N. Tselikas, and, particularly, I. Karali and A. Kotaras, whose com-
ments, fruitful suggestions, and criticisms contributed to the improvement of this book.
xi
About the Author
Dr. George S. Tselikis received both his Dipl.–Ing. degree and his PhD from the School of Electrical
and Computer Engineering of National Technical University of Athens (NTUA). In 1998, he joined
the Department of Electrical Engineering at Columbia University, New York, and worked as a postdoc
research associate. He was a founding member of 4Plus S.A. (1999–2014), where he worked in the devel-
opment of network protocols and services. He has a long working experience in the telecom area, and his
main research interests focus on software specification, development, and testing of network protocols
and services in wired and wireless networks. He has participated in many European research projects
and he has collaborated with several companies in the telecom industry. Since 2004, he has been a visit-
ing lecturer in several Greek universities teaching courses related to network technologies, protocols and
communications, and programming languages.
xiii
Another Random Document on
Scribd Without Any Related Topics
Minä myöskin aamun aallon lailla ennen lapsenmiellä
laulelin, sitten lietona kuin rannan haavat leikin, lemmin,
lauloin, tanhusin; nytp' on riemu poissa, kerttu kulta, saanut
olen huolenvirret sulta.
1895.
Matkalla.
1895.
1895.
Sinipiiat.
Sinipiikojen laulu.
1894.
Pihlajan alla.
— "Miks äkkiä vaikenit, impyein, miks silmäsi kyynelöi?
Mikä pilvi peittävi päivyein, mikä onnesi ontoks söi? Kas,
kuinka kukkivi kaunis maa ja laulavi leivonen ja kuinka pihlaja
tuoksuaa — sinä vain olet murheinen!
1895.
Sonetti Leilalle.
1896.
Sukkamieli.
1896
Tälläpä pojall' on —.
1896.
Hatara sydän.
1896.
Samettisilmä.
1896.
Soutelemassa.
1896.
Hanget soi!
Hanget soi, hanget soi, ja kevät yli kenttien tuulee. Rintani
lyö, rintani käy, taas sieltä jo kuohua kuulee.
1897.
Hämärissä.
(1897).
"Mais oú sont les neiges d'antan?"
Villon.
1.
Vai loistiko niist' oma onneni tuo, jota eloni halki ma hain,
joka kutsuvi luo, joka käskevi luo, mut kaikuna karkaa ain?
2.
3.
4..
Oi, istuos impeni tänne, niin annamme aattehen, niin
annamme aattehen lentää yli vuorien, laaksojen.
5.
En tiedä, miks sua pelkään, kun noin sua katselen. On kuin
sun silmies yöstä sois kaikuja kellojen.
6.
7.
Hän kulkevi kuin yli kukkien, hän käy kuni sävelten siivin,
niin norjana notkuvi varsi sen, kun vastahan vaiti ma hiivin.
8.
Leikitäänkö? Leikitään.
Kisasilla kiistellään.
Ole sinä kissa, minä olen hiiri!
Täss’ on tanhumme piiri.
9.
10.
11.
12.
13.
Sa kuuletko laulua kummaa, joka lemmikin lehdiltä soi, se
minulle mielen oudon ja haavehet herkät toi.
14.
15.
Elä pelkää, impeni nuori, ei emo sua peloittais, häll' oli niin
lempeät silmät — jo kirkkokin jäädä tais.
16.