C - Observation
C - Observation
NO: 01
                                       STACK OPERATIONS
      DATE:
AIM:
                To create a class, to implement the data structure STACK with a constructor to
initialize the top of stack and create a member function PUSH ( ) and POP( ) to insert &delete
ALGORITHM:
     Step 4 : Create PUSH ( ) and POP ( ) function to insert and delete the element & also
check the overview conditions.
Step 6 : Create an object in the main() program to invoke all the member functions.
                                                  1
                            /*STACK OPERATIONS*/
#include<iostream.h>
#include<conio.h>
#include<process.h> int
top;
class STACK
{ int
a[10];
public:
STACK()
    {
       top=0;
     }
   void display();
void push(int ele)
{         top=top+
1;
a[top]=ele;
     }
   void pop()
     {       int
ele;
ele=a[top];
top=top-1;
        cout<<"\n The current top element is"<<ele<<"is deleted";
      }
 };
 void STACK::display()
     {        cout<<"\n";
for(int i=top; i>0; i--)
cout<<a[i]<<"\n";
      }
void main()
{     clrscr
();
   int ch,e;
   STACK obj;
   do
{ clrscr();
                                                2
cout<<"\n\t\t
STACK
OPERATION
S"; cout<<"\n\
t\t
************
*******";
cout<<"\n
MENU";
        cout<<"\n --------"; cout<<"\n
        1)PUSH"; cout<<"\n 2)POP";
        cout<<"\n 3)DISPLAY";
        cout<<"\n 4)EXIT"; cout<<"\n
        Enter your choice: ";
        cin>>ch;
        switch(ch)
         {
            case 1: if(top>=7)
                    cout<<"\n Stack is full";
                    else
                      {
                         cout<<"\n Enter the element:";
                         cin>>e;
               obj.push(e);
                       }
               break;
            case 2: if(top<0)
                    cout<<"\n Stack is empty";
                    else
               obj.pop();
                    break;
            case 3: if(top<=0)
                    cout<<"\n The stack is empty";
               else
                      {
                          cout<<"\n\t Stack items are: \n\t";
                          obj.display();
                       } break;
            case 4: cout<<"\n Program is terminated";
          }
getch();
                                                    3
     }
  while(ch!=4);
getch();
}
OUTPUT:
                                 STACK OPERATIONS
                                 *******************
MENU
---------
1) PUSH
2) POP
3) DISPLAY
4) EXIT
Program is terminated.
                                              4
EX.NO: 02                              ARITHMETIC OPERATIONS
DATE:
 AIM:
              To create class ARITH, which consists of float & integer variable and create the
function ADD(), SUB(), MUL() and DIV() to get and display values.
ALGORITHM:
Step 2 : Create the class ARITH with float & integer variables.
Step 3 : Using member function getdata(), get of integer & float values.
Step 4 : Create member function ADD() to carryout addition of integer & float values.
Step 5 : Create member function SUB() to carryout subtraction of integer & float values.
     Step 6 : Create member function MUL() to carryout multiplication of integer & float
     values.
Step 7 : Create member function DIV() to carryout division of integer & float values.
     Step 8 : Create member function putdata() to call respective functions and display the
    result.
     Step 9 : In the main program, create an object for the class using object with dot operator
    invoke all the above member function.
                                                   5
                        /*ARITHMETIC OPERATIONS*/
#include<iostream.h>
#include<conio.h>
#include<math.h>
 class ARITH
  {
public : void
       getdata(void); float
       add(int, float); float
       sub(int, float); float
       mul(int, float); float
       div(int, float);
   };
float ARITH::add(int a, float b)
  {
         float y=a+b;
         return(y);
   }
float ARITH::sub(int a, float b)
  { float y = a-b;
         return(y);
   }
float ARITH::mul(int a, float b)
  { float y = a*b;
         return(y);
   }
float ARITH::div(int a, f loat b)
   { float y = a/b;
        return(y);
     }
