Question: 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

  • 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. Max int 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). An ADT (called bigint) has been created to support an arbitrary number of digits (specified at compile time). For simplicity, the implementation is limited to non-negative integers.

  • Representation is a key issue for this assignment. An array of integers is recommended, 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) 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.

  • Take the number 12486

bigint
index: 0 1 2 3 4 5 n
nave: 1 2 4 8 6 0 0
best: 6 8 4 2 1 0 0
  • Notice this corresponds to:
bigint
index: 0 1 2 3 4 5 n
place: 100 101 102 103 104 105 10n
best: 6 8 4 2 1 0 0

Requirements

  • Follow, class Programming Requirements

  • Program must compile and run on Visual Studio.

  • Finished work must be submitted to GitHub.

  • You must use the class construct to implement your ADT.

  • Dont edit bigint.hpp or the supplied test files.

  • Use the provided CMakeLists.txt.

  • The ADT bigint need only work for positive integers.

  • Iteration 1 - 50 points
    • Implementation
      • Develop the cpp file to implement your ADT.
      • 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 char[] you provide. You can assume what is provided is a valid bigint. Example: bigint(299793).
      • Overload operator== to compare if two bigints are equal. It should return a bool - true if equal and false otherwise.
      • A debug_print method is provided for you to help developing and debugging.
    • Testing
      • There are a provided set of tests to validate your you implementation of the above.
      • On Visual Studio you will need run each individually.

I at least need bigint(const char * number) implemented correctly so it will work and execute, but the rest is what I'm asking for if possible

  • Iteration 2 - 50 points
    • Implementation
      • Overload output operator<< as a friend, so that it takes a stream and bigint as input and writes the bigint to the stream. It should print at most 25 digits per line. No leading zeros should be printed.
      • Overload input operator>> a bigint in the following manner: Read in any number of digits [09] until a semi colon ; is encountered. The number may span over multiple lines. You can assume the input is valid.
      • Overload the subscript operator[]. It should return the i-th digit, where i is the 10i position. So the first digit is the ones place (100) and the second digit is the tens place (101).
      • Overload the operator+ so that it adds two bigint together.
      • Implement add.cpp. The main reads from the file data11.txt and must do the following:
        • Test for success of opening the file in your program.
        • Read in two numbers into bigints and write both out on separate lines.
        • Add these together and write the result.
        • Then read in two more big numbers, adding them and writing the result until end of file.
        • All output must be labeled and neat.
        • You will need to select the add program to compile/run
      • Testing
        • There are a provided set of tests to validate your implementation of the above.
        • You will need to update the CMakeLists.txt file
        • On Visual Studio you will need run each individually.

bigint.hpp

#ifndef BIGINT_HPP #define BIGINT_HPP

#include

class bigint {

public: static const int MAX_DIGITS = 50;

private: int digits[MAX_DIGITS];

public:

// constructors bigint(); bigint(int number); bigint(const char * number); bool operator==(const bigint & rhs) const;

int operator[](int pos) const;

friend bigint operator+(bigint lhs, const bigint & rhs);

void debug_print(std::ostream & out); friend std::ostream& operator<<(std::ostream & out, const bigint & rhs); friend std::istream& operator>>(std::istream & in, bigint & rhs);

};

#endif

bigint.cpp(What I have so far, feel free to change what I already have inside if absolute must)

#include "bigint.hpp" #include

bigint::bigint() { for(int i = 0; i < MAX_DIGITS; ++i) digits[i] = 0; } bigint::bigint(int num) : bigint() { for(int i = 0; i < MAX_DIGITS; ++i) { digits[i] = num; } }

bool bigint::operator==(const bigint& rhs) const { for (int i = 0; i < MAX_DIGITS; ++i) { if (digits[i] != rhs.digits[i]) return false; } return true; }

bigint::bigint(const char* number) : bigint() {

} std::ostream& operator<<(std::ostream& out, const bigint& rhs) {

}

void bigint::debug_print(std::ostream& out) { out << "| "; for (int i = MAX_DIGITS - 1; i >= 0; --i) { out << digits[i] << " | "; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!