Thursday, April 28, 2011

OBJECT ORIENTED C++ CODE (INHERITANCE)

GUYS HERE IS THE CODE OF INHERINTANCE OF PARENT AND CHILD CLASSES..
THIS CODE IS WRITTEN BY (SIKANDAR HAYAT HUNZAI) FOR HELPING STUDENTS..


CODED BY (SIKANDAR HAYAT)
THIS CODE IS TESTED IN VISUAL BASIC 2010

#include<iostream>

using namespace std;
////////////////////////////////////////////////////////////////////distance class//////////////////////////////////////////

class Distance
{
protected:
    int feet;
    float inches;

public:


Distance()
{
    feet=inches=0;

}

Distance (int f,float i)
{
    feet=f;
    inches=i;
}

int  getfeet()
{
    return feet;
}

float getinches( )
{
    return inches;
}




};
//////////////////////////////////////////////////////////////////// Child class

class signedDistance :public Distance
{

private:

    char sign;


public:

    signedDistance()
       
    {
        sign ='+';
    }

  signedDistance (int b)
    {

        sign=b;
    }

 signedDistance(int f,float i,char ch)

    {
       
        feet=f;
        inches=i;
        sign =ch;
       
    }

    void setsign(char ch)
    {
     sign =ch;
}
    void setfeet(int f)
     {
         feet=f;
     }

     void setinches(float i)
     {
         inches=i;
     }

    char getsign()
{
    return sign;
}


int  getfeet()
{
    return feet;
}

float getinches( )
{
    return inches;
}

};
//////////////////////////////////////////////////////MAIN/////////////////////////////////////////////////
    int main()
    {

       
        signedDistance D(10,6,'+');

        cout<<D.getsign()<<"/"<<D.getfeet()<<"/"<<D.getinches()<<endl;

     


    }




No comments:

Post a Comment