Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C Program: I need help writing this method! I have included the test classe below. METHOD ONE /** * assumes that op1 and op2 contain

C Program: I need help writing this method! I have included the test classe below.

METHOD ONE

/** * assumes that op1 and op2 contain 64 bit two's complement values * and returns true if an overflow would occur if they are summed * and false otherwise * * for example, addOverflow(0x8000000000000000, 0x8000000000000000) returns 1 * addOverflow(0x7fffffffffffffff, 0x7fffffffffffffff) returns 1 * addOverflow(0x8000000000000000, 0x7fffffffffffffff) returns 0 * * @param uint64_t op1 that is one of the operands of the addition * @param uint64_t op2 that is the other operand of the addition * @return true if op1 + op2 would result in an overflow assuming that op1 * and op2 contain 64-bit two's complement values * * RESTRICTIONS: You cannot use an if statement, ternary operator, switch statement * or any other conditional statement. However, you can use other * functions you have written and conditional expressions. For example, * return op1 != op2; * is allowed, but * if (op1 != op2) return true; * is not. The purpose of this restriction is to push you to write * "clean" code. */ bool Tools::addOverflow(uint64_t op1, uint64_t op2) { }

TEST

void addOverflowTests() { assert(Tools::addOverflow(0xffffffffffffffff, 0xffffffffffffffff) == false); assert(Tools::addOverflow(0x8000000000000000, 0x8000000000000000) == true);

/* * Add four more tests. You need to replace N, M, R, and S. * */

assert(Tools::addOverflow(1, N) == true); assert(Tools::addOverflow(1, M) == false); assert(Tools::addOverflow(-1, R) == true); assert(Tools::addOverflow(-1, S) == false);

}

For the last four tests here is the instructions....

addOverflowTests

When two positive numbers are added together, the result should also be positive or else an overflow occurred. Likewise, when two negative numbers are added together, the result should be negative or else an overflow occurred. The four tests you need to add are:

1) Add a test that calls addOverflow with the values 1 and N where N is the smallest positive number that can be added to 1 which will result in an overflow.

2) Add a test that calls addOverflow with the values 1 and M where M is the largest positive number that can be added to 1 which will not result in an overflow.

3) Add a test that calls addOverflow with the values -1 and R where R is the smallest magnitude negative number that can be added to -1 which will result in an overflow. (In other words, -1 + R causes an overflow, but -1 + (R + 1) does not.). R has a greater magnitude than R + 1 because it is further from 0.

4) Add a test that calls addOverflow with the values -1 and S where S is the largest magnitude negative number that can be added to -1 which will not result in an overflow. (In other words, -1 + S does not cause an overflow, but -1 + (S - 1) does.)

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

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago