Question

SEE THE Q3 for actual question, The first Two are Q1 and Q2 answers . Q1...

SEE THE Q3 for actual question, The first Two are Q1 and Q2 answers .

Q1

#include<iostream>
using namespace std;
// add function that add two numbers
void add(){
   int num1,num2;
   cout << "Enter two numbers "<< endl;
   cout << "First :";
   cin >> num1;
   cout << "Second :";
   cin >>num2;
   int result=num1+num2;
   cout << "The sum of " << num1 << " and "<< num2 <<" is = "<< result;
   return;
}
// subtract function that subtract two numbers
void subtract(){
   int num1,num2;
   cout << "Enter two numbers "<< endl;
   cout << "First :";
   cin >> num1;
   cout << "Second :";
   cin >>num2;
   int result=num1-num2;
   cout << "The subtract of " << num1 << " and "<< num2 <<" is = "<< result;
   return;
}
// multiply function that multiply two numbers
void multiply(){
   int num1,num2;
   cout << "Enter two numbers "<< endl;
   cout << "First :";
   cin >> num1;
   cout << "Second :";
   cin >>num2;
   int result=num1*num2;
   cout << "The multipication of " << num1 << " and "<< num2 <<" is = "<< result;
   return;
}

// divide function that divide two numbers
void divide(){
   int num1,num2;
   cout << "Enter two numbers "<< endl;
   cout << "First :";
   cin >> num1;
   cout << "Second :";
   cin >>num2;
   if(num2 ==0){// check denominator is zero or not
       cout << "Denominator can not be zero. Please enter the valid denominator "<< endl;
       cin >> num2;// if zero then ask valid denominator from user
   }
   float result=num1/num2;
   cout << "The division of " << num1 << " and "<< num2 << " is = "<< result;
   return;
}
//main function
int main(){
   cout << "Hello" << endl;//hello message
   cout << "======================================================================="<<endl;
   cout << "Menu "<< endl;//menu
   cout << "======================================================================="<<endl;
   cout << "a/A To add two numbers "<< endl;
   cout << "b/B To subtract two numbers "<< endl;
   cout << "c/C To multiply two numbers "<< endl;
   cout << "d/D To divide two numbers "<< endl;
   cout << "x/X Exit "<< endl;
   cout << "======================================================================="<<endl;
   char ch;
   cin >> ch;// taking options from user
   switch(ch){
       case 'a' : add();
                   break;
        case 'A' : add();
                   break;
       case 'b' : subtract();
                   break;
        case 'B' : subtract();
                   break;
       case 'c' : multiply();
                   break;
        case 'C' : multiply();
                   break;              
       case 'd' : divide();
                   break;
        case 'D' : divide();
                   break;
       case 'x' : cout << "Good Bye " << endl;
                          return 0;
        case 'X' : cout << "Good Bye " << endl;
                          return 0;
       default: cout << "Error: Invalid option "<< endl;// if invalid options
   }
return 0;                          
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

Q 2

#include<iostream>
using namespace std;
// add function that add two numbers
void add(){
   int num1,num2;
   cout << "Enter two numbers "<< endl;
   cout << "First :";
   cin >> num1;
   cout << "Second :";
   cin >>num2;
   int result=num1+num2;
   cout << "The sum of " << num1 << " and "<< num2 <<" is = "<< result<< endl;
   cout << "======================================================================="<<endl;
   return;
}
// subtract function that subtract two numbers
void subtract(){
   int num1,num2;
   cout << "Enter two numbers "<< endl;
   cout << "First :";
   cin >> num1;
   cout << "Second :";
   cin >>num2;
   int result=num1-num2;
   cout << "The subtract of " << num1 << " and "<< num2 <<" is = "<< result<< endl;
   cout << "======================================================================="<<endl;
   return;
}
// multiply function that multiply two numbers
void multiply(){
   int num1,num2;
   cout << "Enter two numbers "<< endl;
   cout << "First :";
   cin >> num1;
   cout << "Second :";
   cin >>num2;
   int result=num1*num2;
   cout << "The multipication of " << num1 << " and "<< num2 <<" is = "<< result<<endl;
   cout << "======================================================================="<<endl;
   return;
}

// divide function that divide two numbers
void divide(){
   int num1,num2;
   cout << "Enter two numbers "<< endl;
   cout << "First :";
   cin >> num1;
   cout << "Second :";
   cin >>num2;
   if(num2 ==0){// check denominator is zero or not
       cout << "Denominator can not be zero. Please enter the valid denominator "<< endl;
       cin >> num2;// if zero then ask valid denominator from user
   }
   float result=num1/num2;
   cout << "The division of " << num1 << " and "<< num2 << " is = "<< result<< endl;
   cout << "======================================================================="<<endl;
  
   return;
}
//main function
int main(){
   cout << "Hello" << endl;//hello message
   cout << "======================================================================="<<endl;
   cout << "Menu "<< endl;//menu
   cout << "======================================================================="<<endl;
   cout << "a/A To add two numbers "<< endl;
   cout << "b/B To subtract two numbers "<< endl;
   cout << "c/C To multiply two numbers "<< endl;
   cout << "d/D To divide two numbers "<< endl;
   cout << "x/X Exit "<< endl;
   cout << "======================================================================="<<endl;
  
   char ch;
   cin >> ch;// taking options from user
   while(ch!='x'||ch!='X'){
      
       switch(ch){
           case 'a' : add();
                       break;
            case 'A' : add();
                       break;
           case 'b' : subtract();
                       break;
            case 'B' : subtract();
                       break;
           case 'c' : multiply();
                       break;
            case 'C' : multiply();
                       break;              
           case 'd' : divide();
                       break;
            case 'D' : divide();
                       break;
           case 'x' : cout << "Good Bye " << endl;
                              return 0;
            case 'X' : cout << "Good Bye " << endl;
                              return 0;
           default: cout << "Error: Invalid option "<< endl;// if invalid options
       }
   cout << endl;
    cin >> ch;
}
return 0;                          
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Question 3

Create a new file (in Dev C++) and save it

Modify the program written for Q2 to use functions. All other criteria from Q1 and Q2 must still be met in Q34. Also, add a new menu option for modulus (%).

SUGGESTED FUNCTIONS (some or all of these functions may be used; additional ones may be used if desired):

  • getMenuChoice() - presents menu and prompts for choice; returns valid menu choice
  • getNumber() - prompts user for numeric input
  • displayMessage() - displays hello/goodbye/error message
  • add() - adds two numbers and displays result
  • subtract() - subtracts two numbers and displays result
  • multiply() - multiplies two numbers and displays result
  • divide() - divides two numbers and displays result
  • modulus() - divides two integers and displays remainder as result
  • displayResult() - displays result of an operation
0 0
Add a comment Improve this question Transcribed image text
Answer #1

/***********************Q3.cpp*******************************/

#include<iostream>
using namespace std;
void getMenuChoice(){
  
cout << "Hello" << endl;//hello message
cout << "======================================================================="<<endl;
cout << "Menu "<< endl;//menu
cout << "======================================================================="<<endl;
cout << "a/A To add two numbers "<< endl;
cout << "b/B To subtract two numbers "<< endl;
cout << "c/C To multiply two numbers "<< endl;
cout << "d/D To divide two numbers "<< endl;
cout << "m/M To modulus two numbers "<<endl;
cout << "x/X Exit "<< endl;
cout << "======================================================================="<<endl;
  
}
// add function that add two numbers
void add(){
int num1,num2;
cout << "Enter two numbers "<< endl;
cout << "First :";
cin >> num1;
cout << "Second :";
cin >>num2;
int result=num1+num2;
cout << "The sum of " << num1 << " and "<< num2 <<" is = "<< result<< endl;
cout << "======================================================================="<<endl;
getMenuChoice();
return;
}
// subtract function that subtract two numbers
void subtract(){
int num1,num2;
cout << "Enter two numbers "<< endl;
cout << "First :";
cin >> num1;
cout << "Second :";
cin >>num2;
int result=num1-num2;
cout << "The subtract of " << num1 << " and "<< num2 <<" is = "<< result<< endl;
cout << "======================================================================="<<endl;
getMenuChoice();
return;
}
// multiply function that multiply two numbers
void multiply(){
int num1,num2;
cout << "Enter two numbers "<< endl;
cout << "First :";
cin >> num1;
cout << "Second :";
cin >>num2;
int result=num1*num2;
cout << "The multipication of " << num1 << " and "<< num2 <<" is = "<< result<<endl;
cout << "======================================================================="<<endl;
getMenuChoice();
return;
}

// divide function that divide two numbers
void divide(){
int num1,num2;
cout << "Enter two numbers "<< endl;
cout << "First :";
cin >> num1;
cout << "Second :";
cin >>num2;
if(num2 ==0){// check denominator is zero or not
cout << "Denominator can not be zero. Please enter the valid denominator "<< endl;
cin >> num2;// if zero then ask valid denominator from user
}
float result=num1/num2;
cout << "The division of " << num1 << " and "<< num2 << " is = "<< result<< endl;
cout << "======================================================================="<<endl;
getMenuChoice();
  
return;
}
void calModulus(){
int num1,num2;
cout << "Enter two numbers "<< endl;
cout << "First :";
cin >> num1;
cout << "Second :";
cin >>num2;
int result=num1%num2;
cout << "The modulus of " << num1 << " and "<< num2 <<" is = "<< result<<endl;
cout << "======================================================================="<<endl;
getMenuChoice();
return;
}

//main function
int main(){

getMenuChoice();
char ch;
cin >> ch;// taking options from user
while(ch!='x'||ch!='X'){
  
switch(ch){
case 'a' : add();
break;
   case 'A' : add();
break;
case 'b' : subtract();
break;
case 'B' : subtract();
break;
case 'c' : multiply();
break;
case 'C' : multiply();
break;
case 'd' : divide();
break;
case 'D' : divide();
break;
case 'm' : calModulus();
           break;
case 'M' : calModulus();
           break;
case 'x' : cout << "Good Bye " << endl;
return 0;
case 'X' : cout << "Good Bye " << endl;
return 0;
default: cout << "Error: Invalid option "<< endl;// if invalid options
}
cout << endl;
cin >> ch;
}
return 0;
}

/**************************output****************************/

Hello
=======================================================================
Menu
=======================================================================
a/A To add two numbers
b/B To subtract two numbers
c/C To multiply two numbers
d/D To divide two numbers
m/M To modulus two numbers
x/X Exit
=======================================================================
m
Enter two numbers
First :12
Second :4
The modulus of 12 and 4 is = 0
=======================================================================
Hello
=======================================================================
Menu
=======================================================================
a/A To add two numbers
b/B To subtract two numbers
c/C To multiply two numbers
d/D To divide two numbers
m/M To modulus two numbers
x/X Exit
=======================================================================

m
Enter two numbers
First :13
Second :2
The modulus of 13 and 2 is = 1
=======================================================================
Hello
=======================================================================
Menu
=======================================================================
a/A To add two numbers
b/B To subtract two numbers
c/C To multiply two numbers
d/D To divide two numbers
m/M To modulus two numbers
x/X Exit
=======================================================================

x
Good Bye
D:Filelcal.exe Hello enu a/A To add two numbers b/B To subtract two numbers c/C To multiply two numbers d/D To divide two num

Select DAFilelcal.exe Enter two numbers First :13 Second:2 The modulus of 13 and 2 is = 1 Hello enu a/A To add two numbers b/

Thanks a lot, Please let me know if you have any problem....................

Add a comment
Know the answer?
Add Answer to:
SEE THE Q3 for actual question, The first Two are Q1 and Q2 answers . Q1...
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
  • #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int...

    #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int num1, num2, result; while(ch == 'Y'){ cout << "Enter first number: "; cin >> num1; while(1){//for handling invalid inputs if(cin.fail()){ cin.clear();//reseting the buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');//empty the buffer cout<<"You have entered wrong input"<<endl; cout << "Enter first number: "; cin >> num1; } if(!cin.fail()) break; } cout << "Enter second number: "; cin >> num2; while(1){ if(cin.fail()){ cin.clear(); cin.ignore(numeric_limits<streamsize>::max(),'\n'); cout<<"You have entered wrong input"<<endl; cout <<...

  • Redo Programming Exercise 7 of Chapter 7 so that your program handles exceptions such as division...

    Redo Programming Exercise 7 of Chapter 7 so that your program handles exceptions such as division by zero and invalid input. Your program should print Denominator must be nonzero and reprompt for a valid denominator when 0 is entered for a denominator. Please specify what should go in the divisionByZero.h file and the changes made to main.cpp Please provide output. Thank you in advance! main.cpp so far #include <iostream> using namespace std; void addFractions(int num1, int num2, int den1, int...

  • I'm kind of new to programming, and I am having trouble figuring out why my program...

    I'm kind of new to programming, and I am having trouble figuring out why my program isn't running. Below is the code that I wrote for practice. I will comment where it says the error is. So the error that I'm getting is "error: no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' ". I'm not sure why I'm getting this because I added the library <iostream> at the top. Thank you. Code: #include <iostream> using namespace std; class...

  • Could someone re-write this code so that it first prompts the user to choose an option...

    Could someone re-write this code so that it first prompts the user to choose an option from the calculator (and catches if they enter a string), then prompts user to enter the values, and then shows the answer. Also, could the method for the division be rewritten to catch if the denominator is zero. I have the bulk of the code. I am just having trouble rearranging things. ------ import java.util.*; abstract class CalculatorNumVals { int num1,num2; CalculatorNumVals(int value1,int value2)...

  • This question is about C++! Honestly, I'm not sure what I am doing right or wrong....

    This question is about C++! Honestly, I'm not sure what I am doing right or wrong. Using just functions, nothing else, I am trying to create a program that uses nothing but functions to take in two fractions, add these fractions, divide these fractions, and then display the simplified fraction all from within a menu. I would very much appreciate any leads, aid, or description on what I've done right and wrong. Thanks! #include <iostream> using namespace std; //Description: Function...

  • Fix this code so only the function prototype comes before main. #include <iostream> using namespace std;...

    Fix this code so only the function prototype comes before main. #include <iostream> using namespace std; bool isMultiple(int num1, int num2) { return num1 % num2 == 0; } int main() { char ch = 'Y'; int num1, num2; while(ch =='Y') // While ch is equal to Y { cout << "Enter two numbers(largest first): "; cin >> num1; // Getting 1st number cin >> num2; // Getting 2nd number if(isMultiple(num1, num2)) cout << num2 << " " << "IS...

  • C++ problem where should I do overflow part? in this code do not write a new...

    C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...

  • Can sombody tell me what wrong for this code to work?? It is c++ btw. thanks!...

    Can sombody tell me what wrong for this code to work?? It is c++ btw. thanks! #include <iostream> #include <string> using namespace std; double op1; double op2; string ADD; string SUBTRACT; string MULTIPLY; string DIVIDE; string selection; string multiply; string divide; string add; string subtract; string "*"; string "+"; string "-"; string "/"; int main() { do { cout << "--------WELCOME TO THE CALCULATOR----------" << endl; cout << "Enter your first operand: "; cin >> op1; cout << "Enter your...

  • So far your TestEqual functions have tested values but haven't made any changes... Q: If you...

    So far your TestEqual functions have tested values but haven't made any changes... Q: If you changed one of the variable values in your function, would it change the value of the variable in main? Why? Q: What are the two options for passing parameters into a function? (by _________ and by __________) What's the difference? Write a new function, MakeEqual, that takes two integers and if they are not equal (tested using your TestEqual function), displays a message and...

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
ADVERTISEMENT