Modify the attached code: Create a new class called CalculatorWithMod. This class should be a sub class of the base class Calculator. This class should also have an additional method for calculating the modulo. The modulo method should only be seen at the sub class, and not the base class! Include exception handling for instances when dividing by 0 or calculating the modulo with 0. You would need to use throw, try, and catch. The modulo (or "modulus" or "mod") is the remainder after dividing one number by another. Example: 20 mod 3 equals 2 Because 20/3 = 6 with a remainder of 2 Refer also to the attached sample outputs:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Modify the attached code:

  • Create a new class called CalculatorWithMod. This class should be a sub class of the base class Calculator. This class should also have an additional method for calculating the modulo. The modulo method should only be seen at the sub class, and not the base class!
  • Include exception handling for instances when dividing by 0 or calculating the modulo with 0. You would need to use throw, try, and catch.

The modulo (or "modulus" or "mod") is the remainder after dividing one number by another.

Example: 20 mod 3 equals 2
Because 20/3 = 6 with a remainder of 2

Refer also to the attached sample outputs:

#include <iostream>
using namespace std;
class Calculator{
public:
calculator (){
cout << "Welcome to my Calculator" << '\n';
}
int addition(int a, int b);
int subtraction(int a, int b);
int multiplication(int a, int b);
float division(int a, int b);
};
int Calculator::addition(int a, int b){
return (a+b);
}
int Calculator::subtraction(int a, int b){
return (a-b);
}
int Calculator::multiplication(int a, int b){
return (a*b);
}
float Calculator::division(int a, int b){
return (a*1.0/b);
}
int main(){
Calculator myCalculator; //change the class name to CalculatorWithMod when
you finish your modifications
int x, y;
cout << "Input 1st integer: ";
cin >> x;
cout << "Input 2nd integer: ";
cin >> y;
cout << "The sum is "
« myCalculator.addition(x, y) <« '\n';
« myCalculator.subtraction(x, y) << '\n';
cout <« "The product is " « myCalculator.multiplication(x, y) << '\n';
< myCalculator.division(x,y) << '\n';
<< myCalculator.modulo(x,y) << '\n'; //uncomment
cout << "The difference is "
cout << "The quotient is "
//cout << "The modulo is "
this when you finish your modifications
return 0;
}
Transcribed Image Text:#include <iostream> using namespace std; class Calculator{ public: calculator (){ cout << "Welcome to my Calculator" << '\n'; } int addition(int a, int b); int subtraction(int a, int b); int multiplication(int a, int b); float division(int a, int b); }; int Calculator::addition(int a, int b){ return (a+b); } int Calculator::subtraction(int a, int b){ return (a-b); } int Calculator::multiplication(int a, int b){ return (a*b); } float Calculator::division(int a, int b){ return (a*1.0/b); } int main(){ Calculator myCalculator; //change the class name to CalculatorWithMod when you finish your modifications int x, y; cout << "Input 1st integer: "; cin >> x; cout << "Input 2nd integer: "; cin >> y; cout << "The sum is " « myCalculator.addition(x, y) <« '\n'; « myCalculator.subtraction(x, y) << '\n'; cout <« "The product is " « myCalculator.multiplication(x, y) << '\n'; < myCalculator.division(x,y) << '\n'; << myCalculator.modulo(x,y) << '\n'; //uncomment cout << "The difference is " cout << "The quotient is " //cout << "The modulo is " this when you finish your modifications return 0; }
Input 1st integer: 12
Input 2nd integer: -5
Input 1st integer: 5
Input 2nd integer: 0
The sum is 7
The sum is 5
The difference is 17
The difference is 5
The product is -60
The quotient is -2.4
The modulo is 2
The product is 0
Division by zero! Answer is undefined...
Modulo by zero! Answer is undefined...
Process exited after 6.722 seconds with return value 0
Process exited after 1.854 seconds with return value 0
Press any key to continue
Press any key to continue .
Transcribed Image Text:Input 1st integer: 12 Input 2nd integer: -5 Input 1st integer: 5 Input 2nd integer: 0 The sum is 7 The sum is 5 The difference is 17 The difference is 5 The product is -60 The quotient is -2.4 The modulo is 2 The product is 0 Division by zero! Answer is undefined... Modulo by zero! Answer is undefined... Process exited after 6.722 seconds with return value 0 Process exited after 1.854 seconds with return value 0 Press any key to continue Press any key to continue .
Expert Solution
steps

Step by step

Solved in 4 steps with 6 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education