Search This Blog

Wednesday, August 12, 2020

Function Overloading in C++

Mr. abhijeet dwivedi

           C++ Programming:-

In this tutorial you will learn:-

Function Overloading in C++

Function overloading means two or more functions can have an equivalent name, but either the amount of arguments or the info sort of arguments has got to vary . within the first example, we create two functions of an equivalent name, one for adding two integers and another for adding two floats. within the second program, we make two functions with identical names but pass them a special number of arguments. Function overloading is additionally referred to as compile-time polymorphism.




We created two functions "add" for integer and float data types, you'll create any number of them of an equivalent name as needed . Just confirm a compiler are going to be ready to determine which one to call. In the program, you'll create add function for long, double, and other data types.


Function overloading C++ program

#include <iostream>

using namespace std;

/* Function arguments are of different data type */

int add(intint);
float add(floatfloat);

int main()
{
  int a, b, x;
  float c, d, y;

  cout << "Enter two integers\n";
  cin >> a >> b;

  x = add(a, b);

  cout << "Sum of integers: " << x << endl;

  cout << "Enter two floating point numbers\n";
  cin >> c >> d;

  y = add(c, d);

  cout << "Sum of floats: " << y << endl;

  return 0;
}

int add(int x, int y)
{
  int sum;

  sum = x + y;

  return sum;
}

float add(float x, float y)
{
  float sum;

  sum = x + y;

  return sum;
}


In the functions, the code is that the same but data types are different, C++ provides an answer to the present problem. We can create one function for various data types which can reduce the dimensions of code by employing a feature of C++ referred to as templates.


C++ program for function overloading

#include <iostream>

using namespace std;

/* Number of arguments are different */

void display(char []);  // print the string passed as argument
void display(char []char []);

int main()
{
   char first[] = "C programming";
   char second[] = "C++ programming";
   
   display(first);
   display(first, second);
   
   return 0;
}

void display(char s[])
{
   cout << s << endl;
}

void display(char s[]char t[])
{
   cout << s << endl << t << endl;
}

Output of program:

C programming
C programming
C++ programming

A function return type has no role because it returns a value when called and at compile time compiler will not be able to decide which one to call.




Polymorphism and Inheritance in C++

Mr. abhijeet dwivedi

          C++ Programming:-

 In this tutorial you will learn:-

Polymorphism

Polymorphism is that in which we can perform a task in multiple forms or ways. It is applied to the functions or methods. Polymorphism allows the thing to make a decision which sort of the function to implement at compile-time also as run-time.


Types of Polymorphism are:


1. Compile-time polymorphism (Method overloading)

2. Run-time polymorphism (Method Overriding)





Inheritance is the process of by which a replacement class is made that inherits the properties of the exist already class. It supports the concept of code reusability and reduces the length of the code in object-oriented programming.


Types of Inheritance are:


1. Single inheritance

2. Multi-level inheritance

3. Multiple inheritance

4. Hybrid inheritance

5. Hierarchical inheritance



Difference between Inheritance and Polymorphism:

S.NOInheritancePolymorphism
1.Inheritance is one in which a new class is created (derived class) that inherits the features from the already existing class(Base class).Whereas polymorphism is that which can be defined in multiple forms.


2.It is basically applied to classes.
Whereas it is basically applied to functions or methods.


3.Inheritance supports the concept of reusability and reduces code length in object-oriented programming.Polymorphism allows the object to decide which form of the function to implement at compile-time (overloading) as well as run-time (overriding).


4.Inheritance can be single, hybrid, multiple, hierarchical and multilevel inheritance.Whereas it can be compiled-time polymorphism (overload) as well as run-time polymorphism (overriding).

5.It is used in pattern designing.While it is also used in pattern designing.





Dynamic and Static Binding in C++

Mr. abhijeet dwivedi

                               C++ Programming:-

In this tutorial you will learn:-


 Dynamic binding

 

Dynamic  memory is the process of linking procedure call to a selected sequence of code (method) at run-time. It means the code to be executed for a selected procedure call isn't known until run-time. Dynamic binding is additionally referred to as late binding or run-time binding.


