Search This Blog

Friday, August 14, 2020

Differences between C and C++ | Basic difference between c and c++ | codes with abhi

Mr. abhijeet dwivedi

                  C++ Programming:- 

In this tutorial you will learn:-

 Differences between C and C++:

 

 


       C                     C++

C does no support polymorphism, encapsulation, and inheritance which suggests that C doesn't support object oriented programming

C++ supports polymorphism, encapsulation, and inheritance because it's an object oriented programing language

C may be a subset of C++

C++ may be a superset of C.

C contains 32 keywords

C++ contains 52 keywords.

For the event of code, C supports procedural programming

C++ is understood as hybrid language because C++ supports both procedural and object oriented programming paradigms.

Data and functions are separated in C because it's a procedural programing language

Data and functions are encapsulated together in sort of an object in C++.

C doesn't support information hiding

Data is hidden by the Encapsulation to make sure that data structures and operators are used as intended

C may be a function driven language because C may be a procedural programing language

 

C++ is an object driven language because it's an object oriented programming.

Function and operator overloading isn't supported in C

 

Function and operator overloading  supported in C++

C may be a function-driven language

\

C++ is an object-driven language

Namespace features aren't present inside the C

Namespace is employed by C++, which avoid name collisions.

Header file employed by C is stdio.h

 

Header file employed by C++ is iostream.h.

Reference variables aren't supported by C

 

Reference variables are supported by C++.

Virtual and friend functions aren't supported by C

Virtual and friend functions are supported by C++.

C doesn't support inheritance

C++ supports inheritance.

 C provides malloc() and calloc() functions for dynamic memory allocation, and free() for memory de-allocation

  C++ provides new operator for memory allocation and delete operator for memory de-allocation.

C was developed by Dennis Ritchie between the year 1969 and 1973 at AT&T Bell Labs 

C++ was developed by Bjarne Stroustrup in 1979.

 

For Example


C-Variable declaration

Only at the top:

int i;

for(i=10; i<10;i++)

 

 

C++ variable declaration

Anywhere in the program;

for(i=1;i<10;i++)

 


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.