Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write a C ++ program (using modular programming techniques) that can perform the following 6 operators for 2 numbers: N1 and N2. You need

Please write a C++ program (using modular programming techniques) that can perform the following 6 operators for 2 numbers: N1 and N2. You need to prompt the user to enter the first number, an operator, and the second number. Please see the sample test below to design your application program properly. This program is a calculator for users to play and enjoy. You must thank the user and stop your program when the operator (entered by the user) is @.

The 6 valid operators for this super calculator are as follows:

  1. + for addition of N1 and N2. Therefore, result = (N1 + N2).
  2. for subtraction of N2 from N1. Therefore, result = (N1 N2).
  3. * for multiplication of N1 with N2. Therefore, result = (N1 * N2).
  4. / for floating-point division of N1 by N2. If N2 is zero, please continue the loop asking user to

enter a non-zero value for N2 until you receive one. Then, result = (N1 / N2).

  1. ** for power N2 with base N1 (i.e., N1N2). Therefore, result = ( N1 ** N2 ).
  2. % for division remainder (i.e., modulus) of N1 by N2. If N2 is zero, please continue the loop

asking user to enter a non-zero value for N2 until you receive one. Then, result = ( N1 % N2 ).

  1. @ for stopping the calculator game. You must thank the user before leaving this program.
  2. Otherwise, please continue the loop asking user to enter a valid operator until you receive one. Then, apply the operator to N1 and N2 to show the result.

===========================================================================.

Modular Programming Techniques: Please define the following functions for your main program to call.

  1. Add( N1, N2)
  2. Subtract (N1, N2)
  3. Multiply (N1, N2)
  4. Divide (N1, N2)
  5. Power (N1, N2)
  6. Modulus (N1, N2)
  7. GetValidOp (N1, N2) : get a valid operator, and then call one of the above 6 functions.

===========================================================================.

The following is a sample standard test, which must be your test case #1. test case must cover all 6 valid operators (at least once for each) plus an invalid one.

Welcome to the program of "your name" !!!

Enter your first number: 10

Enter your operator: +

Enter your second number: 90

Result: 10.0 + 90.0 = 100.0

Enter your first number: 55

Enter your operator: -

Enter your second number: 49.5

Result: 55.0 - 49.5 = 5.5

Enter your first number: 12

Enter your operator: *

Enter your second number: 55

Result: 12.0 * 55.0 = 660.0

Enter your first number: 99

Enter your operator: /

Enter your second number: 0

Enter your second number which cannot be zero: 0.0

Enter your second number which cannot be zero: 0.

Enter your second number which cannot be zero: 7

Result: 99.0 / 7.0 = 14.1429

Enter your first number: 99

Enter your operator: /

Enter your second number: 8

Result: 99.0 / 8.0 = 12.375

Enter your first number: 2

Enter your operator: **

Enter your second number: 12

Result: 2.0 ** 12.0 = 4096.0

Enter your first number: 99

Enter your operator: %

Enter your second number: 0

Enter your second number which cannot be zero: 0.

Enter your second number which cannot be zero: 0.00

Enter your second number which cannot be zero: 7

Result: 99.0 % 7.0 = 1.0

Enter your first number: 99

Enter your operator: %

Enter your second number: 8

Result: 99.0 % 8.0 = 3.0

Enter your first number: 99

Enter your operator: \

Enter your second number: 5

Enter a valid operator: ^

Enter a valid operator: ~

Enter a valid operator: %

Result: 99.0 % 5.0 = 4.0

Enter your first number: 0

Enter your operator: @

Enter your second number: 0

Thank you for using program designed by "you"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Are human errors in thinking and decisionmaking predictable?

Answered: 1 week ago