Demo entry 6335526



Submitted by anonymous on Dec 06, 2016 at 12:16
Language: C++. Code size: 1.8 kB.

#ifndef CLASS_H
#define CLASS_H
#include <iostream>
#include <assert.h>
#include <string.h>
using namespace std;
class fraction
	fraction(int a, int b);
	fraction(int a);
	fraction(const fraction & c);

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

	// = 
	fraction operator=(int );

	// +
	fraction operator+(const fraction&);
	//friend fraction operator+(const fraction&, 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>(int, const fraction&);

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

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

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

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

	// !=
	int operator!=(const fraction&);
	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.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).