BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan

BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan (http://bzupages.com/index.php)
-   Object Oriented Programming (http://bzupages.com/forumdisplay.php?f=35)
-   -   Overloaded Operator == and / (equal & divide) Using C++ (http://bzupages.com/showthread.php?t=1121)

BSIT07-01 31-10-2008 01:12 AM

Overloaded Operator == and / (equal & divide) Using C++
 
You're not allowed to copy it.
Just take the concept...

Code:

#include
using namespace std;

class dis
{
private:
int ft;
int in;



public:
    dis()
    {
    ft=0;
    in=0;
    }

    dis(int feet, int inc)
    {
    ft=feet;
    in=inc;
    }

   
    void display();

    bool operator==(dis obj2);

    int parsetoinchs();

    dis operator / (dis obj2);
   


};

void main()
{

dis obj1(4,4);
dis obj2(2,3);
dis obj3;

if(obj1==obj2)

cout<<"Both OBJECTS are equal";

else
cout<<"Both OBJECTS are not Equal";

cout<
obj3=obj1/obj2;

obj3.display();


}



void dis::display()
    {
        cout<<"Feet : "<         cout<<"Inches : "<     }



dis dis:: operator / (dis obj2)
    {
   
        int var1,var2;
        var1=parsetoinchs();
        var2=obj2.parsetoinchs();
   
        obj2.ft=var1/var2;
        obj2.in=var1%var2;
       
        if(obj2.in>=12)
        {
        obj2.ft+=obj2.in/12;
        obj2.in=obj2.in%12;
        }
       
       
        return obj2;
   
    }


bool dis:: operator==(dis obj2)
    {
        if(ft==obj2.ft && in==obj2.in)
       
            return true;
        else
            return false;


    }


int dis::parsetoinchs()
    {
   
        int inchs=in;
       
        inchs+=ft*12;

        return inchs;

    }



All times are GMT +5. The time now is 01:43 PM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.