Wednesday, 2 January 2013

Introduction to basics of object oriented programming

Introduction to basics of object oriented programming

          Before learning Object Oriented Programming you should have some basics of c-language. Because here we are learning c++ which is a object oriented language so, which is developed from c language. You can also learn c++ without the knowledge of c-language but you can’t convert a problem in to programme without the knowledge of C.
          Let us begin your course by learning the basic input and output statements. The basic input statement in C language is “scanf”, in the same way the basic input statement in C++ is “cin”.
Ø The syntax for this input statement is    cin>>variable_name;
        In c++ we need not specify the format of the variable. We can directly specify the name of the variable. Care should be taken that we should add quotations to the variable name.
   For example we need to enter 5 into a variable named as var. then the input statement is as follows cin>>var; therefore during the compilation complier asks for input for the variable.
The basic output statement in c language is “printf”, in the same way the output statement in c++ is “cout”.
Ø The syntax for cout statement is cout<<”output statement”;
         Here we are two different situations for output statement has 1) the output statement is string 2) output statement is value stored in a variable. To illustrate this example, consider that we need display the value given by the user.
Ø Then the output statement is cout<<”given input values is”<<var;
 This explained as the string which is to be printed is given in the quotations and the variable which is containing this value is given without the quotations.  


#include<iostream.h>
#include<conio.h>
void main()
{
  clrscr();
  int var;
  cout<<"Enter the value in to the variable:";
  cin>>var;
  cout<<"Given input value is:"<<var;
  getch();
}




   
                         



No comments:

Post a Comment