Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

PROGRAMMING IN C++ NOTES

Rating
-
Sold
-
Pages
23
Uploaded on
05-11-2024
Written in
2022/2023

Notes are very useful for C++ is a powerful, high-performance programming language that supports both procedural and object-oriented programming paradigms. It allows developers to create efficient, modular, and reusable code. Key features of C++ include classes, inheritance, polymorphism, and templates, which help in building complex applications. It also offers low-level memory manipulation with pointers, making it suitable for system-level programming. The Standard Template Library (STL) provides useful data structures and algorithms, improving productivity. C++ is commonly used in software development, game programming, real-time systems, and performance-critical applications due to its speed and flexibility.

Show more Read less
Institution
Course

Content preview

UNIT- I
Polymorphism
The term "Polymorphism" is the combination of "poly" + "morphs" which means many
forms. It is a greek word. In object-oriented programming, we use 3 main concepts:
inheritance, encapsulation, and polymorphism.

Real Life Example Of Polymorphism

Let's consider a real-life example of polymorphism. A lady behaves like a teacher in a
classroom, mother or daughter in a home and customer in a market. Here, a single
person is behaving differently according to the situations.




o Compile time polymorphism: The overloaded functions are invoked by
matching the type and number of arguments. This information is available at the
compile time and, therefore, compiler selects the appropriate function at the
compile time. It is achieved by function overloading and operator overloading
which is also known as static binding or early binding. Now, let's consider the
case where function name and prototype is same.
o Run time polymorphism: Run time polymorphism is achieved when the object's
method is invoked at the run time instead of compile time. It is achieved by
method overriding which is also known as dynamic binding or late binding.

,Differences b/w compile time and run time polymorphism.


Compile time polymorphism Run time polymorphism


The function to be invoked is known at the compile time. The function to be invoked is known at the
time.


It is also known as overloading, early binding and static It is also known as overriding, Dynamic bind
binding. and late binding.


Overloading is a compile time polymorphism where Overriding is a run time polymorphism wh
more than one method is having the same name but more than one method is having the same na
with the different number of parameters or the type of number of parameters and the type of
the parameters. parameters.


It is achieved by function overloading and operator It is achieved by virtual functions and pointers.
overloading.


It provides fast execution as it is known at the compile It provides slow execution as it is known at the
time. time.


It is less flexible as mainly all the things execute at the It is more flexible as all the things execute at
compile time. run time.



CONCEPT OF Function Overloading

Function Overloading is defined as the process of having two or more function with the
same name, but different in parameters is known as function overloading in C++. In
function overloading, the function is redefined by using either different types of
arguments or a different number of arguments. It is only through these differences
compiler can differentiate between the functions.

, The advantage of Function overloading is that it increases the readability of the
program because you don't need to use different names for the same action.

C++ Function Overloading Example
Let's see the simple example of function overloading where we are changing number of
arguments of add() method.

// program of function overloading when number of arguments vary.

1. #include <iostream>
2. using namespace std;
3. class Cal {
4. public:
5. static int add(int a,int b){
6. return a + b;
7. }
8. static int add(int a, int b, int c)
9. {
10. return a + b + c;
11. }
12. };
13. int main(void) {
14. Cal C; // class object declaration.
15. cout<<C.add(10, 20)<<endl;
16. cout<<C.add(12, 20, 23);
17. return 0;
18. }

Output:

30
55
C++ Operator Overloading
C++ has the ability to provide the operators with a special meaning for a data
type, this ability is known as operator overloading. Operator overloading is a
compile-time polymorphism. For example, we can overload an operator ‘+’ in a
class like String so that we can concatenate two strings by just using +. Other

Written for

Institution
Course

Document information

Uploaded on
November 5, 2024
Number of pages
23
Written in
2022/2023
Type
Class notes
Professor(s)
Sudarshan bhoi
Contains
Programing in c++

Subjects

$8.89
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
sudarshanbhoi

Get to know the seller

Seller avatar
sudarshanbhoi NYNC COLLEGE CHALISGOAN
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions