Answer to Question #225412 in C for khalid

Question #225412

Suppose a company “ABC” is conducting a test to hire you as OOP Developer and asked you develop a calculator for the basic Arithmetic operators (+, -, *, /, %), where you have to deal at least 11 digit numbers. The numbers can be of with decimal point or without decimal point. The company wants you to develop an efficient code. You can choose any of the following options to develop this whole scenario:


  •       Function Overloading            
  •      Class Template

You have to answer, which option will you choose and arguments in favour of your chosen option regarding code efficiency, code complexity and other factors.



1
Expert's answer
2021-08-12T06:18:03-0400
#include <stdio.h>
int main() {
  char op;
  double num1, num2;
  printf("Enter an operator (+, -, *, /): ");
  scanf("%c", &op);
  printf("Enter two operands: ");
  scanf("%lf %lf", &num1, &num2);


  switch (op) {
    case '+':
      printf("%.1lf + %.1lf = %.1lf", num1, num2, num1 + num2);
      break;
    case '-':
      printf("%.1lf - %.1lf = %.1lf", num1, num2, num1 - num2);
      break;
    case '*':
      printf("%.1lf * %.1lf = %.1lf", num1, num2, num1 * num2);
      break;
    case '/':
      printf("%.1lf / %.1lf = %.1lf", num1, num2, num1 / num2);
      break;
    default:
      printf("Error");
  }


  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS