Question: Please help!! ASAP!! Question 1 Complete the following code so that it solves this problem: https://projecteuler.net/problem=2 (Links to an external site.)Links to an external site.

Please help!! ASAP!!

Question 1

Complete the following code so that it solves this problem:

https://projecteuler.net/problem=2 (Links to an external site.)Links to an external site.

#include

using namespace std;

int main()

{

int N = ____ ;

int a = 0;

int b = ____ ;

int sum = ____ ;

while (b < N)

{

int temp = ____ ;

a = ____ ;

b = a + ____ ;

if (a ____ 2 == 0)

sum ____ a;

}

____ << sum << end;

cin.get();

}

Question 2

What is the solution to the problem in Question 1?

________

Question 3

Modify the code in Question 1 to add all the Fibonacci numbers that are multiples of 3 (instead of even numbers). What is the solution in that case?

________

Question 4

The following class (long_number) represents a number of any length.

#include

#include

#include

#include

using namespace std;

class long_number

{

vector vnumber;

};

Complete the following code so that the default constructor generates the number 0.

____:

____ ()

{

vnumber. ____ ( ____ );

}

Question 5

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

Question 6

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

Question 7

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

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!