-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
389 lines (364 loc) · 13.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="styles.css">
<title>Assignments</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css"
integrity="sha512-xh6O/CkQoPOWDdYTDqeRdPCVd1SpvCA9XXcUnZS2FmJNp1coAFzvtCN9BmamE+4aHK8yyUHUSCcJHgXloTyT2A=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
</head>
<body>
<nav class="navbar">
<div class="max-width">
<div class="logo"><a href="index.html"><img src="Photos\logoCPP.png" alt="iconcpp" width="60rem"></a></div>
<ul id="menu" class="menu">
<li><a href="#Intro" onclick="clicked()" class="menu-btn">What is C++</a></li>
<li><a href="#Object" onclick="clicked()" class="menu-btn">Objects and Classes</a></li>
<li><a href="#Inheritance" onclick="clicked()" class="menu-btn">Inheritance</a></li>
<li><a href="#Polymorphism" onclick="clicked()" class="menu-btn">Polymorphism</a></li>
<li><a href="#Abstraction" onclick="clicked()" class="menu-btn">Abstraction</a></li>
<li><a href="#Encapsulation" onclick="clicked()" class="menu-btn">Encapsulation</a></li>
</ul>
<div id="menu-btn" class="menu-btn">
<i class="fas fa-bars"></i>
</div>
</div>
</nav>
<div class="main-body">
<main id="main-doc">
<section class="main-section" id="Intro">
<header>
What is C++?
</header>
<p>
C++ is a general purpose programming
language and widely used now a days '
for competitive programming. It has
imperative, object-oriented and generic
programming features. C++ runs on lots of
platform like Windows, Linux, Unix, Mac etc.
C++ is an efficient
and powerful language and finds wide use
in various GUI platforms, 3D graphics and
real-time simulations. Because of the
inclusion of rich function libraries,
working in C++ becomes simpler and
convenient than C. Being object-oriented
programming like Java, C++ provides
the support of inheritance, polymorphism,
encapsulation, etc. Unlike C, C++ allows
exception handling and function overloading.
</p>
<p>he “Hello World” program is the first
step towards learning any programming
language and also one of the simplest
programs you will learn. All you have
to do is display the message “Hello World”
on the screen.
<br><br>Let us now look at the program :<br>
</p>
<code>
#include <iostream>
<br>
using namespace std;
<br>
int main()
<br>
{
<br>
cout <<"Hello World";
<br>
return 0;
<br>
}
</code>
<br>
<p>C++ is an Object Oriented Programming Language.
<br> The main pillars of Object Oriented
Programming are :
</p>
<ul>
<li>Objects and Classes</li>
<li>Inheritance</li>
<li>Polymorphism</li>
<li>Abstraction</li>
<li>Encapsulation</li>
</ul>
</section>
<section class="main-section" id="Object">
<header>
Objects and Classes
</header>
<p>
Object-oriented programming – As the name
suggests uses objects in programming.
Object-oriented programming aims to
implement real-world entities like
inheritance, hiding, polymorphism,
etc in programming. The main
aim of OOP is to bind together the data
and the functions that operate on them
so that no other part of the code can
access this data except that function.
</p>
<p><b>Object : </b>An Object is an identifiable
entity with some characteristics and behavior.
An Object is an instance of a Class. When a
class is defined, no memory is allocated but
when it is instantiated (i.e. an
object is created) memory is allocated.
<br>
<b>Class : </b>The building block of C++ that
leads to Object-Oriented programming is a Class.
It is a user-defined data type, which holds its
own data members and member functions, which can
be accessed & used by creating an instance
of that class. A class is like a blueprint for
an object. For Example: Consider the Class
of Cars. There may be many cars with different
names and brand but all of them will share
some common properties like all of them will
have 4 wheels, Speed Limit, Mileage range etc.
So here, Car is the class and wheels,
speed limits, mileage are their properties.
</p>
</section>
<section class="main-section" id="Inheritance">
<header>
Inheritance
</header>
<p>
The capability of a class to derive
properties and characteristics from
another class is called Inheritance.
Inheritance is one of the most important
feature of Object Oriented Programming.
Sub Class: The class that inherits
properties from another class
is called Sub class or Derived Class.
Super Class: The class whose properties
are inherited by sub class is called Base
Class or Super class. Using inheritance, we
have to write the functions only one time
instead of three times as we
have inherited rest of the three classes
from base class(Vehicle).
</p>
<p>
<b>Mode of Inheritance : </b><br><br>
<b>Public Mode : </b>If we derive a sub
class from a public base class. Then the
public member of the base class will
become public in the derived class and
protected members of the base class
will become protected in derived class.
<br><br>
<b>Protected Mode : </b>If we derive a
sub class from a Protected base class.
Then both public member and protected
members of the base class will become
protected in derived class.
<br><br>
<b>Private Mode : </b>If we derive a
sub class from a Private base class.
Then both public member and protected
members of the base class will become
Private in derived class.
<br><br>
<b>Types of Inheritance in C++ : </b>
<br><br><br>
<b>Single Inheritance :</b> In single
inheritance, a class is allowed to inherit
from only one class. i.e. one sub class
is inherited by one base class only.
<br><br>
<b>Multiple Inheritance :</b> Multiple
Inheritance is a feature of C++ where a
class can inherit from more than one
classes. i.e one sub class is inherited
from more than one base classes.
<br><br>
<b>Multilevel Inheritance :</b> In this
type of inheritance, a derived class is
created from another derived class.
<br><br>
<b>Hieratical Inheritance :</b> In this
type of inheritance, more than one sub
class is inherited from a single base
class i.e. more than one derived class
is created from a single base class.
<br><br>
<b>Hybrid (Virtual) Inheritance :</b>
Hybrid Inheritance is implemented by
combining more than one type of
inheritance.
For example: Combining Hierarchical
inheritance and Multiple Inheritance.
</p>
</section>
<section class="main-section" id="Polymorphism">
<header>
Polymorphism
</header>
<p>
The word polymorphism means having many
forms. In simple words, we can define
polymorphism as the ability of a message
to be displayed in more than one form.
A real-life example of polymorphism, a
person at the same time can have
different characteristics.
Like a man at the same time is a father,
a husband, an employee. So the same
person posses different behavior in
different situations. This is called
polymorphism. Polymorphism is considered
as one of the important features of Object
Oriented Programming.
<br>
<b>In C++ polymorphism is mainly
divided into two types:</b>
<br> 1. Compile time Polymorphism<br>
2. Runtime Polymorphism
</p>
<p>Compile time polymorphism: This type of
polymorphism is achieved by function
overloading or operator overloading.
<br> Runtime polymorphism: This type
of polymorphism is achieved by
Function Overriding.
</p>
</section>
<section class="main-section" id="Abstraction">
<header>
Abstraction
</header>
<p>
Data abstraction is one of the most
essential and important feature of object
oriented programming in C++. Abstraction
means displaying only essential information
and hiding the details. Data abstraction
refers to providing only essential information
about the data to the outside world,
hiding the background details or implementation.
<br> Consider a real life example of a man driving
a car. The man only knows that pressing the
accelerators will increase the speed of car
or applying brakes will stop the car but he
does not know about how on pressing accelerator
the speed is actually increasing, he does
not know about the inner mechanism of the car
or the implementation of accelerator, brakes
etc in the car. This is what abstraction is.
</p>
<p>
<b>Abstraction using Classes:</b> We can
implement Abstraction in C++ using classes.
Class helps us to group data members and member
functions using available access specifiers. A
Class can decide which data member will be
visible to outside
world and which is not.
<br>
<b>Abstraction in Header files:</b> One
more type of abstraction in C++ can be
header files. For example, consider the
pow() method present in math.h header file.
Whenever we need to calculate power of a
number, we simply call the
function pow() present in the math.h header
file and pass the numbers as arguments
without knowing the underlying algorithm
according to which the function is actually
calculating power of numbers.
<br><br><b>Advantages of Data Abstraction:
</b><br> 1. Helps the user to avoid writing
the low level code.<br> 2. Avoids code
duplication and increases reusability.<br>
3. Can change internal implementation of
class independently without
affecting the user.<br> 4. Helps to
increase security of an application or program
as only important details are
provided to the user.
</p>
</section>
<section class="main-section" id="Encapsulation">
<header>
Encapsulation
</header>
<p>
In normal terms Encapsulation is defined
as wrapping up of data and information
under a single unit. In Object Oriented
Programming, Encapsulation is defined as
binding together the data and the functions
that manipulates them. Consider
a real life example
of encapsulation, in a company there are
different sections like the accounts section,
finance section, sales section etc. The finance
section handles all the financial transactions
and keep records of all the data related to
finance.
Similarly the sales section handles all the
sales related activities and keep records of
all the sales. Now there may arise a situation
when for some reason an official from finance
section needs all the data about sales in a
particular
month. In this case, he is not allowed to
directly access the data of sales section.
He will first have to contact some other
officer in the sales section and then
request him to
give the particular data. This is what
encapsulation is. Here the data of
sales section and the
employees that can manipulate them are
wrapped under a single name “sales section”.
</p>
<p>
Encapsulation also lead to data abstraction
or hiding. As using encapsulation also hides
the data. In the above example the data of
any of the section like sales, finance or
accounts is hidden from any other section.<br>
In C++ encapsulation
can be implemented using Class
and access modifiers.
</p>
</section>
</main>
</div>
<darkmode>
<div class="mode">
<button onclick="darkMode()">Darkmode
<button onclick="lightMode()">LightMode</button></button>
<script>
function darkMode() {
var element = document.body;
var content = document.getElementById("DarkModetext");
element.className = "dark-mode";
content.innerText = "Dark Mode is ON";
}
function lightMode() {
var element = document.body;
var content = document.getElementById("DarkModetext");
element.className = "light-mode";
content.innerText = "Dark Mode is OFF";
}
</script>
</div><br><br>
</darkmode>
<!-- Copyright -->
<div class="footer">
<!-- <a class="right-btn" href="contactUs.html">Contact us</a> -->
<div>© 2022 Copyright:
<a class="a-link"> C++ Official Website</a></div></div>
<!-- Copyright -->
</body>
<script src="app.js"></script>
</html>