Description: Implement a C++ Class named LongInt that uses an embedded internal private data member of type STL list to represent the list of each of the single digit characters in the long unsigned integer value. The various methods of the STL list object can be used to insert characters into a LongInt variable (e.g., push_front(), push_back()), determine the current number of items in the list (size() ), and iterate through and access the items in the list with iterators or reverse_iterators. Your class must include appropriate constructors, a size() method, an operator+=() method, an operator*=() method, and friend functions for operators >>, <<, +, *, and ==.

Write a main program that will input two values, add them together to produce a third value, multiply them together to produce a fourth value, and output a short report that prints out the two original values, the sum and the product. Your program must also include code to test and demonstrate that the LongInt class works properly.

Details: Your LongInt class must include a header file similar to the following (yours must be commented):

// LongInt.h
// Embedded STL
#pragma once
#include
#include
#include

using namespace std;

class LongInt
{
public:
LongInt(void);
LongInt(const string v);
~LongInt(void); // if necessary
// Size of LongInt value in characters
int size(void);
friend LongInt operator+(const LongInt& x, const LongInt& y);
friend LongInt operator*(const LongInt& x, const LongInt& y);
LongInt& operator+=(const LongInt& rhs);
LongInt& operator*=(const LongInt& rhs);
friend ostream& operator<<(ostream& out, const LongInt& v);
friend istream& operator>>(istream& in, LongInt& v);
friend bool operator==(const LongInt& x, const LongInt&y);
private:
list val;
  • The default LongInt() constructor initializes a list representing the value 0.
  • The LongInt(const string v) constructor method initializes the internal list to each of the digits in the string v.
  • The ostream operator<< function outputs the sequence of digits in the LongInt value in mostsignificant to leastsignificant order to the out stream. As always, out.width() specifies the minimum number of characters to be output. If the field width is greater than the length of x, then the value must be rightjustified by outputting a preceding series of blank spaces before the numeric value.
  • The istream operator>> function clears out any old value, and then inputs a sequence of LongInt characters on a single line one digit at a time and stores them in the internal list.
  • The bool operator== function returns true if x and y represent the same numeric value, and false otherwise.
  • The operator+ function returns a LongInt representing the sum of x and y. The function adds the corresponding digits of x and y, together with a propagating carry, to create a new LongInt sum. Adding two numbers requires you to begin with the least significant digits and iterate towards the most significant digits. Remember that since the digits in a LongInt are being stored as individual character values (e.g., 1, 2, 3), you must convert each digitcharacter into its corresponding numeric value (e.g., 1, 2, 3) before you can add them, and then you must convert the resulting numeric digitsum value back into its corresponding digitcharacter value and a possible carry value into the adjacent position. If ch is a character variable with a digitcharacter value (e.g., 5), then ( ch 0 ) is an expression with the corresponding digitnumeric value (e.g., 5).
  • The operator* function returns a LongInt representing the product of x and y.
  • The operator+= method adds rhs to the current value.
  • The operator*= method multiplies the current value by the rhs.
  • The size() method returns the number of decimal digits in the value.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.