Write a C program that multiplies two very large integers wi
Write a C++ program that multiplies two very large integers, with an arbitrary
number of digits each. Have it read the numbers from standard input and
write the product to standard output.
2 - Functional Description of major components (Class, subprograms..)
Product class
- holds variables of two integers, x and y as private members
-uses functions to get the two integers, multiply the two integers, and displays the result
Function to multiply - within multiply class is a function that multiplies x and y and sets their product to a variable named result
Solution
#include<iostream>
using namespace std;
class Product
{
//declare two variables x and y to hold large integer
long long x;
long long y;
//declare result as long to hold product of two variables x and y
long long result;
public:
//default constructor
Product()
{
x = 0;
y = 0;
result = 0;
}
void get_values()
{
cout<<\"Enter x = \";
cin>>x;
cout<<\"Enter y = \";
cin>>y;
}
long long multiply()
{
result = x * y;
//cout<<\"product of x and y = \"<<result<<endl;
return result;
}
};
int main()
{
//declare object prod1 of type class product
Product prod1;
long long result;
//call method get_values of class Product
prod1.get_values();
//call method multiply of class Product
result = prod1.multiply();
cout<<\"product of x and y = \"<<result<<endl;
}
