Let Us C++
eBook - ePub

Let Us C++

Dive into the nitty-gritties of C++ language and learn why programmers prefer OOPs and C++

Yashavant Kanetkar

Buch teilen
  1. English
  2. ePUB (handyfreundlich)
  3. Über iOS und Android verfügbar
eBook - ePub

Let Us C++

Dive into the nitty-gritties of C++ language and learn why programmers prefer OOPs and C++

Yashavant Kanetkar

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

Highlights Core Features Like Encapsulation, Polymorphism, Inheritance, Virtual Functions, Templates, Exception Handling, STL and more Most best-selling software including MS Office, Internet Explorer, Photoshop, AutoCAD, Google Earth, Firefox etc. are written in C++. So, for anyone who aspires to write good software, C++ has become thelanguage of choice. One has to know the concepts of Object-Oriented Programming and how to use them in C++, to make a mark in the programming world. Let Us C++ teaches you C++ in Yashavant Kanetkar's inimitable style.You would find Let Us C++ easy, yet incredibly thorough. Every discussion is highlighted by clear, direct examples. It will not only serve as your tutorial, but it is likely to be the first thing that you would reach for when faced with a confusing issue. KEY FEATURES• Strengthens the foundations, as a detailed explanation of programming language concepts are given. • Lists down all the important points that you need to know related to various topics in an organized manner.• Provides In-depth explanation of complex topics.• Focuses on how to think logically to solve a problem. WHAT WILL YOU LEARNClasses & Objects, Free Store Management, Stream I/O, References, Virtual Tables and vptr, Templates, Polymorphism, Namespaces, Exception Handling, Inheritance, Smart Pointers, STL WHO THIS BOOK IS FORStudents, Programmers, researchers, and software developers who wish to learn the basics of C++ programming language.AUTHOR BIOYashavant KanetkarThrough his books and Quest Video Courses on C, C++, Java, Python, Data Structures,.NET, IoT, etc. Yashavant Kanetkar has created, molded and groomed lacs of IT careers in the last three decades. Yashavant's books and Quest videos have made a significant contribution in creating top-notch IT manpower in India and abroad.Yashavant's books are globally recognized and millions of students/professionals have benefitted from them. Yashavant's books have been translated into Hindi, Gujarati, Japanese, Korean and Chinese languages. Many of his books are published in India, USA, Japan, Singapore, Korea and China.Yashavant is a much sought after speaker in the IT field and has conducted seminars/workshops at TedEx, IITs, IIITs, NITs and global software companies.Yashavant has been honored with the prestigious "Distinguished Alumnus Award" by IIT Kanpur for his entrepreneurial, professional and academic excellence. This award was given to top 50 alumni of IIT Kanpur who have made a significant contribution towards their profession and betterment of society in the last 50 years. In recognition of his immense contribution to IT education in India, he has been awarded the "Best.NET Technical Contributor" and "Most Valuable Professional" awards by Microsoft for 5 successive years.Yashavant holds a BE from VJTI Mumbai and M.Tech. from IIT Kanpur. Yadhavant's current affiliations include being a Director of KICIT Pvt Ltd. And KSET Pvt Ltd. His Linkedin profile: linkedin.com/in/yashavant-kanetkar-9775255

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Let Us C++ als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Let Us C++ von Yashavant Kanetkar im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Computer Science & Programming in C++. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Jahr
2020
ISBN
9789388176644

1

Introduction To OOP

Object Oriented programming languages like C++ and Java have emerged as the top choice of programmers to create complex applications for the modern digital world. Before we dive into the nitty-gritties of C++ language, it is important to understand why programmers prefer OOPs and C++
  • The Beginning…
  • Structured Programming
  • Object Oriented Programming
  • Characteristics of Object Oriented Languages
    Objects
    Classes
    Encapsulation
    Data hiding
    Inheritance
    Polymorphism
    Containership
    Templates
    Exception handling
    Reusability
  • Exercise
  • KanNotes
What is object-oriented programming (OOP)? This question is little difficult to answer because the software industry has a fascination for terminologies and catch words. Not long ago, words like “artificial intelligence”, “WAP” and “Java” were used as if they were to offer a path to heaven. The same overuse seems to be happening to the phrase “object-oriented”. Since it has been proven that object-oriented techniques offer a way to write better programs, everybody seems to be slapping the label “object-oriented” on their software products.
Hence it is important for us to understand what is OOP, why do we need it, what does it do that traditional languages like C, Pascal and Basic don't and what are the principles behind OOP. This chapter addresses these issues and provides an overview of the features to be discussed in the rest of the book. What we say here will necessarily be general and brief. Don't worry if you don't catch everything in this chapter on the first pass; OOP is a bit complex and understanding it takes time. We will be going over these features again in subsequent chapters. There's lot of ground to cover here, so let's get started.
The purpose of a programming language is to express the solution to a problem with the help of an algorithm (step by step procedure). The success of the solution depends on how the solution models (represents) the problem. Different approaches have evolved over the years to model solutions to problems. The primary amongst them are Structured programming model (also called Procedural programming model) and Object-oriented programming model. Of late, the structured programming model is being replaced by object-oriented programming model. To understand these models we need to begin by taking a peek at the history of programming models.

The Beginning…

