C++, operator overloading

You can only use standard c++ libraries. The key is to use fractions .

This assignment will be about numbers: your goal will be to

implement a class, number, which represents a real number with an

arbitrary number of digits (also known as an arbitrary precision

number). The class should have operators for addition, subtraction,

multiplication, division and comparisons, as well as unary minus.

Additionally, add power( int ) and sqrt( int ) as const

methods. The argument to power is the exponent. The argument of

sqrt gives the number of decimal digits that should be exact in

the result (see also below).

The constructor of number takes a single integer argument and

constructs an instance of number with the argument as its value

(this constructor should allow implicit conversions from int). A

default-constructed number should be 0.

As an example, all of the following should be valid code:

  number a( 10 ), b( 25 );

  number c = a + b;

  number d = c / a;

  number e = d * a;

  assert( e == a + b );

  assert( e != a );

  assert( c > a );

  assert( a < b );

  assert( c.power( 2 ) > c );

  c = number( 10 ).power( -5 );

  assert( c > c.power( 2 ) );

The decimal digits supplied to sqrt should be interpreted as

follows:

  number s = number( 145 ).sqrt( 3 ); /* 3 fractional digits */

  /* the exact result rounded to 3 fractional places is 12.042 */

  number lower = number( 120415 ) * number( 10 ).power( -4 );

  number upper = number( 120425 ) * number( 10 ).power( -4 );

  assert( s > lower );

  assert( s < upper );

Or in other words, if your result is (single) rounded to the given

number of decimal places, it must agree in all those decimal places

with a correctly rounded exact result.

Division by zero and square roots of negative numbers are undefined.

PS: A reference solution is about 250 lines of not very dense code.

#write essay #research paper #blog writing #article writing #academic writer #reflective paper #essay pro #types of essays #write my essay #reflective essay #paper writer #essay writing service #essay writer free #essay helper #write my paper #assignment writer #write my essay for me #write an essay for me #uk essay #thesis writer #dissertation writing services #writing a research paper #academic essay #dissertation help #easy essay #do my essay #paper writing service #buy essay #essay writing help #essay service #dissertation writing #online essay writer #write my paper for me #types of essay writing #essay writing website #write my essay for free #reflective report #type my essay #thesis writing services #write paper for me #research paper writing service #essay paper #professional essay writers #write my essay online #essay help online #write my research paper #dissertation writing help #websites that write papers for you for free #write my essay for me cheap #pay someone to write my paper #pay someone to write my research paper #Essaywriting #Academicwriting #Assignmenthelp #Nursingassignment #Nursinghomework #Psychologyassignment #Physicsassignment #Philosophyassignment #Religionassignment #History #Writing #writingtips #Students #universityassignment #onlinewriting #savvyessaywriters #onlineprowriters #assignmentcollection #excelsiorwriters #writinghub #study #exclusivewritings #myassignmentgeek #expertwriters #art #transcription #grammer #college #highschool #StudentsHelpingStudents #studentshirt #StudentShoe #StudentShoes #studentshoponline #studentshopping #studentshouse #StudentShoutout #studentshowcase2017 #StudentsHub #studentsieuczy #StudentsIn #studentsinberlin #studentsinbusiness #StudentsInDubai #studentsininternational