Dynamic binding is an object oriented programming concept and it's related with polymorphism and inheritance.


Dynamic binding definition

Dynamic binding(dispatch) means a block of code executed with regard to a procedure(method) call is decided at run time.

Dynamic dispatch is usually used when multiple classes contain different implementations of an equivalent method. It provides a mechanism for choosing the function to be executed from various function alternatives at the run-time. In C++, virtual functions are wont to implement dynamic binding

 


Definitions of Static Binding

When compiler acknowledges all the knowledge required to call a function or all the values of the variables during compile time, it's called “static binding“. As all the specified information are known before runtime, it increases the program efficiency, and it also enhances the speed of execution of a program.


Static Binding makes a program very efficient, but it declines the program flexibility, as ‘values of the variable’ and ‘function calling’ are predefined within the program. Static Binding is implemented during a program at the time of coding.


Overloading a function or an operator are the instance of compile-time polymorphism, i.e. static Binding.


Difference between Static and Dynamic Binding


BASIS FOR COMPARISONSTATIC BINDINGDYNAMIC BINDING
Event OccurrenceEvents occur at compile time are "Static Binding".
Events occur at run time are "Dynamic Binding".
InformationAll information needed to call a function is known at compile time.All information need to call a function come to know at run time.
AdvantageEfficiency.Flexibility.
TimeFast execution.Slow execution.
Alternate nameEarly Binding.Late Binding.
ExampleOverloaded function call, overloaded operators.Virtual function in C++, overridden methods in java 

Monday, August 10, 2020

Abstraction and Encapsulation in C++ |Difference between Abstraction and Encapsulation in C++

Mr. abhijeet dwivedi

                                      C++ Programming:-

Abstraction and Encapsulation both are basic object oriented programming (OOP) concepts which permit you to implement real-world objects into programs and codes. While both go hand in hand, they're very different from one another . In simple terms, once you put various things together to make an entity, you really create an idea – an abstract. While both are technically inseparable, they have got literally nothing in common. It’s almost true that each encapsulation is an abstraction because they both hide something, however, they need their justifiable share of differences




What is Abstraction?

Abstracting is a basic OOP concept which focuses on just the relevant data of an object and hides all the irrelevant details which may or may not be for generic or specialized behavior. It hides the background details and emphasizes on the essential points to scale back complexity and increase efficiency. Basically, abstraction may be a programming tool to manage complexity. Abstraction focuses on ideas rather than events. It hides the small print on the planning level by providing functionality to the users. The resulting object also can be called an abstraction. The programmer makes sure the named entity will have all the essential aspects included and none of the irrelevant ones.


Let’s take a real-world example of abstraction. Let’s consider the case of a vehicle, which in this case is your vehicle. A mechanic tries to repair your car or let’s say a specific part of your car. Here, you're the user and you don’t want to urge into the specifics of your car or what part actually broke. You don’t actually care about those things; you just want your vehicle back in its original condition without worrying about the details. So, you really told the mechanic what you would like by segregating the implementation part. This is abstraction. You focused on the foremost essential thing, which is getting your car fixed, instead of that specialize in the specifics.


Difference between Abstraction and Encapsulation


What is Encapsulation?

Encapsulation is yet another OOP concept which binds data and functions into a single component while restricting access to some components. It’s one among the most fundamental concepts of OOP which wraps data and knowledge under one unit. In technical terms, encapsulation means hiding attributes to shield variables from outside access so that change in one part of an application won’t affect the other parts. On the contrary, by making the knowledge more open you’ll risk misuse of knowledge . It provides basic integrity to the info by protecting it from the surface world. In simple terms, it hides the extra details from the outside world.


Let’s take an example of a Bluetooth mouse. You only got to realize the device’s behavior without fear about the implementation details like what quite sensors the mouse has, is it wireless or not, etc. Every single detail describes the mouse but regardless of the details, it’s just a mouse. You just need an interface to use the mouse, which in this case is the mouse pointer. This is encapsulation.