The earliest computers were programmed in binary. Mechanical switches were used to load programs. With the advent of mass storage devices and larger and cheaper computer memories, the first high-level computer programming languages came into existence. With their arrival, instead of thinking in terms of bits and bytes, programmers could write a series of English-like instructions that a compiler could translate into the binary language of computers.
These languages were simple in design and easy to use because programs at that time were primarily concerned with relatively simple tasks like calculations. As a result, programs were pretty short, limited to about a few hundred lines of instructions.
As the computers’ capacity and capability increased, so also did the ability to develop more complex computer programs. However, the earlier programming languages were found wanting in performing the complex programming tasks. These languages suffered from the following limitations:
  1. There were no facilities to reuse existing program code. Wherever the same piece code was required, it was simply duplicated.
  2. The control of execution within a program was transferred via the dangerous goto statement. As a result, there was too much jumping around in the program, often without any clear indication of how, where and why the control is flowing.
  3. All variables in the program were global. Tracking down spurious changes in global data in long convoluted programs was a very tedious job.
  4. Writing, understanding and maintaining long programs became a programmer's nightmare.
In short, we can call this methodology of developing programs as Unstructured programming.

Structured Programming

To overcome the limitations mentioned above, a quest began to develop new languages with new features that would help to create more sophisticated applications. The breakthrough occurred in late 1960's and early 1970's with the introduction of structured programming. The long programs that the programmer found difficult to comprehend could now be broken down into smaller units of few hundred statements. Functions/subroutines/procedures were introduced in these languages to make the programs more comprehensible to their human creators. A program was now divided into functions, with each function having a clearly defined purpose. How structured programming overcame the limitations experienced in unstructured programming is given below.
  1. Reuse of existing program code - Wherever the same piece code is required at multiple places in a program, the function containing that code is used. As a result, there is no need to repeat the same code at multiple places.
  2. Excessive use of goto statement - The excessive use could be minimized with the introduction of powerful control instructions that could transfer the control within the program in an easy-to- understand manner.
  3. Unexpected changes in global variables - With introduction of functions, need for global variables got minimized.
  4. Complexity of programs - Complexity became more manageable as structured programming permitted better organization of the program.
A structured program is built by breaking down a solution into smaller pieces (also called as divide and conquer technique) that then become functions within that program. Each function can have its local variables and logic. The execution begins with one function and then all other functions are called directly or indirectly from this function. This is shown in Figure 1-1.
Figure 1-1. Structured programming.
In structured programming, there is less need of global variables, which are now replaced by local variables that have a smaller and more controllable scope. Information is passed between functions using parameters and functions can have local variables that cannot be accessed outside the function's scope.
By isolating processes within functions, a structured program minimizes the chance that one function will affect another. This also makes it easier to locate problems, if any. Structured programming helps you to write cleaner code and maintain control over each function. All this makes the development and maintenance of code easier as well as efficient.
A new concept came into existence with structured programming— Abstraction. Abstraction permits the programmer to look at something without being concerned with is internal details. In a structured program, it is enough to know which task is performed by function. It does not matter to the programmer how that task is performed so long as the function does it reliably. This is called functional abstraction and is the corner-stone of structured programming.
Structured programming dominated the software world for almost two decades—from 1970 to 1990. With the constant improvement in the hardware and increasing demands from the users for feature-rich programs, the complexity of programs increased multi-fold and that's the time structured programming approach started showing signs of strain. This occurred because of the following weaknesses in the structured programming model:
  1. The primary components of structured programming—functions and data structures—didn't model the real world problems in a natural way.
  2. Mechanisms to reuse existing code were limited.
  3. Maintaining, debugging and upgrading large programs were a difficult task.
The solution to these limitations is discussed in the next section.

Object Oriented Programming

The real-world problems and their solutions are not organized into values and procedures separate from one another. Problem solvers do not perceive the world that way. They deal with their problem domains by concentrating on the objects and letting the characteristics of those objects determine the procedures to apply to them. To build a house, grow a tomato, or repair an engine, first you think about the object and its purpose and behavior. Then you select your tools and procedures. The solution fits the problem.
Thus the world is object-oriented, and the object-oriented programming methodology expresses computer programs in ways that model how people perceive the world. Because programmers are people, it is only natural that their approach to the work of the world reflects their view of the world itself.
The object-oriented methodology is built on the foundation laid by the structured programming concepts and data abstraction. Data abstraction does for data what functional abstraction does for operations. With data abstraction, data structures can be used without having to be concerned about the exact details of implementation. For example, floating-point numbers are abstracted in programming languages. You are not required to know how a floating-point number is represented in binary while assigning a value to it. Likewise, you are not bothered how binary multiplication takes place while multiplying floating-point numbers. Abstraction for floating-point numbers has existed in programming languages since long. However, it is only recently that languages have been developed that let you define your own abstract data types.
The fundamental change in OOP is that a program is designed around the data being operated upon, rather than around the operations themselves. This is to be expected once we appreciate that the very purpose of the program is to access or manipulate data. The basic idea behind object-oriented language is to combine into a single unit, both, the data and the functions that operate on the data. Such a unit is called an object.
An object's functions, called member functions or methods in C++, typically provide the only way to access its data. If you want to access a data item in an object, you call a member function in the object. It will read the item and return the value to you. You can't access the data directly.
If you want to modify the data in an object, you know exactly which functions interact with it—the member functions in the object. No other functions can access the data. This simplifies writing, debugging, and maintaining the program.
A C++ program typically consists of a number of objects which communicate with each other by calling one another's member functions. The organization of a C++ program is shown in Figure 1-2.
Figure 1-2. Object-oriented programming.
When you approach a programming problem in an object-oriented manner, you no longer ask how the problem will be divided into functions, but rather how it will be divided into objects. Thinking in terms of objects, rather than functions, has a surprisingly helpful effect on how easily programs can be designed. This results from the close match bet...

Inhaltsverzeichnis