Starting from:
$24.99

$18.99

Object and Generic Programming in C++ Laboratory Exercise 4 (Week 6) Solution

Task: Overloading operators

 

 

We will reuse some definitions and implementations of the class BigInteger defined in the lab 3 for this task.

 

Define the class BigInteger in a file BigInteger.h and implement its member functions in a file BigInteger.cpp that can be used to store a large positive integer. The class contains two data members: a pointer of short integer and the size of the dynamic short integer array. Define the following member functions:

 

•   The default constructor;

•    An initialization constructor initializes a BigInteger instance with a char array, in which all elements are decimal digits.

•   The copy constructor makes a deep copy from a BigInteger instance.

•   The destructor;

•   Define insertion operator and extraction operator for the class.

•    Define assignment operator for the class that makes a deep copy from a BigInteger object.

•    Define addition operator that returns a BigInteger object of addition result. Do not change the operands.

•    Define multiplication operator for the class that returns a BigInteger object of multiplication result. Do not change the operands.

•    Define comparison operator “equals to” that returns the value “true” if two BigInteger objects contain the same values.

 

 

 

Write the driver program include main function in a file lab4Main.cpp to declare instances of

BigInteger, test all the overloading operators defined above.

 

Be careful not to submit the solutions for the lab 4 task.

 

Compile the files by

g++ –o task4 lab4Main.cpp BigInteger.cpp

 

And execute it. Your program should be run like the following example (Red data means input from keyboard)

 

 

 

./task4

Input a big integer for bi1: 567239745104730482394650169432

Input a big integer for bi2: 882323456205024318310561095

Initial bi3=1234567890

bi3 = bi1 + bi2 = 568122068560935506712960730527

bi3 = bi1 * bi2 = 500488932397662823233748695498247943120741026136737448040 bi1 is not equal to bi2

bi3 = bi2 = 882323456205024318310561095 bi3 is equal to bi2

 

 

 

Submission:

 

submit –u your-user-name –c CSCI204 –a L4 BigInteger.h BigInteger.cpp lab4Main.cpp

 

and input your password.

 

Make sure that you use the correct file names. The UNIX system is case sensitive. You must submit all files in one submit command line.

 

After submit your assignment successfully, please check your email of confirmation. You should keep this email for the reference.

 

You would receive ZERO of the marks if your program codes could not be compiled correctly.

 

Later submission will not be accepted. Submission via e-mail is NOT acceptable.

 

End of Specification

More products