Difference between Abstraction and Encapsulation

While both are fundamental concepts related to OOP and they are technically inseparable, they still have their differences in many aspects.


Differences in “ Definition” of Abstraction and Encapsulation – Abstraction is a fundamental OOP concept which emphasizes on all the essential aspects of an object by hiding the irrelevant details to increase efficiency and eliminate complexity. Encapsulation, on the opposite hand, may be a data hiding mechanism which wraps the info and knowledge during a capsule to limit access from outside world.

Differences in “Functionality” of Abstraction and Encapsulation– Abstraction is a data hiding mechanism which highlights only the essential features to make complex programs simpler, while encapsulation, on the other hand, is a method of binding data and codes into one entity. The idea is to shield the implementation details from external access.

Differences in “Implementation” of Abstraction and Encapsulation – Abstraction is implemented using abstract class and interface, while encapsulation is implemented using access modifiers. Five sorts of modifiers are wont to encapsulate data: Private, Public, Internal, Protected, and guarded Internal.

Differences in “Concept” of Abstraction and Encapsulation– The idea behind abstraction is to focus on what rather than how. Encapsulation hides the internal mechanics of how. For example, once you drive a car, you recognize exactly what the pedal does but you'll not know the entire mechanism behind it because the info is encapsulated.

Differences in “Example” of Abstraction and Encapsulation – Let’s take an example of a smartphone. You know what it does but you may not know how it does what it does. You only care about the monitor and keypad buttons instead of worrying about its inner circuitry. Here, smartphone is an abstract where the inner implementation details are encapsulated.

 

 

Features of object oriented programming c++

Mr. abhijeet dwivedi

                                   C++ Programming

Features of C++

 C++ is an upgraded version of C programming. the most idea behind creating C++ programming was to feature object orientation to the C programing language . the main upgradations are object-oriented programming methodology, namespace feature, operator overloading, error & exception handling. The motivation behind object-oriented programming is to undertake to ascertain the entire world within the sort of classes & objects.





C++ is an upgraded version of C programming. the most idea behind creating C++ programming was to feature object orientation to the C programing language . the main upgradations are object-oriented programming methodology, namespace feature, operator overloading, error & exception handling. The motivation behind object-oriented programming is to undertake to ascertain the entire world within the sort of classes & objects. 


There are various features of C++ like ,


Object Oriented

Simple

Platform Dependent

Mid-level programing language 

Structured programing language 

Rich Library

Memory Management

Powerful & Fast 

Pointers

Compiler based

Syntax based language

            

Let’s discuss all of them one by one.


Object Oriented programing language 

The main upgradation from C to C++ is object-oriented programming. It follows concept of oops like polymorphism, inheritance, encapsulation, abstraction. This makes development and maintenance easier. 


Let’s briefly understand the concepts of object-oriented programming.


Class: a category may be a user-defined blueprint or prototype from which objects are created. It represents the set of properties or methods that are common to all or any objects of 1 type.


Object: it's a basic unit of Object-Oriented Programming and represents the real-life entities. A C++ program creates many objects which interact by invoking methods.


Polymorphism: Polymorphism refers to the power of OOPs programming languages to differentiate between entities with an equivalent name efficiently.


Inheritance: Inheritance is that the mechanism during which one class is allowed to inherit the features (fields and methods) of another class.


Encapsulation: Encapsulation is defined because the wrapping from data under one unit. it's the mechanism that binds together code and therefore the data it manipulates.


Abstraction: Data Abstraction is that the property by virtue of which only the essential details are showed the user. The trivial or the non-essentials units aren't showed the user.


Features of C++ : Simple


C++ provides a structured approach wherein you'll break the matter into parts and style the answer modularly. It provides you an upscale set of library functions that you simply can use while implementing the answer .

If you've got worked with C language, then moving to C++ would be a really smooth transitioning. The syntax is nearly similar with minute changes. 


Platform Dependent 


Platform dependent language means the language during which programs are often executed only thereon OS where it's developed & compiled. It cannot run or execute it on the other OS . 


