Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ two files: solution.cc and solution.hpp an unsigned int base. The function will multiply init_value by increasing powers of base (base^ 1 , base^ 2

C++

two files: solution.cc and solution.hpp

image text in transcribed

an unsigned int base. The function will multiply init_value by increasing powers of base (base^ 1 , base^ 2 , , base^ (n1), base^ n) until integer overflow is observed. You can use pow from . Should you do so, keep in mind pow returns a double; your program must perform integer arithmetic when multiplying the base raised to the exponent against the init_value. ExponentTo0verflow will return an std: : pair (you can use std: : make pair), where the pair's first field is the exponent that base was raised to that caused overflow when multiplied by int in it_value. The pair's second field is the number observed when overflow occurred. For example, if we invoked: - ExponentTo0verflow (1048,2); - The implementation of ExponentTo0verf low would multiply the original value 1048 by base 2 raised to increasing exponent values until overflow was observed. - On my machine, this occurred with exponent 21 and the overflow value observed was -2097152000. - That is, when we multiplied 1048221, integer overflow was observed for the first time: exponents 1 through 20 inclusive did not cause overflow. - ExponentTo0verflow (2000,2); - The implementation of ExponentTo0verf low would multiply the original value -2000 by base 2 raised to increasing exponent values until overflow was observed. - On my machine, this occurred with exponent 21 and the overflow value observed was 100663296 . - That is, when we multiplied 2000221, integer overflow was observed for the first time: exponents 1 through 20 inclusive did not cause overflow. - ExponentTo0verflow (20000,4); - The implementation of ExponentTo0verf low would multiply the original value -20000 by base 4 raised to increasing exponent values until overflow was observed. - On my machine, this occurred with exponent 9 and the overflow value observed was -947912704 . - For this case, why is the computed overflow value negative when the starting value passed to this function is -20000 ? Consider that on my machine: 2000048=1310720000 and 2000049= -947912704. Did you notice that 2000049 evaluates to a less negative value than 2000048 ? Consider that std: : numeric_limits>:min() returns 2,147,483,648 and that 2000049 should equal 5,242,880,000. Do you see what's going on? An int cannot store the result of 2000049 since it's outside the type's range. Consider such cases for positive and negative init_values! You can do this by comparing the value you computed with exponent n to the value computed with exponent n1. If the result computed with exponent n has the same sign but is less than that computed with exponent n 1, you've observed an overflow. an unsigned int base. The function will multiply init_value by increasing powers of base (base^ 1 , base^ 2 , , base^ (n1), base^ n) until integer overflow is observed. You can use pow from . Should you do so, keep in mind pow returns a double; your program must perform integer arithmetic when multiplying the base raised to the exponent against the init_value. ExponentTo0verflow will return an std: : pair (you can use std: : make pair), where the pair's first field is the exponent that base was raised to that caused overflow when multiplied by int in it_value. The pair's second field is the number observed when overflow occurred. For example, if we invoked: - ExponentTo0verflow (1048,2); - The implementation of ExponentTo0verf low would multiply the original value 1048 by base 2 raised to increasing exponent values until overflow was observed. - On my machine, this occurred with exponent 21 and the overflow value observed was -2097152000. - That is, when we multiplied 1048221, integer overflow was observed for the first time: exponents 1 through 20 inclusive did not cause overflow. - ExponentTo0verflow (2000,2); - The implementation of ExponentTo0verf low would multiply the original value -2000 by base 2 raised to increasing exponent values until overflow was observed. - On my machine, this occurred with exponent 21 and the overflow value observed was 100663296 . - That is, when we multiplied 2000221, integer overflow was observed for the first time: exponents 1 through 20 inclusive did not cause overflow. - ExponentTo0verflow (20000,4); - The implementation of ExponentTo0verf low would multiply the original value -20000 by base 4 raised to increasing exponent values until overflow was observed. - On my machine, this occurred with exponent 9 and the overflow value observed was -947912704 . - For this case, why is the computed overflow value negative when the starting value passed to this function is -20000 ? Consider that on my machine: 2000048=1310720000 and 2000049= -947912704. Did you notice that 2000049 evaluates to a less negative value than 2000048 ? Consider that std: : numeric_limits>:min() returns 2,147,483,648 and that 2000049 should equal 5,242,880,000. Do you see what's going on? An int cannot store the result of 2000049 since it's outside the type's range. Consider such cases for positive and negative init_values! You can do this by comparing the value you computed with exponent n to the value computed with exponent n1. If the result computed with exponent n has the same sign but is less than that computed with exponent n 1, you've observed an overflow

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Database Programming With Visual C# .NET

Authors: Ying Bai

1st Edition

0470467274, 978-0470467275

More Books

Students also viewed these Databases questions

Question

How do Dimensional Database Models differ from Relational Models?

Answered: 1 week ago

Question

What type of processing do Relational Databases support?

Answered: 1 week ago

Question

Describe several aggregation operators.

Answered: 1 week ago