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

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

Create a flowchart and modify the code.

 

INSTRUCTION:

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

 

CODE TO COPY:

#include <iostream>


using namespace std;


class Calculator{
public:
Calculator(){
printf("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;


printf("Input 1st integer: ");
scanf("%d",&x);
printf("Input 2nd integer: ");
scanf("%d",&y);


printf("The sum is %d \n", myCalculator.addition(x,y));
printf("The difference is %d \n", myCalculator.subtraction(x,y));
printf("The product is %d \n", myCalculator.multiplication(x,y));
printf("The quotient is %d \n", myCalculator.division(x,y));


return 0;


}

 

I have attached the sample output

Input 1st integer: 12
Input 2nd integer: -5
The sum is 7
The difference is 17
The product is -60
The quotient is -2.4
The modulo is 2
Process exited after 6.722 seconds with return value 0
Press any key to continue..
%3D
Transcribed Image Text:Input 1st integer: 12 Input 2nd integer: -5 The sum is 7 The difference is 17 The product is -60 The quotient is -2.4 The modulo is 2 Process exited after 6.722 seconds with return value 0 Press any key to continue.. %3D
Input 1st integer: 5
Input 2nd integer: 0
The sum is 5
The difference is 5
The product is e
Division by zero! Answer is undefined...
Modulo by zero! Answer is undefined...
Process exited after 1.854 seconds with return value 0
Press any key to continue
Transcribed Image Text:Input 1st integer: 5 Input 2nd integer: 0 The sum is 5 The difference is 5 The product is e Division by zero! Answer is undefined... Modulo by zero! Answer is undefined... Process exited after 1.854 seconds with return value 0 Press any key to continue
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Exception Handling Keywords
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
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