C++ may be a platform-dependent language. Having said that, C++ programs are often executed in many machines with bit or no change.


Mid-level programing language 


C++ has the power to try to to both low-level & high-level programming. this is often the rationale why C++ is understood as a mid-level programing language . once we mention low-level programming, C++ is employed to develop system applications like the kernel, driver, etc. 


Structured programing language 


In C++ programming, the code is modular with the assistance of functions, classes & objects, and therefore the modules are loosely coupled. Modular code is straightforward to know & modify. This makes C++ a structured programing language . 


Rich Library

Developers have access to a lot of in-built functions provided by C++ language. this protects time & makes development fast. Let’s check out a number of the C++ header files & functionalities provided by it.


: Contains C++ standard input and output functions


: Contains stream manipulators that format streams of knowledge 


: Contains math library functions


: Contains function for conversions of numbers to text and vise versa, memory allocation, random numbers and various other utility functions. 


: Contains function for manipulating the time and date


: Contains function for functions that perform input from files on disk and output to files on disk


: Contains classes and functions employed by the C++ Standard Library to allocate memory to the C++ Standard Library containers


: Contains classes for accessing data within the C++ Standard Library containers



: Contains functions for manipulating data in C++ Standard Library containers


Memory Management


C++ supports dynamic memory allocation. you'll free the allocated memory at any time. Not only this C++ also provides dynamic memory management techniques. 


Powerful & Fast


C++ may be a fast language as compilation and execution time is a smaller amount . Also, it's a good sort of data types, functions & operators.


Pointers


Pointers are variables that store the address of another variable. Pointer points to the memory location of a variable. C++ supports pointer and provides solutions to a lot of problems that demand access to memory location.


Compiler based


C++ may be a compiler-based programing language . Without compilation, no C++ program are often executed. The compiler first compiles the C++ program then it's executed.


C++ Features: Syntax based language

C++ may be a language that complies strongly with syntax. Language following rules and regulations very strictly is understood as tight syntax-based language. C, C++, Java, .net are a number of the examples. 


Now I hope you'd have understood different features provided by C++. I hope this blog is informative and added value to you.


Thus we've come to an end of this text on ‘Features of C++’. If you would like to find out more, inspect the Java Training by Edureka, a trusted online learning company. Edureka’s Java J2EE and SOA training and certification course is meant to coach you for both core and advanced Java concepts along side various Java frameworks like Hibernate & Spring.


Got an issue for us? Please mention it within the comments section of this blog “C++ features” and that we will revisit to you as soon as possible.

 

 

 

Thursday, July 2, 2020

Object and Class in c++

Mr. abhijeet dwivedi
Object and Class in C++

In this tutorial you will learn

Object(Instance of classes):-

It is a piece of code which represent the real life entity and this is created in runtime.
* It combine data & function.
* Object also give a life to class.
* Object can be manipulated.
* Object occupy the memory location.
* It is also instance of classes.

For example:-


In the above figure, you can see a car so car have a some attributes like color, speed, model,etc and functionality like get speed, get fuel, etc.
Then the all attributes and functionally of car is OBJECT.
And, Car is class.

Class:-

Collection of similar object(Homogeneous) is called class.
* Class is also a user define function.
* Class can not be manipulated cause it is not available memory except static class.
* Class does not occupy memory location.

Syntax of class

Class class name
{
Private:    ------------------Hide data
variable declaration;
function;
Public:     ---------------------- Private data
function and variable;
};



Differentiate between Object and Class:-

               OBJECT

       CLASS

                                                   

 1.

Object is an instance of class

Class is a collection of similar object.

 2.

Object gives life to the class

The class can be generate by object.

 3.

Object occupy memory loaction

Class can not occupy memory location.

 4.

Object can be manipulated.

Class can not be manipulated cause it is not available memory except static class



Sunday, June 21, 2020

Introduction and features of c++

Mr. abhijeet dwivedi
                   C++ Programming
In this tutorial you will learn:-

     Introduction of c++

