[Solved]Need Help C Project Done Still Working Assignment Create Library Capable Holding Arbitrari Q37072918
NEED HELP WITH MY C++ PROJECT.
HAVE SOME DONE BUT IT IS STILL NOT WORKING.
For this assignment you will create a library capable of holdingarbitrarily large numbers capable of basic arithmetic operations.It is a two-phase project, starting with construction and printing,ending with the arithmetic operations. How do we go about holdingarbitrarily large numbers? You have already implemented a dynamicarray; this earns you the right to use a valuable part of the C++standard library: the std::vector class. For this assignment, wewill represent a bigint as the following type:
std::vector number;
Which you can read as “a number is a vector of vec_bins” while avec_bin is an integer type that will represent a single digit of anumber. So we’re going to represent numbers just like you learnedin school: as a sequence of digits.
Constructors
Default constructor bigint a; yields a BigInt equal to 0.
String Constructor bigint a(“100000000”); yields a BigInt equalto the integer value of the string provided, in this case:100,000,000.
Integer Constructor bigint a(100); yields a BigInt equal to theinteger provided, in this case: 100. Integers can be up to unsignedlong long in size.
BigInt Constructor c++ bigint a(0); bigint b(a); // Creates bfrom a. Yields two equivalent BigInts, both equal to 0 in thiscase.
Yields two equivalent BigInts, both equal to 0 in this case.
Methods to_string( bool commas = false ) Returns the stringinterpretation of the BigInt, with an optional flag to generate astring that utilizes commas for formatting.
c++ bigint a = 1000000; std::cout << a.to_string()<< std::endl; // prints “1000000n” std::cout <<a.to_string(true) << std::endl; // prints “1,000,000n”
(private) strip_zeros() Used to remove leading zeros from aBigInt.
add( bigint &that ) Returns a new BigInt which is the sum of*this and that. *this and that are not modified by this operation.Addition: +, += Adds two BigInts together. c++ bigint a = 1000;bigint b = 1e50; bigint c = a + b; c += a; c += b;c++ bigint x =10; bigint y = 15; bigint z = x.add(y); // z is 25, moreover x isstill 10, y is still 15.
multiply( bigint &that ) Returns a new BigInt which is theproduct of *this and that. *this and that should not be modified bythe operation. = Multiplies two BigInts together. c++ bigint a =10; bigint b = 1e27; bigint c = a*b; c *= a;
c++ bigint x = 5; bigint y = 2; bigint z = x.multiply(y); // z =10; x = 5; y = 2;
Stream operator, << BigInt provides stream operators forease of printing, the ostream (<<) operator runsto_string.
Operators
Digit Access: [] c++ bigint a(123); int x = a[2]; // x == 1.Yields the digit at the specified index. This method is typicallyused for testing, and during internal arithmetic operations
Comparators
Equality: == and != c++ bigint a(10); bigint b(10); a == b; //Yields true. a != b; // Yields false.
Greater Than / Less Than:
>, >=, <, <= Compares the values of two BigInts,returning true if the former is larger.
THIS IS MY CODE SO FAR
/*
A class to represent arbitrarily large integers
*/
#include “bigint.h”
void bigint::strip_zeros() {
// remove any leading 0s
while(!number.empty() && number.back() == 0)number.pop_back();
if(number.empty()){
number.push_back(0);
}
}
/* Constructors
*
* */
// empty constructor
bigint::bigint() {
number.clear();
number.push_back(0);
}
bigint::bigint(const std::vector<vec_bin> &that){
number.clear();
number = that;
this->strip_zeros(); // same as(*this).strip_zeros();
}
bigint::bigint(unsigned long long i) {
number.clear();
// No matter what, record a digit (even if its 0).
// Continue to do so while the number leftover isnt 0
do {
number.push_back((vec_bin)(i % 10));
} while (i /= 10);
}
bigint::bigint(std::string str) {
number.clear();
// Get each digit, starting from the end, and append tonumber.
for (int i = str.length(); i > 0; –i)number.push_back((vec_bin)(str[i-1]))
}
for ( ; i >= 0; –i)
out << number.push_back[i];
return 0;
}
bigint::bigint(const bigint &that) {
number = that.number;
}
/* Number Access
*
* */
const std::vector<vec_bin> &bigint::getNumber() const{
return number;
}
vec_bin bigint::operator[](size_t index) const {
return number[index];
}
/** Comparators
*
* */
bool bigint::operator==(const bigint &that) const {
return = ((*this, that);
}
bool bigint::operator!=(const bigint &that) const {
return != ((*this), that);
}
bool bigint::operator<(const bigint &that) const {
return < ((*this), that);
}
bool bigint::operator<=(const bigint &that) const {
return = ((*this), that) || < ((*this), that);
}
bool bigint::operator>(const bigint &that) const {
return > ((*this), that);
}
bool bigint::operator>=(const bigint &that) const {
return > ((*this), that) || >((*this), that);
}
/** Addition
*
* */
bigint bigint::add(const bigint &that) const {
}
bigint bigint::operator+(const bigint &that) const {
bigint sum = *this
sum += that;
return sum;
}
bigint &bigint::operator+=(const bigint &that) {
}
bigint &bigint::operator++() {
(*this) = (*this) + 1;
return(*this);
}
bigint bigint::operator++(int) {
}
/** Multiplication –
*
* */
bigint bigint::multiply(const bigint &that) const {
}
bigint bigint::operator*(const bigint &that) const {
}
bigint &bigint::operator*=(const bigint &that) {
}
/** Display methods
*
* */
std::ostream &operator<<(std::ostream &os, constbigint &bigint1) {
return os << bigint1.to_string(true);
}
std::string bigint::to_string(bool commas) const {
// Build a string representation of the bigint.
std::string result;
result += (static_cast<char>(number[number.size() – 1] + ‘0’));
// iterate up to 2 from the end, so triplets of digits can beseparated by commas
for (int i = number.size() – 2; i >= 0; –i) {
if (i % 3 == 2 && commas) result += ‘,’;
result += (static_cast<char>(number[i] + ‘0’ ));
}
return result;
}
THE MAIN.CPP
#include <iostream>
#include “bigint.h”
using namespace std;
// Wicked small test file – just to get your feet wet with testingbigint
int main() {
bigint x =18446744073709551614;
bigint y = 6;
bigint z = x + y;
cout << z << endl;
z++;
cout << z << endl;
x = 5;
y = 4;
bool q = (x != y);
cout << q << endl;
return 0;
}
THE HEADER FILE
#ifndef __BIGINT_H__
#define __BIGINT_H__
#include <vector>
#include <string>
#include <stdint.h>
#include <fstream>
#include <iostream>
typedef unsigned short vec_bin;
class bigint {
private:
std::vector<vec_bin> number;
void strip_zeros();
public:
/** Constructors
*
* Bigints can be built via:
* – Zero
* – Vectors
* – Unsigned integers
* – Strings
* – files
* – Other Bigints
* */
bigint();
bigint(const std::vector<vec_bin> &that);
bigint(unsigned long long i);
bigint(std::string str);
bigint(std::ifstream &infile);
bigint(const bigint &that);
/** Number access.
*
* */
const std::vector<vec_bin> &getNumber() const;
vec_bin operator[](size_t idx) const;
/** Comparators
*
* */
bool operator==(const bigint &that) const;
bool operator!=(const bigint &that) const;
bool operator<(const bigint &that) const;
bool operator>(const bigint &that) const;
bool operator<=(const bigint &that) const;
bool operator>=(const bigint &that) const;
/** Arithmetic
*
* */
// Addition
bigint add(const bigint &that) const; // returns a new bigiintthat is the sum of the two bigints *this and that
bigint operator+(const bigint &that) const; // returns a newbigiint that is the sum of the two bigints *this and that
bigint &operator+=(const bigint &that); // adds bigint thatto bigint *this and overwrites *this
bigint &operator++(); // Prefix increment i.e. ++i
bigint operator++(int); // Postfix increment i.e. i++
/** Display
*
* << operator, to_string, and pprint.
* */
std::string to_string(bool commas = false) const; // returns astring representation of the bigint with or without commas.
friend std::ostream &operator<<(std::ostream &os,const bigint &bigint1); // use << operator to print thebigint as a string with commas to the ostream.
std::string scientific(unsigned int decimal_points = 3) const; //returns a string of the form “1.123E25” i.e. scientific notationwith the gievn number of decimal points.
void to_file(std::ofstream &outfile, unsigned int warp =80);
};
#endif // __BIGINT_H__
Expert Answer
Answer to NEED HELP WITH MY C++ PROJECT. HAVE SOME DONE BUT IT IS STILL NOT WORKING. For this assignment you will create a library… . . .
OR

