Git Product home page Git Product logo

rational-numbers's Introduction

rational-numbers

How to use

Class of rationals numbers. Stores numbers in the format 2/3.

Creation:

rational a(2, 3); rational a = {2, 3}; rational a; 

Arithmetic operations

You can add, subtract, multiply and divide two rational numbers. For example:

rational a(2, 3);
rational b(2, 3);
rational c = a + b;
rational d = a - b;
rational e = a * b;
rational f = a / b;

Also you can use this operator:

rational a(2, 3);
rational b(2, 3);
a += b

You can compare two rational numbers. For example:

rational a(2, 3);
rational b(2, 3);
if (a == b) { ... }
if (a != b) { ... }
if (a >= b) { ... }
if (a < b) { ... }

You can check true or false rational. For example:

rational a(0, 1);
bool c = a ? true : false; // c == false
if (!a) { ... }
rational a(2, 3)
bool c = a ? true : false; // c = true
if (a) { ... } 

You can use input and output for rational numbers. For example:

rational a;
cin >> a;
cout << a;

You can use rational in vector, map, tuple, set. For example:

vector<rational> a = {{2, 1}, {3, 4}};
set<rational> a = {{2, 1}, {3, 4}};

tuple<rational, rational, rational> a = make_tuple(rationa(2, 1), rational(3, 4), rational(5, 4));

map<rational, int> a; 
rational r= {2, 1};
map[r] = 1;

Tests

Main.cpp by default run tests. The file test.cpp contains tests.


rational-numbers's People

Contributors

chukak avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.