Bjarne stroustrup
The programming language is developed by Bjarne Stroustrup in 1979 at AT & T (new jersey).
1. C++ is a high level programming language
2. C++ is object oriented programming language.
3. C++ is a superset of C programming language. We apply all concept of C in C++ programming languages.
4. C++ is develop by the combination of two programming language first is Simula 67 and second one is C.
Features of C++
1. Object:- Object is primary entity and this is created in runtime, it combines data and function.
2. Classes:- Classes is a collection of similar object (homogeneous object) and it is also a user define datatype.
3. Abstraction:- An abstraction is used for hiding of data.
4. Inheritance:- Inheritance is a process by which one object can acquire the properties of another object.
5. Encapsulation:-
Encapsulation is a process of wrapping of data and function together.
6. Overloading:- The concept of overloading p provised extensibility this means that we can extend the existing features.
7. polymorphism:- The word polymorphism means having many forms. Typically, polymorphism occurs when there is a hierarchy of classes and they are related by inheritance.
8. Dynamic Binding:- The dynamic binding is a process of connecting one program to another program.
Uses of C++:-
1. Games:- With the help of C++ it is very easy to develop a game because C++ provide all resources for gaming type software.

2. GUI based application:- GUI based application is also developed with the help of C++ programming language. For example:- Adobe system.

3. Database software:- C++ is also used for develop database software.

4. Operating system:- C++ is also used for develop operating system. There are some famous operating system  which is written in c++. For example- Apple OS, Microsoft, etc.

5. Browser:- This language C++ is also used for develop browser software. for example:- fire fox, and some google application.
6. Banking application:- C++ is also used for develop banking application.

7. Compilers:- C++ programming language is also used for developing compilers and most of the compilers are written in C++.

8. Enterprise software:- C++ is also used in many enterprise software.




Sunday, May 24, 2020

Tokens and Data type in Python Programming

Mr. abhijeet dwivedi

Python Programming:

In this tutorial, you will learn:-

      Token:

 


 

 

The smallest individual unit in a program is known as token in python.

There are 5 types of token available in python programming:-

1. Identifiers:-

An identifier is a name used to identify a variable, function, modules, or another object, etc.

Rules:-

* Identifiers can be a combination of letters  in lowercase(a to z) and uppercase(A to Z) or digit(0  to 9) or an underscore(_)
* Identifiers can't be stored with digit.
* Keywords can't be used as an identifier.
* Special symbol like : !, @, #, $, %,etc are use as identifiers.
* Identifier can be of any length.

2. Keyword:-

Keyword is a reserved words that have a special meaning in python programming
 * Keywords can't be used as identifiers.
* Python 3.7 has 33 keywords.
* All keywords except true, false, & name are the lower case and they must be written at it is.3.

 3. Operator:-

Operator are sign which is used to generate an expression or to perform any calculation. Python uses a nonalphanumeric character and character combination as an operator.
please visit our operator post to get more information, python operator.
For example:-   x+y=c;    ----- Airthmatic operator.

4. Delimiters:

Delimiters are the symbols and symbols combinations used in expression like list, dictionaries, string, etc.
For Example:-  {, }, [, ], :, =, +=,>>,etc

5. literals:-

A literals is a numbers or string that appears in a programming.
For example:-   
42  ---  Integer type   (literals)
29.8 ---- float 
"codeswithabhi"  -----string
12+i     --- complex

 Data type:-

  

1. None:

In this data type not any value stored means null value carries none data type.

2. Numeric:

* Integer:

In integer we have to take all values in integer data type.
For e.g:  >> abhi=10   ---int value
if we wanna confirm our data type so, you can use this function to check to check type of data type:
>> type(a)
<class'int'>

* Float:-

In this type of data type, we have to take all values in floating values (Decimal values).
For eample:      >>c=10.34  ---- Float value
If we wnna check type of data type that we takes type function :
>>Type(c)
<class'float'>

* Complex:

The complex data type holds the comples data type.
For exmple:   a=100+3k
print("type of data type",a  type(a))
<class'comple'>

* Boolean:

