Search This Blog

Friday, 14 February 2014

defining the member functions outside the class in c++


//defining member functions outside any class in c++

/*
  As we know that class contains both data members and member functions .
  both data and member functions can be defined outside the class also by using scope resolution operator.
*/


#include<iostream.h>
#include<conio.h>

class MyProgram
{
   int a,b,c;

   public:
         void input();
         void output();
};

void MyProgram::input()
         {
            cout<<"Enter the integer values for the variables:";
            cin>>a>>b>>c;
         }

void MyProgram:: output()
         {
            float avg;
            int sum;
            sum=a+b+c;
            avg=sum/3;
            cout<<"sum of entered no is:"<<sum<<endl;
            cout<<"Average is:"<<avg;
         }
void main()
{
   MyProgram mp;
   mp.input();
   mp.output();
   getch();
}

Output

Enter the integer values for the variables:4  4  6
sum of entered no is:14
Average is:6.0000

No comments:

Popular Posts