Skip to main content

Posts

Showing posts with the label / and % and perform the task accordingly

Write a program with class calculate that ask user to enter two numbers and any of the operators: +, -, *, / and % and perform the task accordingly. For example if an user enters numbers 2 & 5 and operator '+', a program should add 2 to 5 and display 7 as result. Use switch statement to make a selection among operators. Assume appropriate data members and member functions. With output and explanation.

 here's an example program with a class named Calculate that performs arithmetic operations based on user input: #include <iostream> using namespace std; class Calculate {     private:         double num1, num2;     public:         void getNumbers() {             cout << "Enter two numbers: ";             cin >> num1 >> num2;         }         void add() {             cout << "The sum is: " << num1 + num2 << endl;         }         void subtract() {             cout << "The difference is: " << num1 - num2 << endl;         }         void multiply() {             cout << "The product is: " <...