void main()
    { int a;
       float
       b;
       ARITH A;
clrscr();
cout<<"\n\t\t\t\t ARITHMETIC OPERATIONS";
                                       6
     cout<<"\n\t\t\t\t *************************";
     cout<<"\n Enter the integer & float values: \n";
     cin>>a>>b; cout<<”\n\t\t Arithmeticoperations”;
     cout<<”\n\t\t ******************”;
     cout<<"\n
     ======================================="; cout<<"\
     n ADDITION = "<<A.add(a,b)<<"\n";
     cout<<"\n SUBTRACTION = "<<A.sub(a,b)<<"\n";
     cout<<"\n          MULTIPLICATION = "<<A.mul(a,b)<<"\n";
     cout<<"\n DIVISION = "<<A.div(a,b)<<"\n";
     cout<<"\n =======================================";
     getch();
 }
OUTPUT:
                     ARITHMETIC OPERATIONS
                      **************************
                                        7
 Enter the integer & float values:
10 2.5
                                     Arithmetic operations
                                     *****************
===========================================
ADDITION = 12.5
SUBTRACTION = 7.5
MULTIPLICATION = 25
DIVISION = 4
===========================================
EX.NO: 03
                                            8
     DATE:                   SUM OF INDIVIDUAL DIGITS
AIM:
           To create a program to read an integer number and find sum of all individual digits
ALGORITHM:
     Step 5 : Use inline functions rem() & que() to find quotient & reminder of the given
values.
     Step 6 : Create member function digit() to find sum of all individual digit..
                                                 9
#include<iostream.h>
#include<conio.h> inline
long int rem(long int b)
    { return(b%10);
    } inline long int que(long
int c)
    { return(c/10);
    } class
add
{ public: long int
       a,sum;
       clrscr(); add()
        {
           cout<<"\n\t\t SUM OF INDIVIDUAL DIGITS"; cout<<"\
            n\t\t **************************"; cout<<"\n
            CONSTRUCTOR INVOKED";
           cout<<"\n -------------------------------------";
           a=0; sum=0;
           cout<<"\n \t A="<<a<<"\t SUM="<<sum;
       }          void
getdata()
        { cout<<"\n Enter the
          digits:";
             cin>>a;
       }
void digit()
        {
              long int t;
       sum=0;
       while(a>0)
          { t=rem(
          a);
          a=que(a);
          sum=sum
          +t;
          if(a<=0)
            { if(sum>=10
              )
                { a=sum;
                   sum=0;
                                          10
                   }
               }
         }          cout<<"\n Sum of the individual digits for given number
is:"<<sum; }
    ~add()
    {
           cout<<"\n\n DESTRUCTOR INVOKED";
           cout<<"\n \n -----------------------------------";
           cout<<"\n\t A="<<a<<"\t SUM="<<sum;
           getch();
     }
}; void
main()
{ clrscr(); add a1;
       a1.getdata();
       a1.digit();
       getch();
  }
OUTPUT:
       CONSTRUCTOR INVOKED
       -------------------------------------
                             A=0      SUM=0
                                                11
       Enter the digits                                    : 987
       DESTRUCTOR INVOKED
       ----------------------------------
A=0 SUM=6
     EX.NO: 04
                                     FLOAT OBJECT OPERATOR
     DATE:
                                         OVERLOADING
AIM:
           To create a class FLOAT that contains one float data member & overload all the four
ALGORITHM:
                                               12
     Step 1   : Start the process.
Step 4 : Create an overload operator function (+) to add the float values.
Step 5 : Create an overload operator function (-) to subtract the float values.
Step 6 : Create an overload operator function (*) to multiply the float values.
Step 7 : Create an overload operator function (/) to divide the float values.
Step 9 : With the help the object invoke the overload functions and display the result.
                                                13
   float operator/(FLOAT f2);
 };
