Question
Question The following class (long_number) represents a number of any length. #include #include #include #include using namespace std; class long_number { vector vnumber; }; Complete
Question
The following class (long_number) represents a number of any length.
#include
#include
#include
#include
using namespace std;
class long_number
{
vector
};
Complete the following code so that the default constructor generates the number 0.
____:
____ ()
{
vnumber. ____ ( ____ );
}
Continuing with the code on Question 4, complete the following code which implements the function print, which prints the long_number
____ print()
{
For (int ____ : ____ )
{
____ << n;
}
cout << endl;
}
If your code is correct the following code should show one (and only one) 0 on the screen.
int main() { long_number n1; n1.print(); cin.get(); return 0; }
Continuing with the code in Question 5, complete the following code which implements a constructor that turns an array of chars into a long_number.
For example, if the string is "12345", the corresponding long_number will have the following value in its fields:
vnumber = {1,2,3,4,5}
____ ( ____ input[], int_size)
{
for (int i = 0; i < ____ ; i++)
{
vnumber. ____ (( ____ )input[ ____ ] (int) ____ );
}
}
If your code is correct the following code should show 12345 on the screen.
int main() { char input1[] = "12345"; long_number n1(input1, 5); n1.print(); cin.get(); return 0; }
Continuing with the code in Question 6, complete the following code which implements the operator+ so that the operator adds to long_numbers together.
friend long_number ____ (long_number lhs, ____ long_number& rhs)
{
int carry = ____ ;
int i = ____ (lhs. ____ (), rhs. ____ ())- ____ ;
for (;i>=0;I ____)
{
int sum = lhs.vnumber[i] + rhs.vnumber[i] + carry;
lhs.vnumber[i] = sum ____ 10;
carry = sum ____ 10;
}
if (carry > 0)
{
lhs.vnumber. ____ (lhs.vnumber. ____ (), ____ );
}
____ lhs;
}
Question 8
Use the long_number from the previous part to calculate the sum of these two numbers:
91942213363574161572522430563301811072406154908250
23067588207539346171171980310421047513778063246676
[Extra Credit - 15 points]
Submit your code for all the previous questions as one cpp file.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started