Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objectives: Develop, implement, and use an Abstract Data Type (ADT) with the class construct in C++. Problem: The data type int in C++ is limited

Objectives: Develop, implement, and use an Abstract Data Type (ADT) with the class construct in C++. Problem: The data type int in C++ is limited to the word size of the CPU architecture (e.g., 32 or 64 bit). Therefore you can only work with signed integers up to 2,147,483,647 (in the case of signed 32 bit). Unsigned 32 bit is still only 10 digits. Maxint for 64 is somewhat larger at 9,223,372,036,854,775,807 but still only 19 digits. Clearly, this causes difficulties for working with very large integer values (say 100 digits). Your job is to develop an ADT (called bigint) that can take any size postive integer. It should work for 100, 200, 500, etc. digit integers. Representation is a key issue for this assignment. We recommend an array of integers, with each element representing one single digit (0 to 9) of the big number. One could use an array of char, but the memory savings is pretty minimal. Placing the values in the array is the interesting part. The nave representation makes storing the bigint easy but makes the operations (add and multiply) very difficult to implement. A slightly more clever representation makes storing the big number a little bit harder but makes implementing the operations way easier. Arrays are typically drawn to be read left to right with the 0 element on the left and the largest on the right. However, arrays are a completely made up concept and are not physical in nature. So you can draw them and think about them anyway you want. For this problem having the right side as the 0 element and the left side as the largest makes much more sense. Take the example of the number 7925. We show how it is stored in the array below. The 5 is in the one's position, the 2 in the 10's position and so on. This neatly corresponds to the index of the array. The addition and multiple algorithms given below use this representation. bigint

Index: n ... 6 5 4 3 2 1 0
Place: 10^n ... 10^6s 10^5s 10000s 1000s 100s 10s 1s
Value: 0 ... 0 0 0 7 9 2 5

Requirements:

In your svn folder, name the folder for this project bigint.

There is a makefile and test cases provided for you in the svn/shared folder in svn.

Your program must compile and run on the department's system (wasp or honet) using the provided makefile.

You must use the class construct to implement your ADT.

The ADT bigint need only work for positive integers.

Use a global constant value for the maximum size of the bigint that is, a constant sized array.

using namespace std; is stricly forbiden. As are any global using statements.

Milestone 1 - 30 ptsImplementation:

Develop .hpp and .cpp files to implement your ADT.

The size of the bigint must be specified by a global constant.

A default constructor to initialize a bigint to zero.

A constructor to initialize a bigint to an int value you provide [0, maxint]. Example: bigint(128).

A constructor to initialize a bigint to a const char[] you provide. You can assume what is provided is a valid bigint. Example: bigint("299793").

Develop a method called debugPrint that will be helpful for debugging your bigint. Use a method defintition of void debugPrint(std::ostream&) const; It simply prints out each element of your bigint array starting from the size of the bigint, minus 1, to zero. Printing a "|" between each value would also be pretting helpful.

Overload output operator<< as a friend or free function, so that takes a stream and bigint as input and writes the bigint to the stream. It should print at most 50 digits per line. No leading zeros should be printed.

Overload operator== to compare if two bigints are equal. It should return a bool - true if equal and false otherwise.

Testing:

Use the provided set of test cases to demostrate the correctness of each method you develop. You may add additional cases to these tests.

There is a test driver for each of the three different constructors and equal. The tests for the constructors use the operator<<() and operator==(). So these will be tested at the same time.

These will be a model for the unit tests for the rest of the project.

You will add unit tests for each part of the assignment.

The command make tests will build and run the unit tests.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

4 How can you create a better online image for yourself?

Answered: 1 week ago