float FLOAT::operator+(FLOAT f2)
{ float t;
        t=f+f2.f;
        return(t);
}
float FLOAT::operator-(FLOAT f2)
{ float t; t=f-
        f2.f;
        return(t);
}
float FLOAT::operator*(FLOAT f2)
{ float t;
        t=f*f2.f;
        return(t);
}
float FLOAT::operator/(FLOAT f2)
{ float t;
        t=f/f2.f;
        return(t
        );
} void
main()
{
    FLOAT f1,f2;
    float f;
    clrscr();
    cout<<"\n\t\t FLOAT OBJECT OPERATOR OVERLOADING"; cout<<"\n\t\t
    *****************************************";
    cout<<"\n Enter the float value for object-1:"; f1.getdata();
    cout<<"\n Enter the float value for object-2:"; f2.getdata();
    cout<<"\n\t\t OUTPUT FOR FLOAT OBJECT OPERATOR OVERLOADING"; cout<<"\n\
    t\t ================================================";
    cout<<"\n\t\t --------------------------------------------------------";
    f=f1+f2;
    cout<<"\n\t\t Sum of two objects f=f1-                   :"<<f<<endl;
    f2;
    cout<<"\n\t\t Difference of two objects                  :"<<f<<endl;
    f=f1*f2;
    cout<<"\n \t\tProduct of two objects                     :"<<f<<endl;
                                     14
    f=f1/f2;
    cout<<"\n\t\t Division of two objects                    :"<<f<<endl;
    cout<<"\n \t\t-------------------------------------------------------";
    getch();
}
OUTPUT:
                    ---------------------------------------------------------------------------------
                            Sum of two objects                         : 11.2
                                                        15
                         Difference of two objects                   : 5.8
      EX.NO: 05
                                          STRING FUNCTIONS
      DATE:
AIM:
               To create a class STRING and write member function to get and display strings.
overload the operator (+) to concatenate two string and overload the operator (==) to compare
two strings.
ALGORITHM:
Step 3 : Create member function getdata(), to get the values for two strings.
                                                      16
     Step 4    : In the class using member function operator “+” to concatenate two strings.
Step 5 : In the class using member function operator “==” to compare two strings.
      Step 7   : Create an object in the main program to involve all the above member
functions.
                              /*STRING FUNCTIONS*/
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<process.h> class
STRING
   { char a[50],b[50],c[100];
      public:
      void getdata()
      { cout<<"\n Enter the first string: ";
         cin>>a;
         cout<<"\n Enter the second string:";
         cin>>b;
      }
      void operator+(STRING&temp)
      {
         strcpy(temp.c,temp.a);
         strcat(temp.c,temp.b);
      }
      void operator==(STRING&temp)
      {
                                                17
           cout<<"\n\t STRING COMPARISION";
cout<<"\n\t **********************";
if(strcmp(temp.a,temp.b)!=0)
               { cout<<"\n Strings are not equal";
               }
            else
               { cout<<"\n Strings are Equal";
               }
        }
       void display()
          {
              cout<<"\n\t STRING CONCATENATION"; cout<<"\
              n\t *************************"; cout<<"\n First
              String                   = "<<a;
                                           18
                                                             : "<<strlen(a);
                                                             : "<<strlen(b);
                                                             : "<<strlen(c);
           cout<<"\n Second String               = "<<b;
            cout<<"\n Concatenation of string    = "<<c;
         } void
      length()
         {
            cout<<"\n\t LENGTH OF THE STRINGS";
         cout<<"\n\t *************************";
         cout<<"\n Length of the first string
         cout<<"\n Length of the second string   cout<<"\n
         Length of the Concatenation of string }
 };
void main()
{ int
 ch;
   STRING s;
 con:
   clrscr();
   cout<<"\n\t\t\t STRING FUNCTIONS"; cout<<"\n\t\
 t\t *******************";
   cout<<"\n MENU";
 cout<<"\n ---------";
   cout<<"\n 1)STRING COMPARISION";
 cout<<"\n 2)STRING CONCATENATION";
   cout<<"\n 3)STRING LENGTH";
 cout<<"\n 4)EXIT";
   cout<<"\n Enter your choice:
 "; cin>>ch; switch(ch)
   { case 1 : s.getdata();
       s==s;      getch();
       goto con;
       case 2 : s.getdata();
            s+s;
                s.display();
       getch();
       goto con;
                                            20
                                            19
      case 3 : s.getdata();
                s+s;
                s.length();
       getch();
                goto con;
      case 4 : cout<<"\n\n Program is terminated";
      getch(); }
    while(ch!
    =4);
    getch();
}
                                             21
OUTPUT:
                                     STRING FUNCTIONS
                                      *******************
MENU
---------
1)STRING COMPARISION
2)STRING CONCATENATION
3) STRING LENGTH
4) EXIT
        STRING COMPARISION
        ***********************
                     Strings are not Equal
        STRING CONCATENATION
        **************************
              First String                              = RAJA
              Second String                             = RAJAN
               Concatenation of string                  = RAJARAJAN
Program is terminated.
                                                   22
     EX.NO: 06
                                    EMPLOYEE DETAILS
     DATE:
AIM:
      To create a class EMPLOYEE having employee details and also another class pay from
above class and calculate DA, HRA, and PF depending upon the grade.
ALGORITHM:
CODING:
#include<iostream.h>
#include<conio.h> #include<iomanip.h>
class EMPLOYEE
                                               23
{     protected
:        int
eno,i;
       char ename[20],dept[20],grade;
float hra,pf,bs,da,net,gross;
public:         void getdata()
      {
         clrscr();
         cout<<"\n EMPLOYEE DETAILS:";
cout<<"\n ==================";
         cout<<"\n ENTER THE EMPLOYEE NUMBER:";
cin>>eno;
         cout<<"\n ENTER THE EMPLOYEE NAME:";
         cin>>ename;
         cout<<"\n ENTER THE EMPLOYEE DEPARTMENT:";
cin>>dept;
         cout<<"\n ENTER THE BASIC SALARY:";
         cin>>bs;
         cout<<"\n ENTER THE GRADE (A/B/C/D/E):";
         cin>>grade;
      }
};
class pay : public EMPLOYEE
{     publi
c:
    void get(void)
    {
        if(grade=='A')
{           hra=bs*0.5;
da=bs*50/100;
pf=bs*0.1;
      }
      else if(grade=='B')
{            hra=bs*0.4;
da=bs*30/100;
pf=bs*0.1;
       }
   else if(grade=='C')
{       hra=bs*0.3;
                                     24
da=bs*20/100;
pf=bs*0.1;
   }
   else if(grade=='D')
{         hra=bs*0.2;
da=bs*10/100;
pf=bs*0.1;
    }
   else if(grade=='E')
{         hra=bs*0.
1;         da=0;
pf=0;
     } } void
sal(void)
{     gross=hra+da+
bs;     net=gross-pf;
}
void putdata(void)
{     clrscr
();
    cout<<"\n\t EMPLOYEE DETAILS";
    cout<<"\n\t ==================";
    cout<<"\n\t EMPLOYEE NUMBER                                :"<<eno<<endl;
cout<<"\n\t EMPLOYEE NAME                    :"<<ename<<endl;         cout<<"\n\t
DEPARATMENT                         :"<<dept<<endl;          cout<<"\n\t GRADE
                           :"<<grade<<endl;          cout<<"\n\t BASIC
SALARY                     :"<<bs<<endl; cout<<"\n\t HOUSE RENT
ALLOWANCE                  :"<<hra<<endl; cout<<"\n\t DEARNES
ALLOWANCE :"<<da<<endl;                   cout<<"\n\t PROVIDENT FUND
:"<<pf<<endl;
    cout<<"\n\t GROSS SALARY                          :"<<gross<<endl;
    cout<<"\n\t -------------------------------------------------------------";
    cout<<"\n\t NET SALARY                                     :"<<net<<endl;
    cout<<"\n\t
-------------------------------------------------------------"; }
};
                                                     25
void main() {
clrscr();
pay p[10];
int i,n;
    clrscr();
     cout<<"\n\t EMPLOYEE DETAILS";     cout<<"\n\t
==================";        cout<<"\n ENTER THE
NUMBER OF EMPLOYEES:";                     cin>>n;
for(i=0;i<=(n-1);i++)
     {
         p[i].getdata();
      }
    for(i=0;i<=(n-1);i++)
{         p[i].get();
p[i].sal();
p[i].putdata();
getch();
     }
}
                                        26
OUTPUT:
                          EMPLOYEE DETAILS
=================
EMPLOYEE DETAILS
=================
ENTER THE EMPLOYEE NUMBER              : 2012
EMPLOYEE DETAILS
==================
     EMPLOYEE DETAILS
==================
    EMPLOYEE NUMBER           : 2012
GRADE :A
------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
  EMPLOYEE NUMBER                        : 2013
DEPARATMENT : ACCOUNTS
GRADE :B
------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
  EX.NO: 07
                                        VIRTUAL FUNCTION
  DATE:
                                                    28
AIM:
                To create a class SHAPE which consists of two virtual functions & derive three
classes square, rectangle, triangle from class SHAPE and calculate Area and Perimeter.
ALGORITHM:
      Step 2       : Create a class SHAPE which consists of two virtual functions call_area() &
call_peri() .
     Step 3        : Create a sub-class square from class shape to calculate area & perimeter of
square.
      Step 4      : Create a sub-class rectangle from class shape to calculate area & perimeter
of                     rectangle. .
      Step 5      : Create a sub-class triangle from class shape to calculate area & perimeter
of                     triangle. .
      Step 6      : Using member function area & perimeter of each classes.
      Step 7 : In the main program using pointer and an objects invoke all the above member
function and display the result.
                                 /*VIRTUAL FUNCTION*/
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<process.h> class
SHAPE
  { protected:
     float
     a,b,c,l,h;
     public:
     virtual float call_area()
       { return(0.00);
                                                  29
       } virtual float
     call_peri()
       { return(0.00);
       }
   };
class square:public SHAPE
   { public:
     square()
       {
           cout<<"\n\t\t SQUARE OPERATIONS"; cout<<"\
           n\t\t --------------------------------"; cout<<"\n Enter
           the side of the square: ";
           cin>>a;
       } float
     call_area()
       { cout<<"\n Area = ";
           return(a*a);
       } float
     call_peri()
       { cout<<"\n Perimeter = ";
           return(4*a);
       }
   };
class rectangle:public SHAPE
   { public:
       rectangle()
         {
             cout<<"\n\t\t RECTANGLE OPERATIONS";
             cout<<"\n\t\t --------------------------------------";
            cout<<"\n Enter the length                       : ";
             cin>>l;
            cout<<"\n Enter the breadth                      : ";
             cin>>b;
         } float
       call_area()
         { cout<<"\n Area = ";
             return(l*b);
         } float
       call_peri()
         { cout<<"\n Perimeter = ";
             return(2*(l+b));
         }
                                                     30
  }; class triangle:public
SHAPE
  { public:
      triangle()
        {
           cout<<"\n\t\t TRIANGLE OPERATIONS"; cout<<"\
           n\t\t -----------------------------------"; cout<<"\n Enter
           the base                : ";
           cin>>l;
          cout<<"\n Enter the height                        : ";
           cin>>h;
           cout<<"\n Enter the three sides                  : ";
           cin>>a>>b>>c;
        }
      float call_area()
        { cout<<"\n Area = ";
           return(0.5*l*h);
        } float
      call_peri()
        { cout<<"\n Perimeter = ";
           return(a+b+c);
        }
  }; void
main()
  { int ch;
      SHAPE *s;
      do
        { clrscr();
           cout<<"\n\t\t DISPLAY SHAPES";
            cout<<"\n\t\t ****************";
            cout<<"\n\t MENU"; cout<<"\n\t
            --------";
           cout<<"\n 1)SQUARE";
            cout<<"\n 2)RECTANGLE" ;
            cout<<"\n 3)TRIANGLE" ;
            cout<<"\n 4)EXIT"; cout<<"\n
            Enter your choice:" ; cin>>ch;
            switch(ch)
                                                    31
          { case 1: square sq; s = &sq;
             cout<<s->call_area();
             cout<<s->call_peri(); break;
             case 2: rectangle rec; s =
                     &rec; cout<<s-
                     >call_area();
                     cout<<s->call_peri();
                     break;
             case 3: triangle tri; s=&tri;
                     cout<<s-
                     >call_area();
                     cout<<s->call_peri();
                     break;
             case 4: cout<<"\n Program is terminated";
            getch();
          }
      getch();
     } while(ch!
    =4); getch();
}
                                            32
OUTPUT:
                                           DISPLAY SHAPES
                                           ****************
MENU
--------
1) SQUARE
2) RECTANGLE
3) TRIANGLE
4) EXIT
            Area          = 4
           Perimeter      = 8
