Object Oriented Programming: C++

Advertisement:


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
{
  String name[];
  int age;
}s1;

To access members of structure:

s1.name[];
s1.age;

Video Tutorial: Basics of C++



YouTube Link: http://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.


Related posts:







Get FREE blog updates to your email inbox. Enter your email ID and subscribe:


Do not forget to click the verification link in your email, after subscribing.
--Thanks for your support

Start Making Money From Your Programming Skills


( Free ebook )
ebook cover
  • Subscribe to Technotip.com blog update and you will be able to download "Tips, Tricks and Strategies to Make Money Online" eBook for free.
  • You will also receive tips to improve your programming skills, and strategies to make money from your programming skills. We will also send useful resources for learning and building your application.
  • You can also make money with us, by just recommending our website to your friends and family. You will get complete strategy for making $300 and more in the ebook that we will send you - once you subscribe to our free blog update using the below form..

Leave a Reply