Anda di halaman 1dari 3

Object Oriented Programming

Implement a class BigInt to handle big integers more than what primitive integer data type can handle. The
BigInt class has the following properties:

1.
2.
3.
4.
5.

String Num: to store the number in it.


Define two variables, BigInt remainder , BigInt: quotient
Default constructor : BigInt ()
Constructor with parameters : BigInt(string s),
Copty constructor BigInt(const BigInt & bi),

6. Virtual Overloading of +operator to Add two BigInt Numbers:


virtual BigInt operator+ (const BigInt& arg);

7. Virtual Overloading of -operator to subtract two BigInt Numbers:


virtual BigInt operator-(const BigInt& arg);
8. Virtual Overloading of *operator to multiply two BigInt Numbers:
virtual BigInt operator* (const BigInt& arg);
9. Virtual Overloading of / operator to Divide two BigInt Numbers:
virtual BigInt operator/ (const BigInt& arg);
10. Virtual Overloading of == operator to compare two BigInt Numbers:
virtual bool operator ==(const BigInt& arg);
11. Virtual Overloading of << operator to print a BigInt :
virtual ostream& operator<< (ostream& os, const BigInt& arg)
12. Virtual Overloading of >> operator to read a BigInt :
virtual istream& operator>> (istream& os, const BigInt& arg);
Extend the BigInt class by BigComplex class and add the following properties
1. String iNum: to store the imaginary part of a complex number.
2. Default constructor : BigComplex ()
3. Constructor with parameters : BigComplex (string real, string imag),
4. Copty constructor BigComplex(const BigComplex & arg),
5. Overwrite functions from point 6 to 10 to perform (+,-,*,/) mathematical and comparison operations on two
BigComplex objects; you may define two variables numerator of type BigComplex and denominator of type
BigInt to store the return result of division operation.
6. Overwrite functions from point 11 to 12 to work on BigComplex class.
Write a main function that tests all functions in both BigInt and BigComplex classes. You can add any functions
and code to implement the requirements.

For testing
478637843647863473644374636666666666666666666678888888888888374364873483764346247324637463463463
746374643723888888888888888888888888888888888888888888887473777373737737377397238728932382738239
283823729893728888888888888888889999999999999333333333333330000000000000338237237278639872732732
68
+
837463476347836473647364736437437434737474346464664646438483483843887467347364734347367343777777
774343437474734773773477777777777777777773434737437374736366463438376374638943436373746637463746
73467346374634343434
=
478637843647863473644374636666666666666666666678888888888888374364873483764347084788113811299937
393739380161326323626363235353553535327372372732776356234838511721105081155175013072369857473013
057301507671506666666662323626327374736366462771709707972273436373746637801983971952103619076167
02
=================================================================
X=
834853478563475647534785645745467546785647856487564785648576478564756475647856456475647856478564
875647865467546756478564564785647865475646547576457846574574658475634754658475485457468576464546
547854687564756478564785647547563
Y=
984574857489754985734567847854578645786474774757474774747477474747477747747758586886696979797999
483838382828884884854857847887584845847585845485488887485794584574875894847584758945894785748958
9454854758475984758945487589484854787858485848548581
X-Y =
-98457485748975498565108249999823108103299621018292802006891268909872126918290093903022133223321
383819081804323702836729306134083017019972938900692410093822992981723011019012729309833131028311
13969397289899520212397632901920098309293700201001018
=======================================================================
478637843647863473644374636666666666666666666678888888888888374364873483764347084788113811299937
393739380161326323626363235353553535327372372732776356234838511721105081155175013072369857473013
057301507671506666666662323626327374736366462771709707972273436
*
478637843647863473644374636666666666666666666678888888888888374364873483764347084788113811299937
393739380161326323626363235353553535327372372732776356234838511721105081155175013072369857473013
0573015076715066666666623236263273747363664627717097
=
229094185371876600586988730838639396129844959057665380622502836814420902909611948819734064497003
594531743738974016362249163813696756714022580301674094891772453138317306201271869067417315557101
243879943891067034092029356394079787933119174808107152490645820608336449584660445531761026339646
362479528932331981743002587424297733157797176062500598027450951745115633075076647133468542967410
370181355033007670265539311690343064791416858453462332969490692631534049731987872705780247406050
5153902741736135292
===============================================================
856475647856436874637446845358746547564876347463487365777777777777777777777777777893458476547854
547687857845648756475475647577475684756746547854785685847564647857454658746578465847854674754875
478854754674545677777777777777485448348384478564745745674564754785475478547854785648758957485748
95478954

/
48754785467854657478546784564875764574564785457
Quotient =
175670068002070140439198356054298141685156710216477749426267573410814788141003695541891737258157
904017691083276013893655595601247849386275857984279818719100456478307995233724171601432074058736
9188197843524091592570620730425932404472933240241924429746
Remainder =
6305117842137298975600274754671050757336475032

Illustrations of Operations on complex numbers

To add and subtract complex numbers: Simply combine like terms. For example, (3 2i) (2 6i) = 3 2i 2 + 6i = 1 +

4i.

To multiply two complex numbers:


Example: (3 2i)*(9 + 4i) = 27 + 12i 18i 8i2, which is the same as 27 6i 8(1), or 35 6i.

To divide complex numbers: Multiply both the numerator and the denominator by the conjugate of the denominator and

then combine like terms.


For example, say you're asked to divide

The complex conjugate of 3 4i is 3 + 4i. Follow these steps to finish the problem:

1.

Multiply the numerator and the denominator by the conjugate.

Numerator: (1 + 2i)(3 + 4i) = 3 + 4i + 6i + 8i2, which simplifies to (3 8) + (4i + 6i), or 5 + 10i.


Denominator (3 4i)(3 + 4i) = 9 + 12i 12i 16i2 =25 , Because i2 = 1 and 12i 12i = 0,

2.

Rewrite the numerator and the denominator.

Anda mungkin juga menyukai