Translate

Tuesday, 30 October 2012

Structure


 structure is a collection of heterogeneous types of data elements. here by heterogeneous we mean elements of different data types. i.e. int, float, char etc.


Syntax:
  struct name
       {
             dataType-1 var;
             dataType-2 var;
             ...............
        };

  it is also called User Defined Data Type. In other words using keyword struct we can create our own data types.

Monday, 29 October 2012

Functions


  Function is a named set of statements doing a particular job within the program. A program have many function and they can call to each other.

Types of functions:
1. library functions: functions defined in the language library are called library functions. eg. printf(),Scanf(),getch() etc.

2. user Defined Functions: functions defined by the users according to need are called user defined functions.

Sunday, 28 October 2012

decision making Statements:


    decision Making Statements are used to make a choice among a no. of options eg. to check weather the number is +ve or -ve, too find the division of Student ie. Ist, 2nd or Fail.

Types:

a) 
If condition only: It execute the statement if given condition evaluate true.

Syntax: 

  if(TRUE)
{
    Statements
}

b)
else-if: if condition evaluate is true then execute if block and if condition is false then execute else block. we can also say that it is used to make choice between 2 options only. eg. to check student is pass or fail.


Syntax: 

  if(TRUE)
{
    Statements;
}

else

{
    Statements;
}

  in this we not need to give any condition in else because else means it is opposite to the condition given in  if.

c)
Ladder If-else: Used to make choice among more than two options.
 if(condition)
{
   statement;
}
else if(condition)
{
   statement;
}

else if(condition)
{
   statement;
}
else
{
  statement;
}

d)
Nested If else: It is also used to make choice among more than 2 options. in this if-else statements are nested in if and else blocks.

Syntax:

if(condition)
     {

              if(TRUE)
                     {
                          Statements;
                      }

              else

                      {
                           Statements;
                       }

      }
else
     {

              if(TRUE)
                    {
                         Statements;
                     }

             else

                    {
                          Statements;
                    }

      }

program to check given number is positive or negative:


#include<iostream.h>
#include<conio.h>
void main()
{
   clrscr();
   int n;
   cout<<"Enter any number\n";
   cin>>n;
   if(n<0)
     {
          cout<<"Given number is negative";
      }
   else
      {
           cout<<"Given number is positive";
       }
getch();
}

Wednesday, 24 October 2012

Program for Concatenation of two strings

#include<iostream.h>
#include<conio.h>
#include<string.h>
class string
   {
     char st[20];
     public:
void input()
    {
cout<<"\nEnter the string=";
cin.getline(st,20);
    }
     string operator+(string s)
   {
     string temp;
     strcpy(temp.st,st);
     strcat(temp.st,s.st);
     return temp;
   }
     void output()
   {

     cout<<"\nThe string is="<<st;
   }
   };
void main()
      {
string s1,s2,s3;
clrscr();
s1.input();
s2.input();
s3=s1+s2;
s3.output();
getch();
      }

Thursday, 11 October 2012



\\Program for finding the given number is even or odd

#include<iostream.h>
#include<conio.h>
void main()

    {

      clrscr();
      int n;
      cout<<"Enter the number=";
      cin>>n;
      if(n%2==0)
cout<<"\n\nGiven number is even";
      else
cout<<"\n\nGiven number is Odd";
      getch();
    }

Saturday, 6 October 2012

Welcome to C/C++

#include<iostream.h>
#include<conio.h>
void main()
   {
         clrscr();     // clear the output screen
         cout<<"welcome to C/C++";  // print on screen
         getch();                                   // ask for enter any character
   }