a) How can create the equivalents of a four-function calculator. The program should request the user to enter a number, an operator, and another number. (Use floating point). It should then carry out the specified arithmetical operation: adding, subtracting, multiplying, or dividing the two numbers. Use switch case statement to select the operation. Finally display the result.
When it finishes the calculation, the program should ask if the user wants to do another calculation. The response can be ‘y’ or ‘n’.
Sample Output
Some sample interaction with the program might look like this:
Enter first number, operator, second number: 10/3
Answer: 3.33333
Do another (y/n)?y
Enter first number, operator, second number: 12+100
Answer: 112
Do another (y/n)?n
b) Write C++ code to replace two variables A and B with each other.
Given A=2, B=1, you need to swap the values of A and B without using any third variable.
Sample Output
A =2
B=1
After swapping
A=1
B=2
2006-10-18
10:53:27
·
4 answers
·
asked by
Anonymous
in
Computers & Internet
➔ Programming & Design