Programalama > C++

Etiketler: kesir, karsilastirmasi

Ort. 0
Puan ver:
//Class Bölümü fractions.h

#ifndef FRACTIONS_H
#define FRACTIONS_H

class fractions
{

public:
fractions(int,int);
bool operator<( fractions &);//
bool operator>( fractions &);//
bool operator<=( fractions &);//
bool operator>=( fractions &);
bool operator==( fractions &);//
bool operator!=( fractions &);//

fractions &operator+( fractions &);
fractions &operator-( fractions &);
fractions &operator*( fractions &);
fractions &operator/( fractions &);
//void print();




private:
int pay;
int payda;




};



#endif




//Fonksiyonların tanımlanması


#include<iostream>
using namespace std;

#include"fractions.h"

fractions::fractions(int a,int b)
{
pay=a;
payda=b;
}

fractions &fractions::operator+( fractions &object)
{

pay=((pay*object.payda)+(object.pay*payda));
payda=payda*object.payda;
return *this;
}

fractions &fractions::operator -(fractions &object)
{
pay=((pay*object.payda)-(object.pay*payda));
payda=payda*object.payda;
return *this;
}

fractions &fractions::operator *(fractions &object)
{
pay=pay*object.pay;
payda=payda*object.payda;
return *this;
}
fractions &fractions::operator /(fractions &a)
{
pay=pay*a.payda;
payda=payda*a.payda;
return *this;
}

bool fractions::operator <(fractions &a)
{
if(pay*a.payda<payda*a.pay)
return true;
else
return false;
}

bool fractions::operator >(fractions &a)
{
if(pay*a.payda>payda*a.pay)
return true;
else
return false;
}

bool fractions::operator !=(fractions &a)
{

if(pay/payda!=a.pay/a.payda)
return true;
else
return false;
}

bool fractions::operator <=(fractions &a)
{
if(pay/payda<=a.pay/a.payda)
return true;
else
return false;
}


bool fractions::operator ==(fractions &a)
{
double b,c;
b=pay/payda;
c=a.pay/a.payda;
if(b==c)
return true;
else
return false;
}

bool fractions::operator >=(fractions &a)
{
if(pay/payda>=a.pay*a.payda)
return true;
else
return false;
}






//Main kısmı


#include<iostream>
using namespace std;
#include"fractions.h"

int main()
{
fractions a(1,4),b(3,4);

cout<<"a = 1/4    b = 3/4  "<<endl;
if(a<b)
cout<<"a<b"<<endl;
if (a>b)
cout<<"a>b"<<endl;
if(a<=b)
cout<<"a<=b"<<endl;
if(a>=b)
cout<<"a>=b"<<endl;
if(a==b)
cout<<"a=b"<<endl;
if(a!=b)
cout<<"a!=b"<<endl;






return 0;
}


Yorumlar                 Yorum Yaz
Bu hazır kod'a ilk yorumu siz yapın!
KATEGORİLER
ASP - 240
ASP.NET - 24
C# - 75
C++ - 174
CGI - 8
DELPHI - 247
FLASH - 49
HTML - 536
PASCAL - 246
PERL - 11
PHP - 160
WML - 9
XML - 2
Copyright © 2002 - 2024 Hazır Kod - Tüm Hakları Saklıdır.
Siteden yararlanırken gizlilik ilkelerini okumanızı tavsiye ederiz.
hazirkod.com bir İSOBİL projesidir.