Object Oriented Programming: C++

To understand and switch from C to C++, you need to know some of the basic similarities and differences between the two.

Sample C Program:

#include<stdio.h>

void main()
{
  printf("Welcome To C");
}

Here stdio.h header file is included inorder to make use of printf and scanf functions.

Sample Cpp Program:

#include<iostream.h>

void main()
{
  cout<<"Welcome To Cpp";
}

Here iostream.h header file is included inorder to make use of cout and cin objects.

cout is an object of class ostream.
cin is an object of class istream.

Both these ostream and istream classes are present inside iostream.h file.

In both C and C++, execution of the program starts from main() function.

The difference is, printf and scanf are functions; while cout and cin are objects.

<< is called Insertion Operator. To show result on output window.
>> is called Extraction Operator. To get input from the user(keyboard).

Structures In C:

struct Student
{
  char name[20];
  int age;
}s1;

To access members of structure:

s1.name;
s1.age;

Video Tutorial: Basics of C++



YouTube Link: https://www.youtube.com/watch?v=GuZFpc0diJ4 [Watch the Video In Full Screen.]



Class In Cpp:

#include<iostream.h>
#include<conio.h>

class Student
{
  int a, b, c;

  public:
  void read() { cin>>a>>b>>c; }
  void show() { cout<<"\nEntered Numbers are "<<a<<" , "<<b<<" , "<<c; }
};

int main()
{
  A a;
  clrscr();

  cout<<"\nEnter 3 nums\n";

  a.read();
  a.show();

  getch();
 
}

member functions are accessed with the help of objects.

object.member

This way data binding is done and a level of security is imparted to the data.

Binding of Data and method into a single unit is called ENCAPSULATION.