The boolen check the condition of two variables and also comparing two values.
For example:
>>a=10
>>b=100
>>a>b
>> False

3.  List :

In python we can create and also store data, and this data may be in integer, flaot, string, also combination of all 3 types of data type:
For Example:  >>abc[1,2,3]
        type (abc)
   <class'list'>
We discuss list in brief in our next post..

4. Tuple :

It is colllection of objects enclosed within ( ).
For example: >> a= (9,1,2)
          >>type(a)
      >> <class'tuple'>

There are some charactrstics of tuple:

* Hetrogeneous :
* Immutable :
 * Duplicate
We will discuss more in detail in our next upcomming post...

5. Set :

A set is an un oredered collection of items, Every set element is unique (no duplicates)p and cannot be changed.
For example:    >> A=(1,2,4,1,7,2)
>>print(A)
>>1,2,4,7    ----- here repeating number is avoid by set
And if we wanna check type of set:
>>Type(A)
>> <class'set'>
We discuss this topic in detail in our next upcomming post.

6. String :

The group of character is know as string. In pytho we can eaisly access string rather than another various programming language.
For example:
>> S="codeswithabhi"
Print(S)
codeswithabhi
And we can also check it by using type function
>>type(S)
<class' string'>

Learn complete Complete course





7. Range:

In other programming language we use loops and give condition to access a particular condition which is given by programmer, similary range gives a also a path, condition, and printing range.
For example:
>>Range(1,10) 
 So, in this condition interpreter print only 1 to 9.

8. Dictionary:-

Dictinary in python is an un ordered collection of data values , used to store data values like a map, for every values assign a key.
For example: 
>>d={'abhi':'codes','hello':'abhi'}
>>d.key
>>dict.key(['abhi':'codes'])  -- so here we print key
d values 
dict.values(['hello':'abhi')    ---here we print values.


Thanks for reading....

If you any doubt related this topic please drop your question in comment box.

Saturday, May 23, 2020

Python Variables - Codes With Abhi

Mr. abhijeet dwivedi

Python Programming:-

In this tutorial, you will learn:-

Variables:-

 

  In Python, a variable is considered as a tag that is tied to some value. In other words, variables are a type of container which holds some value. A variable name can be in alphanumeric type but not start with a number. For e.g: name1=100
Python considered variables as an object


 .

Variable assignment:

In python programming language there no need to declare or defined in advance as a case of another programming language.
Let, create a variable and assign value.
>>n=100
>>print(n)
>>100
so very easy you can assign any value in a variable and print it using print() function which is already stored in python's library.

Multiple variable assignment:-

In other programming languages like c, c++,etc We need to declare and assign like this:
a=10;
b=10;
c=10;
 and then print, but in python,we can assign value in only one line like this:
>>a=b=c=10;
>>print(a)
>>print(b)
>>print(c)
>>10
>>10
>>10

 



For example, suppose we take,

>>a=10

      a ------Tag name

   10

   1002    ---------Address

>>Print(a)

10        ------- - output

type(a)   ---by type function we find the type of variable

<class' int'>    -------- type of datatype

id(a)     ---by this id function we can get the address of the value

1002     -------address

So, in python  "a" is a type of tag we can not say it variable in python it is just a tag that carries integer value.
As we know that in other programming languages a variable takes an address in memory, but in python the value takes an address.
And one more thing suppose if we take two types of the same value and try to take in a different variable like this :
>> a=10  
>> b=10
So, in this situation 10 already takes one address, and when the interpreter read b's value it cannot give another address to b's  10, it just combines both a and b into one tag which has a value 10.

Rules for variable declaration:-

1. Every variable should start with alphabet or underscore (_)
2. No space is allowed in variable declaration.
3. Except underscore (_) no other special symbol is allowed in the middle of the variable declaration
4. A variable is written with a combination of letter, number, & any special character

For example:- 

* a
* name 
* abhi12
* _city
* codewith_abhi
* Codeswithabhi
so this is some variable declarations



Python


Thanks for reading and if any doubt related to this topic ask your question below comment box.