So it's been a while since I've coded (a quarter) and I'm taking a data structures II class. I have an assignment where I have to implement a C++ Class named LongInt that uses an embedded internal private data member of type STL list<char> 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 ==.
I've got the basic header and source file outlined (look below) but I am confused on how to implement the class functions. It's really worrying me just how much I forgot about coding so any help would really...REALLY be appreciated.
Thanks.
Header:
// LongInt.h
// Embedded STL <list>
#pragma once
#include <iostream>
#include <list>
#include <string>
using namespace std;
class LongInt
{
public:
LongInt(void);
LongInt(const string v);
~LongInt(void);
// 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<char> val;
};
Source file:
#include <iostream>
#include <iomanip>
using namespace std;
#include "LongInt.h"
int main(int argc, char *argv[])
}
LongInt x, y;
cout << “Initially x = “ << x << endl; //0
cout << "LongInt Testing" << endl;
cout << "Enter x: ";
cin >> x; //82738392000900333454432483992432
cout << "Enter y: ";
cin >> y; //8485938378494837372832442
int maxlen = x.size(); // determine length of largest value
if(maxlen < y.size()) maxlen = y.size();
++maxlen; // Leave room for carry out
cout << " x = " << setw(maxlen) << x << endl; //82738392000900333454432483992432
cout << " y = " << setw(maxlen) << y << endl; //8485938378494837372832442
LongInt sum = x + y;
LongInt prod = x * y;
cout << "sum = " << setw(maxlen) << sum << endl; //82738400486838711949269856824874
cout << "prod = " << setw(maxlen) << prod << endl;
// Test == method
if(x == y) cout << "[x == y]" << endl;
else cout << "[x != y]" << endl;
// Test "On the fly" addition
cout << "fly = " << LongInt("12345") + LongInt("99") << endl;
// Test += method
x = LongInt("12345"); x += LongInt("99");
cout << " x = " << x << endl;
y = LongInt("12345"); y *= LongInt("99");
cout << " y = " << y << endl;
return(0);
}