Skip to content

Commit 7469601

Browse files
author
Anika
committed
Add calculator.cpp with basic operations
1 parent ddab38b commit 7469601

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Calculator.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
class Calculator {
5+
public:
6+
int add(int a, int b) { return a + b; }
7+
int subtract(int a, int b) { return a - b; }
8+
int multiply(int a, int b) { return a * b; }
9+
double divide(int a, int b) {
10+
if (b == 0) {
11+
cout << "Error: Division by zero!" << endl;
12+
return 0;
13+
}
14+
return (double)a / b;
15+
}
16+
};
17+
18+
// Example usage
19+
int main() {
20+
Calculator calc;
21+
cout << "Add: " << calc.add(5, 3) << endl;
22+
cout << "Subtract: " << calc.subtract(5, 3) << endl;
23+
cout << "Multiply: " << calc.multiply(5, 3) << endl;
24+
cout << "Divide: " << calc.divide(5, 3) << endl;
25+
return 0;
26+
}
27+

0 commit comments

Comments
 (0)