Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program that multiplies two very large integers, with an arbitrary n

ID: 3939957 • Letter: W

Question

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

Explanation / Answer

#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;
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote