[Solution]HugeInt Class

We are given the .h file and the driver .cpp need to build the implementation files in c++, please make it original Use the provided…

We are given the .h file and the driver .cpp need to build the implementation files in c++, please make it original Use the provided HugeInt.h. Complete the implementation of the HugeInt class in HugeInt.cpp. You may not change or modify the HugeInt header. Using C++
HugeInt Class
The HugeInt class represents an integer of very many digits.
Each digit is stored in a node of a doubly linked list of nodes. There is a pointer to each end of the list. The list can be traversed in either direction. Each node has a pointer in each direction.
Each node has a single integer digit and two pointers. One pointer, next_greater, points to the next, more significant digit. The other pointer, next_lesser, points to the next, less significant digit.
A single pointer of type Node points to the least significant digit. This pointer is lsd.
A single pointer of type Node points to the most significant digit. This pointer is msd.
The digits are stored in order from the least significant digit to the most significant digit.
The HugeInt objects may be added together. This must be done with operator overloading. Specifically, the operator+ must be overloaded.
The Hugeint objects may be compared for equal or less than. This must be done with operator overloading. Specifically, the operator>,operator<,operator== operators must be overloaded.
HugeInt Driver
The HugeInt driver should create several HugeInt objects and demonstrate all features.
HugeInt.h
#ifndef HUGEINT_H_
#define HUGEINT_H_
enum SignType {PLUS, MINUS};
class HugeInt{
private:
struct Node
{
int digit; // SINGLE DIGIT ONLY ie: (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
Node *next_greater; // Next More Significant Digit
Node *next_lesser; // Next less Significant Digit
};
/* Integer 345 is stored in List: lsd-> 3 -><- 4 -><- 5 <- msd
Integer 123 is stored in List: lsd-> 1 -><- 2 -><- 3 <- msd
To add: add the least significant digits, potentially
keeping track of a carry value. Then move to the next
left nodes in both HugeInts. Add these and the carry.
Create a new carry value. Continue until both HugeInt
lists are empty. If one list is empty, keep processing
the non-empty list.
*/
Node *lsd; //Least significant digit
Node *msd; //Most significant digit
SignType sign; //enum of the sign of the HugeInt
int numDigits; //Number of digits in the HugeInt
void makeEmpty(); //clear the linked list of digits
public:
HugeInt();
~HugeInt();
bool operator<(const HugeInt &second) const;//compare for less than. return true/false
bool operator==(const HugeInt &second) const;//compare for equal. return true/false
HugeInt operator+(const HugeInt &second) const;//add
HugeInt operator-(const HugeInt &second) const;//subtract
HugeInt operator=(const HugeInt &second) const;//copy
void insertDigit(int); //insert new integer digit. Insert each digit separately!!!!!!!
void printDigits() const; //print the HugeInt from lsd to msd.
};
#endif
tester.cpp
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <ctime>
#include “HugeInt.h”
using namespace std;
int main()
{
HugeInt hi1;
HugeInt hi2;
HugeInt hi3;
srand((unsigned) time(0));
int digit;
for (int i = 0; i < 1000; i++){
digit = (rand()%10); //random digit 0-9
hi1.insertDigits(digit); //insert digit
digit = (rand()%10); //random digit 0-9
hi2.insertDigits(digit);
}
hi1 = hi1 + hi2; //add HugeInts
if (hi1 == hi2){
cout << “Equaln”;
}
if (hi1 < hi2){
cout << “hi1 is less than hi2n”;
}else{
cout << “hi1 is more than hi2n”;
}
cout << “HugeInt 1:n”;
printDigits(hi1);
cout << “HugeInt 2:n”;
printDigits(hi2);
return 0;
};

Assignment status: Solved by our experts

>>>Click here to get this paper written at the best price. 100% Custom, 0% plagiarism.<<<

Leave a Reply

Your email address will not be published. Required fields are marked *