Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Submit your BigInteger class files ( BigInteger . cpp and BigInteger.h ) and a screen shot of your class in action using the provided demo

Submit your BigInteger class files (BigInteger.cpp and BigInteger.h) and a screen shot of your class in action using the provided demo code. Do not alter the demo code in any way; I will be running your classes in my own copy anyway. The code must run to completion if you are to recieve any credit. If the demo code crashes, you get a zero.
If your class supports only addition, the maximum grade is 50%.
Addition and all six relational operators is worth 60%(D).
Pass the multiplication test to reach a grade of 70%(C).
Now we do some subtraction to try to get you to 80%(B).
For full credit, your class must support all five integer operations.
Note that once you have division, mod is basically free.
This means that if you don't implement some of the operations, your code must throw exceptions instead, so that the test program exits with at least some grace. Exiting with an exception is not considered a crash.
#include
#include
using namespace std;
class myException: public exception
{
private:
string s;
public:
virtual const char* what() const throw()// how you override the base class virtual method "what"
{
return s.c_str();
}
myException() : exception(){ s = "Default Message"; }// default constructor
myException(const string & Message) : exception(Message.c_str()){ s = Message; }// a custom constructor
};
int main(){
// using the built in exception classes
int n;
while(true){
try{
cout "Enter an integer (zero to exit). If it's less than zero an exception will be thrown." endl;
cin >> n;
if (n ==0){
break;
}
if (n 0){
logic_error le("Value less than zero!");
throw le;
}
else{
cout "You gave me " n endl;
}
}
catch(const logic_error & le){// always catch objects by const reference, not value
cout "I just caught an exception!" endl;
cout le.what() endl;
}
}
cout "Thank you for playing Exception Demo Phase One!" endl;
// you can throw (and catch) anything you want
while(true){
try{
cout "Enter an integer (zero to exit). If it's even an exception will be thrown." endl;
cin >> n;
if (n ==0){
break;
}
if (n %2==0){
throw n;
}
else{
cout "You gave me " n endl;
}
}
catch(int ne){// catching a value
cout "I just caught " ne " as an exception!" endl;
}
}
cout "Thank you for playing Exception Demo Phase Two!" endl;
// let's throw a reference to an int and change it
while(true){
bool exception_happened = false;
try{
cout "Enter an integer (zero to exit). If it's even an exception will be thrown and one will be added to the integer." endl;
cin >> n;
if (n ==0){
break;
}
if (n %2==0){
throw &n;
}
else{
cout "You gave me " n endl;
}
}
catch(int * ne){// catching a pointer to an int, deliberately not const as we're going to change it
cout "I just caught "*ne " as an exception!" endl;
++*ne; // this updates the value stored at the pointer ne
exception_happened = true;
}
if (exception_happened){
exception_happened = false;
cout "There was an exception, the value is now " n endl;
}
}
cout "Thank you for playing Exception Demo Phase Three!" endl;
// using our custom exception class, default throw
while(true){
bool exception_happened = false;
try{
cout "Enter an integer (zero to exit). If it's even a custom exception will be thrown." endl;
cin >> n;
if (n ==0){
break;
}
if (n %2==0){
throw myException();
// throw myException("Oh No!");
}
else{
cout "You gave me " n endl;
}
}
catch(const myException & me){
cout "The exception was " me.what() endl;
}
}
cout "Thank you for playing Exception Demo Phase Four!" endl;
return EXIT_SUCCESS;
}
image text in transcribed

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_2

Step: 3

blur-text-image_3

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

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

Explain the importance of HRM to all employees.

Answered: 1 week ago

Question

Discuss the relationship between a manager and an HR professional.

Answered: 1 week ago

Question

Outline demographic considerations.

Answered: 1 week ago