Demo entry 6337385



Submitted by anonymous on Dec 09, 2016 at 08:30
Language: C++. Code size: 2.1 kB.

#ifndef CLASS_H
#define CLASS_H
#include <iostream>
#include <assert.h>
#include <string.h>
using namespace std;
class fraction
	fraction() :nu(0), de(1){};
	explicit fraction(int a) :nu(a), de(1){};

	fraction(int a, int b);
	fraction(const fraction & c);

	int getnu() const;
	int getde() const;

	// = 
	fraction operator=(int );

	// +
	fraction operator+(const fraction&);
	friend fraction operator+(const fraction&,const int);
	friend fraction operator+(int, const fraction&);

	// -
	fraction operator-();
	fraction operator-(const fraction&);
	friend fraction operator-(const fraction&, int);
	friend fraction operator-(int, const fraction&);

	// *
	fraction operator*(const fraction&);
	friend fraction operator*(const fraction&, int);
	friend fraction operator*(int, const fraction&);

	// /
	fraction operator/(const fraction&);
	friend fraction operator/(const fraction&, int);
	friend fraction operator/(int, const fraction&);

	fraction Reciprocal();

	//Logical Operations 
	// >
	int operator>(const fraction&);
	friend int operator>(const fraction&, int);
	friend int operator>(int, const fraction&);

	// >=
	int operator>=(const fraction&);
	friend int operator>=(const fraction&, int);
	friend int operator>=(int, const fraction&);

	// <
	int operator<(const fraction&);
	friend int operator<(const fraction&, int);
	friend int operator<(int, const fraction&);

	// <=
	int operator<=(const fraction&);
	friend int operator<=(const fraction&, int);
	friend int operator<=(int, const fraction&);

	// ==
	int operator==(const fraction&);
	friend int operator==(const fraction&, int);
	friend int operator==(int, const fraction&);

	// !=
	int operator!=(const fraction&);
	friend int operator!=(const fraction&, int);
	friend int operator!=(int, const fraction&);

	// << && >>
	friend ostream &operator<<(ostream &os, const  fraction  &c);
	friend istream &operator>>(istream &is, fraction  &c);

	int nu, de; //numerator & denominator
	void reduce();

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).