Question

Problem 9: (20 Points) Write a CH program to implement sum, subtraction, multiplication and division operations of two number

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;

float sum(float x, float y){

return x+y;

}

float subtract(float x, float y){

return x-y;

}

float multiply(float x, float y){

return x*y;

}

float divide(float x, float y){

return x/y;

}

int main() {

  

  while(true){

   cout << "Enter your choice: " << endl;

   cout << "1. Sum" << endl;

   cout << "2. Subtraction" << endl;

   cout << "3. Multiplication" << endl;

   cout << "4. Division" << endl;

   cout << "0. quit" << endl;

  

   int choice;

float x, y;

   cin >> choice;

   switch(choice){

   case 1:

   cout << "Enter 2 nubmers: " << endl;

   cin >> x >> y;

   cout << sum(x, y) << endl;

   break;

   case 2:

   cout << "Enter 2 nubmers: " << endl;

   cin >> x >> y;

   cout << subtract(x, y) << endl;

   break;

   case 3:

   cout << "Enter 2 nubmers: " << endl;

   cin >> x >> y;

   cout << multiply(x, y) << endl;

   break;

   case 4:

   cout << "Enter 2 nubmers: " << endl;

   cin >> x >> y;

   cout << divide(x, y) << endl;

   break;

   case 0:

   cout << "quit!" << endl;

   return 0;

   }

  }

  return 0;

}

} 8 } } main.cpp saved 1 #include <iostream> 2 using namespace std; 3 4 float sum( float x, float y){ 5 | return x+y; 6 7 flo30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 int choice; float x, y; cin >> cEnter your choice: 1. Sum 2. Subtraction 3. Multiplication 4. Division 0. quit 1 Enter 2 nubmers: 2 4.5 6.5 Enter your choiceEnter your choice: 1. Sum 2. Subtraction 3. Multiplication 4. Division 0. quit 4 Enter 2 nubmers: 2 4 0.5 Enter your choice:

***********************************************************************************************************

Please upvote the answer. It will encourage me to answer more questions and it will be very helpful to me. Thank You.

***********************************************************************************************************

Add a comment
Know the answer?
Add Answer to:
Problem 9: (20 Points) Write a CH program to implement sum, subtraction, multiplication and division operations...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • usingc++ 1. Write a program to find the Sum(), Subtraction(), Multiplication(), Division() operations using Switch statement....

    usingc++ 1. Write a program to find the Sum(), Subtraction(), Multiplication(), Division() operations using Switch statement. For Division operation, please include denominator equals to zero check.

  • Using c++.. 1. Write a program to find the sum(), Subtraction(), Multiplication(), Division() operations using Switch...

    Using c++.. 1. Write a program to find the sum(), Subtraction(), Multiplication(), Division() operations using Switch statement and functions. 2. Write a program to find the summation of N numbers. Use two functions. One function will take the input from user and the other will perform the summation from 1 to N. 3. Write a program to find the factorial of a number. Use two functions. One function will take the input from user and the other will perform the...

  • Problem 3 (35) Design a calculator that performs four operations: addition, multiplication, division and subtraction with...

    Problem 3 (35) Design a calculator that performs four operations: addition, multiplication, division and subtraction with 2 integer type numbers a) Ask user what type of operation to perform (+, , * or/) a. If the user inputs 'none' then the program terminates. Otherwise it will keep continuing the calculation. (hint: use while) b) Ask user to provide 2 integer number inputs c) Perform operation (whatever operation they mentioned in a) d) Print result e) In division operation, perform a...

  • A Simple Calculator Summary: Write a console program (character based) to do simple calculations (addition, subtraction,...

    A Simple Calculator Summary: Write a console program (character based) to do simple calculations (addition, subtraction, multiplication and division) of two numbers, using your understanding of Java. Description: You need to write a program that will display a menu when it is run. The menu gives five choices of operation: addition, subtraction, multiplication, division, and a last choice to exit the program. It then prompts the user to make a choice of the calculation they want to do. Once the...

  • The matrix operations that you should include are Addition, Subtraction and Multiplication. The driver can be...

    The matrix operations that you should include are Addition, Subtraction and Multiplication. The driver can be as simple as asking the user to enter two matrices and then presenting a simple menu that allows the user to select the operation they want to test. Have the menu in a loop so that the user can test any other operation unless they choose to exit the menu. Also, provide the user an option to select two new matrices. Make sure that...

  • Write a Python Program that displays repeatedly a menu as shown in the sample run below....

    Write a Python Program that displays repeatedly a menu as shown in the sample run below. The user will enter 1, 2, 3, 4 or 5 for choosing addition, substation, multiplication, division or exit respectively. Then the user will be asked to enter the two numbers and the result for the operation selected will be displayed. After an operation is finished and output is displayed the menu is redisplayed, you may choose another operation or enter 5 to exit the...

  • Create a web page that will help students practice math - Addition, Subtraction, Multiplication and Division....

    Create a web page that will help students practice math - Addition, Subtraction, Multiplication and Division. The page should generate and display a math problem using 2 random numbers from 1 to 12. Addition: [1 - 12] + [1 - 12] = [2 - 24]<-Calculated Subtraction: [2 - 24]<-Calculated - [1 - 12] = [1 - 12] Multiplication: [1 - 12] * [1 - 12] = [1 - 144]<-Calculated Division: [1 - 144]<-Calculated / [1 - 12] = [1 -...

  • Write a C++ Program that simulates a basic calculator using functions which performs the operations of...

    Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero) Display a menu for list of operations that can be calculated and get the input from user about his choice of calculation. Based on user choice of operation, take the input of number/numbers from user. Assume all input values are of type double. Calculations must be...

  • Write a C++ Program that simulates a basic calculator using functions which performs the operations of...

    Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero) Display a menu for the list of operations that can be calculated and get the input from the user about his choice of calculation. Based on user choice of operation, take the input of number/numbers from user. Assume all input values are of type double. Calculations...

  • Write a C program to implement matrix multiplication operations. First, you need to prompt the user...

    Write a C program to implement matrix multiplication operations. First, you need to prompt the user for the size of both matrix. Then take inputs for both matrices and perform matrix multiplication operation. Finally, print the resulting matrix into the output.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT