Welcome To Uday Satya Blog

41-50 PROGRAMS



/*****************************************************************
   41. Using inline function to perform all arithmetic operations
*******************************************************************/

#include
#include
inline int add(int a,int b)
 {
  return(a+b);
 }
inline int sub(int a,int b)
 {
  return(a-b);
 }
inline int mul(int a,int b)
 {
  return(a*b);
 }
inline float div(float x,float y)
 {
  return(x/y);
 }

void main()
{
 clrscr();
 int a,b;
 float x,y;
 cout<<"\n Enter Any Two Integer Values :"<
 cin>>a>>b;
 cout<<"\n Enter Any Two Floating Points Values :"<
 cin>>x>>y;

 cout<<"\n\n The Addition Of Two Integers Is = "<
 cout<<"\n\n The Subtraction Of Two Integers Is = "<
 cout<<"\n\n The Multiplication Of Two Integers Is = "<
 cout<<"\n\n The Division Of Two Floating Points Is = "<
 getch();
}

OUTPUT:-

 Enter Any Two Integer Values :
 8 9
 Enter Any Two Floating Points Values :
 5.36 6.9

 The Addition Of Two Integers Is = 17

 The Subtraction Of Two Integers Is = -1

 The Multiplication Of Two Integers Is = 72

 The Division Of Two Floating Points Is = 0.776812
























/******************************************************************
     42. Program to print date using scope resolution operator
*******************************************************************/

#include
#include
 class date
  {
   private :
     int d,m,y;
   public :
     void getdate();
     void putdate();
   };
 void date :: getdate()
  {
   cin>>d>>m>>y;
  }
 void date :: putdate()
  {
   cout<<" "<
  }
void main()
{
 date d[100];
 clrscr();
 int i,n;
 cout<<"\n Enter The Number Of Dates You Want To Be Printed : "<
 cin>>n;
   for(i=0;i
   {
    cout<<"\n Enter The "<
    d[i].getdate();
   }
    for(i=0;i
    {
     cout<<"\n The "<
     d[i].putdate();
     cout<
    }
   getch();
  }

OUTPUT:-

 Enter The Number Of Dates You Want To Be Printed :
 3
 Enter The 1 Date :
 06
 11
 1991
 Enter The 2 Date :
 24
 10
 1994
 Enter The 3 Date :
 26
 12
 1947

 The 1 Date Is :
 06/ 11/ 1991
 The 2 Date Is :
 24/ 10/ 1994
 The 3 Date Is :
 26/ 10/ 1991











/*****************************************************************
   43. Program to print date, defining function inside the class
******************************************************************/
#include
#include
 class date
  {
   private :
     int d,m,y;
   public :
    void getdate()
   {
    cin>>d>>m>>y;
   }
    void putdate()
  {
   cout<<" "<
  }
  };
void main()
 {
  date d;
  clrscr();
  cout<<"\n Enter The Date :"<
  d.getdate();
  cout<<"\n The Entered Date Is :"<
  d.putdate();
  getch();
 }

OUTPUT:-
 Enter The Date :
 06
 11
 1991
 The Entered Date Is :
 06/11 /1991


/*****************************************************
        44. Program to enter and display ‘n’ objects
******************************************************/

#include
#include
 class date
  {
   private :
     int d,m,y;
   public :
    void getdate()
   {
    cin>>d>>m>>y;
   }
    void putdate()
  {
   cout<<" "<
  }
  };
void main()
 {
  date d[100];
  clrscr();
  int i,n;
  cout<<"\n Enter The Number Of Dates You Want To Be Printed :"<
  cin>>n;

   for(i=0;i
   {
    cout<<"\n Enter The "<
    d[i].getdate();
   }
    for(i=0;i
    {
     cout<<"\n The "<
     d[i].putdate();
    }
   getch();
  }

OUTPUT:-

 Enter The Number Of Dates You Want To Be Printed :
 2
 Enter The 1 Date :
 25
 12
 2010
 Enter The 2 Date :
 10
 11
 2009

 The 1 Date Is :
 25/ 12/ 2010
 The 2 Date Is :
 10/ 11/ 2009



















/*****************************************************************
    45. To print date passing constants as parameters to function
******************************************************************/

#include
#include
class date
            {
            int d,m,y;
            public :
                        void getdate(int a,int b,int c)
                        {
                        d = a;
                        m = b;
                        y = c;
                        }
                        void putdate()
                        {
                        cout<
                        }
            };



void main()
            {
            clrscr();
            date d;
            d.getdate(15,8,1947);
            cout<<"Date Entered is : "<
            d.putdate();
            getch();
            }






/*****************************************************************
    46. To print date passing variables as parameters to function
******************************************************************/
#include
#include
class date
            {
            int d,m,y;
            public :
                        void getdate(int a,int b,int c)
                        {
                        d = a;
                        m = b;
                        y = c;
                        }
                        void putdate()
                        {
                        cout<
                        }
            };



void main()
            {
            clrscr();
            date d;
            cout<<"Enter Date Month and Year"<
            int a,b,c;
            cin>>a>>b>>c;
            d.getdate(a,b,c);
            cout<<"Date Entered is : "<
            d.putdate();
            getch();
            }




/*************************************************************
 47.To find greater of 2 numbers by nesting member function
**************************************************************/
#include
#include
class large{
  int a,b;
public:
            void input();
            int great();
            void display();
};
void large::input(){
  cout<<"enter a and b values";
  cin>>a>>b;
}
void large::display(){
  cout<<"greatest number is "<
}
int large::great(){
  if(a>b)
  return a;
  else
  return b;
}
void main(){
  large l;
  clrscr();
  l.input();
  l.display();
  getch();
}

OUTPUT :
enter a and b values
3 4

greatest number is 4

/******************************************************************
48.Perform all arithmetic operations by nesting member function
********************************************************************/
#include
#include

class calc
            {
            float a,b;
            public :
                        void getdata()
                        {
                        cin>>a>>b;
                        }
                        float add()
                        {
                                    return(a+b);
                        }
                        float sub()
                        {
                                    return(a-b);
                        }
                        float mul()
                        {
                                    return(a*b);
                        }
                        float div()
                        {
                                    return(a/b);
                        }
                        void putdata()
                        {
                        cout<<"SUM of Two Numbers is : "<
                        cout<<"DIFF of Two Numbers is : "<
                        cout<<"PRODUCT of Two Numbers is : "<
                        cout<<"Division of Two Numbers is : "<
                        }
            };



void main()
            {
            clrscr();
            calc c;
            cout<<"Enter any two Numbers : "<
            c.getdata();
            c.putdata();
            getch();
            }




OUTPUT

Enter any two Numbers :
17  2
                                                                               
SUM of Two Numbers is : 19
DIFF of Two Numbers is : 15
PRODUCT of Two Numbers is :  34
Division of Two Numbers is : 8.5                                                                         
                                                                               
                                                                               
                                                                                
                                                                               
                                                                               
                                                                               
                                                                                
                                                                               
                                                                               
                                                                                
                                                                               
                                                                               
                                                                                
                                                                               
                                                                               /*******************************************************
     49. Program to implement static data member
********************************************************/
#include
#include
class item
{
private:
            static int count;
            int number;
public:
            void getdata(int a)
            {
            number=a;
            count++;
            }
            void getcount()
            {
            cout<<"count";
            cout<
            }};
int item::count;
void main()
{
  item a,b,c;
  clrscr();
  a.getcount();
  b.getcount();
  c.getcount();
  a.getdata(100);
  b.getdata(200);
  c.getdata(300);
  cout<<"after reading data"<
  a.getcount();
  b.getcount();
  c.getcount();
  getch();
}


OUTPUT :

count0
count0
count0

after reading
count3
count3
count3



























/*************************************************************
       50.program to implement static member functions
**************************************************************/
#include
#include
class test
{
  int code;
  static int count;
public:
            void setcode()
            {
              code=++count;
            }
            void showcode()
            {
              cout<<"object no."<
            }
            static void showcount()
            {
              cout<
            }
};
int test::count;
void main()
{
  test t1,t2;
  clrscr();
  t1.setcode();
  t2.setcode();
  test::showcount();
  test t3;
  t3.setcode();
  test::showcount();
  t1.showcode();
  t2.showcode();
  t3.showcode();
  getch();
}


OUTPUT :

2
3

object no.1
object no.2
object no.3




0 comments:

Post a Comment