Programming homework

Hello, so I have attempted at this code for a while but I still can't get it working, I'm using Cengage, the question is
"Programming Exercise 11 in Chapter 8 explains how to add large integers using arrays. However, in that exercise, the program could add only integers of, at most, 20 digits. This chapter explains how to work with dynamic integers. Design a class named largeIntegers such that an object of this class can store an integer of any number of digits. Add operations to add, subtract, multiply, and compare integers stored in two objects. Also add constructors to properly initialize objects and functions to set, retrieve, and print the values of objects. Write a program to test your class."
There are three systems "largeIntegers.cpp", "largeIntegers.h", and "main.cpp" they all need to have code in them to work so this is what I have so far.
largeInteger.cpp
#include <iostream>
#include <string>
#include "largeIntegers.h"

void largeIntegers::setNum(int list[], int length)
{
for(int i=0; i<length; i++)
{
number=number*10+list[i];
}
}
void largeIntegers::printNum(ostream&)
{
cout<<"number is: "<<number;
}
void largeIntegers::getNum(istream&)
{
cout<<"Enter an integer: ";
cin>>number;
}
void largeIntegers::copyNum(const largeIntegers& right)
{
number=right.number;
}
bool largeIntegers::equal(const largeIntegers& right)const
{
if(right.number==number)
{
return true;
}
else
return false;
}
bool largeIntegers::notEqual(const largeIntegers& right)const
{
if(right.number==number)
{
return false;
}
else
return true;
}
bool largeIntegers::greaterThan(const largeIntegers& right)const
{
if(right.number>number)
{
return true;
}
return false;
}
bool largeIntegers::lessThan(const largeIntegers& right)const
{
if(right.number<number)
{
return true;
}
else
return false;
}
bool largeIntegers::lessOrEqualTo(const largeIntegers& right)const
{
if(right.number<=number)
{
return true;
}
else
return false;
}
bool largeIntegers::greaterOrEqualTo(const largeIntegers& right)const
{
if(right.number>=number)
{
return true;
}
else
return false;
}
largeIntegers largeIntegers::add(const largeIntegers& num)
{
largeIntegers n;
n.number=number-num.number;
return n;
}
largeIntegers largeIntegers::multiply(const largeIntegers& num)
{
largeIntegers n;
n.number=number*num.number;
return n;
}
largeIntegers::largeIntegers()
{
number=0;
}
largeIntegers::largeIntegers(int list[], int length, char numSign)
{
for(int i=0; i<length; i++)
{
number=number*10+list[i];
}
if(numSign=='_')
{
number=number-(2*number);
}
}
largeInteger.h
#include <iostream>
#include <string>
using namespace std;
class largeIntegers
{
private:
long long int number;
public:
void setNum(int list[], int length);
void printNum(ostream&);
void getNum(istream&);
void copyNum(const largeIntegers& right);
bool equal(const largeIntegers& right) const;
bool notEqual(const largeIntegers& right) const;
bool greaterThan(const largeIntegers& right) const;
bool lessThan(const largeIntegers& right) const;
bool lessOrEqualTo(const largeIntegers& right) const;
bool greaterOrEqualTo(const largeIntegers& right) const;
largeIntegers add(const largeIntegers&
num);
largeIntegers subtract(const largeIntegers&);
largeIntegers multiply(const largeIntegers& num);
largeIntegers();
largeIntegers(int list[], int length, char numSign);
};
main.cpp
#include <string>
#include <iostream>
#include <iomanip>
#include "largeIntegers.h"

using namespace std;
int main()
{
largeIntegers num1, num2;
largeIntegers temp;
num1.getNum(cin);
num2.getNum(cin);
cout<<"num1: ";
num1.printNum(cout);
cout<<endl;
cout<<"num2: ";
num2.printNum(cout);
cout<<endl;
temp=num1.add(num2);
cout<<"num1+num2=";
temp.printNum(cout);
cout<<endl;
temp=num1.subtract(num2);
cout<<"num1-num2=";
temp.printNum(cout);
cout<<endl;
temp=num1.multiply(num2);
cout<<"num1*num2=";
temp.printNum(cout);
cout<<endl;
system("PAUSE");
return 0;
}
Thank you!
how annoying this is comes down to how you store the values.
if you use say base 10, 15 digits per chunk shoved into a container of 64 bit ints
and it can be useful to store the numbers in reverse so [0] and [0] represent the same thing and when you hit size() of either number add carry once and copy down the rest.

its much more efficient to use the entire 64 bit int and a non base 10 approach rather than a simple base 10 approach but for debugging and understanding that is a good starting point.
Topic archived. No new replies allowed.