Area = 30
                                                  33
            Perimeter = 22
            Area          =    7.5
            Perimeter = 15
      EX.NO: 08
                                               FRIEND FUNCTION
      DATE:
AIM:
             To create two classes with a integer and float variable and create a friend functions to
display the integer and float values of both the classes separately.
ALGORITHM:
      Step 2      : Create a class shape and corresponding getdata() function to get integer and
                     Float value an input
      Step 3      : Create a class shape1 and corresponding getdata() function to get integer and
                     Float value an input
                                                       34
      Step 4 : Create a friend function shape common to both classes & display the integer
and float values of two classes separately by taking object of two classes as
argument. .
      Step 5 : In the main program create objects for both classes.
.
      Step 6 : Call the friend function with these objects as argument.
/*FRIEND FUNCTION*/
#include<iostream.h>
#include<conio.h>
#include<process.h>
class shape1; class
shape
   { protected:
          int a;   float
       b; public:
       void getdata();
          friend void shape2(shape,shape1);
   }; class
shape1
   { protected: int
       a1; float b1;
       public: void
       getdata();
          friend void shape2(shape,shape1);
   }; void
shape::getdata()
   { clrscr();
       cout<<"\n\t\t FRIEND FUNCTION"; cout<<"\n\t\t
       ******************";
                                             35
      cout<<"\n Enter the integer and float value for first class: ";
      cin>>a>>b;
   } void
