subject

This assignment presents code that is designed to show the two functions operating with and without overflow or underflows. Using the existing source code, you will add logic to the add_numbers() and subtract_numbers() functions to detect, prevent, and notify the caller of a numeric overflow. You will also modify the calling test_overflow and test_underflow functions to be notified of success or failure of the add or subtract functions they call, and to modify them, the functions write to the console with overflow status (true or false) and the numeric result of the function. The following are a few key notes:
The source code has been commented with TODOs to explain the detailed rules you must follow.
There are comments that mark code that must be changed.
There may be more than one way to solve this problem, so be sure to demonstrate that you can detect an underflow or overflow, prevent it, and communicate it back to the calling function.
Remember to leverage capabilities provided by the standard C++ library to help you achieve success.
Please comment on any changes you make in the code to explain the logic, formulas, or data types you are adding. You will also create a brief written summary of the approach taken. It should explain how this approach is designed to stop the overflow or underflow, any issues you encountered, and how you resolved those issues.
Specifically, you will prepare the following:
Numeric overflow and underflow secure coding
C/C++ program functionality and best practices
A summary of your process in a Word document that contains a screenshot of the application console output
// NumericOverflows. cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include // std::cout
#include // std::numeric_limits
///
/// Template function to abstract away the logic of:
/// start + (increment * steps)
///
/// A type that with basic math functions
/// The number to start with
/// How much to add each step
/// The number of steps to iterate
/// start + (increment * steps)
template
T add_numbers(T const& start, T const& increment, unsigned long int const& steps)
{
T result = start;
for (unsigned long int i = 0; i < steps; ++i)
{
result += increment;
}

return result;
}
///
/// Template function to abstract away the logic of:
/// start - (increment * steps)
///
/// A type that with basic math functions
/// The number to start with
/// How much to subtract each step
/// The number of steps to iterate
/// start - (increment * steps)

template
T subtract_numbers(T const& start, T const& decrement, unsigned long int const& steps)
{
T result = start;

for (unsigned long int i = 0; i < steps; ++i)
{
result -= decrement;
}

return result;
}
// NOTE:
// You will see the unary ('+') operator used in front of the variables in the test_XXX methods.
// This forces the output to be a number for cases where cout would assume it is a character.
template
void test_overflow()
{
// TODO: The add_numbers template function will overflow in the second method call
// You need to change the add_numbers method to:
// 1. Detect when an overflow will happen
// 2. Prevent it from happening
// 3. Return the correct value when no overflow happened or
// 4. Return something to tell test_overflow the addition failed
// NOTE: The add_numbers method must remain a template in the NumericFunctions header.
//
// You need to change the test_overflow method to:
// 1. Detect when an add_numbers failed
// 2. Inform the user the overflow happened
// 3. A successful result displays the same result as before you changed the method
// NOTE: You cannot change anything between START / END DO NOT CHANGE
// The test_overflow method must remain a template in the NumericOverflows source file
//
// There are more than one possible solution to this problem.
// The solution must work for all of the data types used to call test_overflow() in main().
// START DO NOT CHANGE
// how many times will we iterate
const unsigned long int steps = 5;
// how much will we add each step (result should be: start + (increment * steps))
const T increment = std::numeric_limits::max() / steps;
// whats our starting point
const T start = 0;
std::cout << "Overflow Test of Type = " << typeid(T).name() << std::endl;
// END DO NOT CHANGE
std::cout << "\tAdding Numbers Without Overflow (" << +start << ", " << +increment << ", " << steps << ") = ";
T result = add_numbers(start, increment, steps);
std::cout << +result << std::endl;
std::cout << "\tAdding Numbers With Overflow (" << +start << ", " << +increment << ", " << (steps + 1) << ") = ";
result = add_numbers(start, increment, steps + 1);
std::cout << +result << std::endl;
}
template
void test_underflow()
{
// TODO: The subtract_numbers template function will underflow in the second method call

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 15:30
Why would a programmer use the logical operator and in an if statement? a: when an action is to be taken that requires both conditions to be falseb: when an action is to be taken that requires both conditions to be truec: when an action is to be taken that requires the first condition to be falsed: when an action is to be taken that requires the second condition to be truei took the test and the answer is b.
Answers: 3
question
Computers and Technology, 23.06.2019 03:50
Q-1 which of the following can exist as cloud-based it resources? a. physical serverb. virtual serverc. software programd. network device
Answers: 1
question
Computers and Technology, 23.06.2019 15:20
An ou structure in your domain has one ou per department, and all the computer and user accounts are in their respective ous. you have configured several gpos defining computer and user policies and linked the gpos to the domain. a group of managers in the marketing department need different policies that differ from those of the rest of the marketing department users and computers, but you don't want to change the top-level ou structure. which of the following gpo processing features are you most likely to use? a, block inheritance b, gpo enforcement c, wmi filtering d, loopback processing
Answers: 3
question
Computers and Technology, 24.06.2019 12:40
Match the feature to the network architecture. expensive to set up useful for a small organization easy to track files has a central server inexpensive to set up difficult to track files useful for a large organization does not have a central server client- server network peer-to-peer network
Answers: 3
You know the right answer?
This assignment presents code that is designed to show the two functions operating with and without...
Questions
question
Mathematics, 18.08.2019 10:30
question
Mathematics, 18.08.2019 10:30
question
Mathematics, 18.08.2019 10:30
question
Mathematics, 18.08.2019 10:30
question
Mathematics, 18.08.2019 10:30
question
Mathematics, 18.08.2019 10:30
question
Computers and Technology, 18.08.2019 10:30
question
Mathematics, 18.08.2019 10:30
Questions on the website: 13722363