Question: Book: C++ programming program disign including data structures Problem: Programming Exercise 11 in Chapter 8 explains how to add large integers using arrays. However, in

Book: C++ programming program disign including data structures

Problem: 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.

Should Include

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& num);

largeIntegers multiply(const largeIntegers& num);

largeIntegers();

largeIntegers(int list[], int length = 0, char numSign = '+');

--------------------------------------------------------------------------------------

Should Include

//*********************************************************************************************

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;

}

//***************************************************************************************************

The result should look like below.

--------------------------------------------------------------------------------------------------------------------

Enter an integer: 12345678901234567890123456789012345

Enter an integer: 87654321098765432109876543210987654

num1:12345678901234567890123456789012345

num2: 87654321098765432109876543210987654

num1+num2:99999999999999999999999999999999999

num1-num2:-7530864215987654654654849494964305309

num1*num2:1082152431865198465421909808495465654354689879846565480798465132134840988630

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!