shape1::getdata()
   { cout<<"\n Enter the integer and float value for second class: ";
      cin>>a1>>b1;
   }
                                                    36
OUTPUT:
                                       FRIEND FUNCTION
                                       ******************
Enter the integer and float value for first class : 3 8.5
Enter the integer and float value for second class : 9 1.4
---------------------------------------------------------------------------------------------
                                                         37
     EX.NO: 09
                                         SUM OF MATRIX
     DATE:
AIM:
           To create a program using function overloading to read two matrix of different data
types. Such as integer and float numbers and display the sum of two matrixes and also display
the sum of arrays individually.
ALGORITHM:
Step 3 : Create a member function read() to read the matrix of integer data type.
Step 4 : Create a member function get() to read the matrix of float data type.
     Step 5    :   Then create a member function sum(),to find the sum of two matrix and
                   display it.
Step 6 : And also find the sum of matrix individually and display it.
                                               38
                                /*SUM OF MATRIX*/
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
float r1=0; double
c1=0; class mat
   { int a[10][10],m,n,i,j;
       double b[3][3],c[3]
       [3]; public:
       void get(int r1,float c1)
         { m=r1;
            n=c1;
         } void
       read();
       void get();
       void sum();
   }; void
mat::read()
   { cout<<"\n\t\t Sum of matrix"; cout<<"\n\t\
       t ************"; cout<<"\n Enter the
       integer matrix A: \n"; for(i=0;i<m;i++)
       { for(j=0;j<n;j+
         +) cin>>a[i][j];
       }
   } void
