overflow.cpp Integers can only hold positive values up to several billion before
ID: 667507 • Letter: O
Question
overflow.cpp
Integers can only hold positive values up to several billion before they overflow. Write a program to explore this concept. Your program should not ask for input, instead it should do integer computations with numbers that you choose, and then produce output. Use code and experimentation to demonstrate the following ideas and place a short report in the title comments of your program:
Show that adding together two large integers will result in overflow that is easy to detect, and explain how to detect it in your report.
Show that multiplying together two large integers will also result in overflow, but that it can be harder to detect.
Speculate how you might detect overflow after multiplication, write about it in your report, and try it in your code.
Unlike the previous four programs, this one gives the student a lot of freedom. No two overflow.cpp programs submitted in CS 1410 should be the same.Therefore, it is the programmer's responsibility to display computed values to the user with very clear messages. The user should not have to work hard to understand your experiment, they should simply run your program and see informative output that demonstrates the three ideas above.
Don't forget to include a report discussing each of the above ideas in the title comments of your program.
Explanation / Answer
#include #include using namespace std; int sum(int, int); int sub(int, int); int product(int, int); int division(int, int); int remainder(int, int); int main() { int a, b, result; char operation; try { cout > a; if (!cin) { throw overflow_error("input overflow"); } else { cout > b; if (!cin) { throw overflow_error("input overflow"); } else { cout > operation; } } } catch (overflow_error &overflow) { coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.