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

HOME BZU Mail Box Online Games Radio and TV Cricket All Albums
Go Back   BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan > Institute of Computing > Bachelor of Science in Information Technology > BsIT 3rd Semester > Object Oriented Programming

Object Oriented Programming By Mam Sidra Malik


Reply
 
Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
  #1  
Old 31-10-2008, 01:12 AM
BSIT07-01's Avatar
Addicted to Computer


 
Join Date: Sep 2007
Location: ------------
Age: 34
Posts: 1,309
Contact Number: ---------------
Program / Discipline: BSIT
Class Roll Number: 07-01
BSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant future
Default Overloaded Operator == and / (equal & divide) Using C++

You're not allowed to copy it.
Just take the concept...

Code:
#include <iostream>
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<<endl;

obj3=obj1/obj2;

obj3.display();


}



void dis::display()
    {
        cout<<"Feet : "<<ft<<endl;
        cout<<"Inches : "<<in<<endl;
    }



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;

    }

Reply With Quote
Reply

Tags
divide, equal, operator, overloaded


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
The C++ Modulus Operator bonfire Introduction to Computing 0 26-02-2011 11:15 PM
1 by n sinx is equal to .BZU. Funny Cut Piece 0 05-11-2010 03:59 PM
Happy Employees Equal More Productivity .BZU. Articles 0 21-06-2010 05:41 AM
when you are overloaded by your boss usman_latif_ch Funniest Pictures 0 12-06-2010 11:09 AM
Operator of the Year..!!! usman_latif_ch BZU Graphics and Wallpapers 0 30-03-2010 07:16 PM

Best view in Firefox
Almuslimeen.info | BZU Multan | Dedicated server hosting
Note: All trademarks and copyrights held by respective owners. We will take action against any copyright violation if it is proved to us.

All times are GMT +5. The time now is 12:13 PM.
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.