mat::get()
   { cout<<"\n Enter the float matrix B: \n";
       for(i=0;i<m;i++)
         { for(j=0;j<n;j++)
            cin>>b[i][j];
         }
   } void
mat::sum()
   { for(i=0;i<m;i++)
         { for(j=0;j<n;j++)
                { c[i][j]=a[i][j]+b[i][j];
                   r1=r1+a[i][j];
                   c1=c1+b[i][j];
                }
                                                  39
       } cout<<"\n Sum of matrix A & B
     is: \n"; for(i=0;i<m;i++)
       { for(j=0;j<n;j++)
           cout<<c[i][j]<<"\t";
           cout<<"\n";
       } cout<<"\n Sum of matrix A is:
     "<<r1; cout<<"\n Sum of matrix B is:
     "<<c1;
  } void
main()
  { clrscr(); int r,c; mat m; cout<<"\n\t\t SUM OF
     MATRIX"; cout<<"\n\t\t ****************";
     cout<<"\n Enter the no.of rows and columns: ";
     cin>>r>>c; m.get(r,c);
     m.read();
     m.get();
     m.sum();
      getch();
  }
OUTPUT:
       SUM OF MATRIX ****************
                              1    5   9
                              7    5   3
                              2    4   6
                                             40
       Sum of matrix A & B is:
       Sum of matrix A is     : 42
       Sum of matrix B is     : 38.8
   EX.NO: 10
                                             PALINDROME
   DATE:
AIM:
          To check whether the given string is palindrome or not palindrome by using pointer.
ALGORITHM:
                                                42
OUTPUT:
PALINDROME **************
String is palindrome
                                              43
   EX.NO: 11
                        CONTENTS OF THE FILE WITH
   DATE:
                              LINE NUMBER
AIM:
       To check a file and display the contents of that file with line number.
ALGORITHM:
                                             44
         /*CONTENTS OF THE FILE WITH LINE NUMBER*/
#include<iostream.h>
#include<conio.h>
#include<fstream.h> void
main()
   { clrscr(); int n,i; char
      str[20]; ofstream
      out("data.dat");
      cout<<"\n\t\t CONTENTS OF THE FILE"; cout<<"\n\t\t
      ***********************";
      cout<<"\n";
      cout<<"\n Enter no.of strings : ";
      cin>>n; for(i=0;i<n;i++)
        { cout<<"\n Enter the strings: ";
           cin>>str; out<<str<<endl;
        } out.close(); ifstream in("data.dat"); cout<<"\n\t\t
      Contents of the file with line numbers";
      cout<<"\n\t\t -----------------------------------------------“; for(i=1;i<=n;i+
      +)
        { in>>str;
           cout<<"\n"<<i<<"."<<str<<endl;
        }
      in.close();
     getch();
   }
OUTPUT:
2) PENCIL
   EX.NO: 12
                                             MERGED FILES
   DATE:
AIM:
           To check a merged two file into a single file.
ALGORITHM:
   Step 2      :   Create two files “d1.dat” and “d2.dat” using input file stream.
                                                   46
      Step 3    :   Create file “d3.dat” using output stream for merge two files.
Step 4 : Enter the data for two files using get functions.
      Step 8    :   Check the merge file “d3.dat” by opening that file or by using command
                    prompt.
/*MERGED FILES*/
#include<iostream.h>
#include<conio.h>
#include<fstream.h> void
main()
   { clrscr(); char c; ifstream
      in1("d1.dat"); ifstream
      in2("d2.dat");
      ofstream
      out("d3.dat");
      while(in1.eof( )==0)
          { in1.get(c);
             out<<c;
                                                   47
          }
      while(in2.eof( )==0
      )
          { in2.get(c);
             out<<c;
          } in1.close( ); in2.close( );
      out.close( ); cout<<"\n Merged
      file: d3.dat";
     getch();
 }
OUTPUT:
Raja
C:\TC\BIN>Type d3.dat
                  Raja
                  Rajan
49