C++ Online Compiler
Example: C++ Program to Perform Arithmetic Operations using Objects and Classes
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ Program to Perform Arithmetic Operations using Objects and Classes #include <bits/stdc++.h> using namespace std; class ArithmeticOperations { public: void Sum(int a, int b) { int sum = a + b; cout << "SUM " << a << " + " << b << " = " << sum << "\n"; } void Difference(int a, int b) { int sub = a - b; cout << "DIFFERENCE " << a << " - " << b << " = " << sub << "\n"; } void Multiplication(int a, int b) { int mul = a * b; cout << "PRODUCT " << a << " * " << b << " = " << mul << "\n"; } void Quotient(int a, int b) { float div = (float)a / b; cout << "QUOTIENT " << a << " / " << b << " = " << div << "\n"; } void Modules(int a, int b) { int mod = a % b; cout << "MODULUS " << a << " % " << b << " = " << mod << "\n"; } }; // It's the driver function int main() { int p, q; cout << "Enter any two numbers:\n"; cin >> p >> q; // To make the instances of `ArithmeticOperations` class ArithmeticOperations AO; // It will print the final output of all arithmetic operations cout << endl; AO.Sum(p, q); AO.Difference(p, q); AO.Multiplication(p, q); AO.Quotient(p, q); AO.Modules(p, q); return 0; }
12 15
Output
Clear
ADVERTISEMENTS