Create a new file (in Dev C++) and save it as lab10_XYZ.cpp (replace XYZ with your initials).In Lab 2, you created a menu for a simple calculator program.In Lab 6, you added some functionality based on the user selection.In Lab 7, you added some functionality for a main program loop and input validation.In this lab, you will create some general purpose functions to offload some of the tasks in main().Write functions for:displaying a message (void)display menu and return user selection (int)prompt user for a number and return the number (int)adding (void)subtracting (void)multiplying (void)dividing (void)checking if number is 0 (bool)Prototypes must be written for each function. Definitions for each function may be in any order, after main().Call functions as needed. Remember that functions can call other functions. If you see the same code repeating in different places, there is a good chance that a function could be used to simplify things. By now, you've gone through the thought process of how the main program loop works. Since the assignment is more about the use of functions, I'm providing a good bit of the main() function below. You will still need to determine arguments to use and how the parameters will be structured within each function. You may use the code below, or modify your existing code to use functions.SAMPLE MAIN PROGRAMint main(){bool flag = true;int choice;displayMessage("Hello, welcome to the calculator program!\n\n");while (flag){choice = menu();switch (choice){case ADD: add(); break;case SUB: subtract(); break;case MUL: multiply(); break;case DIV: divide(); break;case EX: flag = false; break;default: displayMessage("\nSorry, that was invalid\n"); break;}}displayMessage("\n\nProgram exiting. Goodbye!\n");return 0;}LANGUAGE IS C++Simple as possible PLEASE!

Question
Asked Oct 30, 2019

Create a new file (in Dev C++) and save it as lab10_XYZ.cpp (replace XYZ with your initials).

  • In Lab 2, you created a menu for a simple calculator program.
  • In Lab 6, you added some functionality based on the user selection.
  • In Lab 7, you added some functionality for a main program loop and input validation.

In this lab, you will create some general purpose functions to offload some of the tasks in main().

Write functions for:

  • displaying a message (void)
  • display menu and return user selection (int)
  • prompt user for a number and return the number (int)
  • adding (void)
  • subtracting (void)
  • multiplying (void)
  • dividing (void)
  • checking if number is 0 (bool)

Prototypes must be written for each function. Definitions for each function may be in any order, after main().

Call functions as needed. Remember that functions can call other functions. If you see the same code repeating in different places, there is a good chance that a function could be used to simplify things. By now, you've gone through the thought process of how the main program loop works. Since the assignment is more about the use of functions, I'm providing a good bit of the main() function below. You will still need to determine arguments to use and how the parameters will be structured within each function. You may use the code below, or modify your existing code to use functions.

SAMPLE MAIN PROGRAMint main()
{
bool flag = true;
int choice;

displayMessage("Hello, welcome to the calculator program!\n\n");

while (flag)
{
choice = menu();
switch (choice)
{
case ADD: add(); break;
case SUB: subtract(); break;
case MUL: multiply(); break;
case DIV: divide(); break;
case EX: flag = false; break;
default: displayMessage("\nSorry, that was invalid\n"); break;
}
}

displayMessage("\n\nProgram exiting. Goodbye!\n");
return 0;
}

LANGUAGE IS C++

Simple as possible PLEASE!

check_circleExpert Solution

C++ program

The code for calculator programs is

#include <iostream>

using namespace std;

void displayMessage(std::string msg);

int menu();

int getNum();

void add(int num1,int num2);

void subtract(int num1,int num2);

void multiply(int num1,int num2);

void divide(int num1,int num2);

bool isZero(int num);

int main()

{

bool flag=true;

int choice;

displayMessage("Hello, welcome to the calculator program!\n\n");

enum level {ADD = 1, SUB, MUL, DIV, EX};

while(flag)

{

int num1=getNum();

int num2=getNum();

choice=menu();

switch(choice)

{

case ADD: add(num1,num2);

break;

case SUB: subtract(num1,num2);

break;

case MUL: multiply(num1,num2);

break;

case DIV: divide(num1,num2);

break;

case EX:  flag=false;

break;

default:  displayMessage("\nSorry, that was invalid\n");

break;

}

}

displayMessage("\n\nProgram exiting. Goodbye!\n");

return 0;

}

void displayMessage(std::string msg)

{

cout<<msg<<endl;

}

int menu()

{

int menuchoice;

cout<<"1. Addition"<<endl;

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

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

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

cout<<"5. Exit Program\n"<<endl;

cout<<"Enter choice : ";

cin>>menuchoice;

return menuchoice;

}

int getNum()

{

int num;

cout<<"Enter number : ";

cin>>num;

return num;

}

void add(int num1,int num2)

{

cout<<"The sum of "<<num1<<" and "<<num2<<" : "<<(num1+num2)<<"\n"<<endl;

}

void su...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour*

See Solution
*Response times may vary by subject and question
Tagged in

Engineering

Computer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: Simplify the following functional expressions using Boolean algebra and its identities. List the ide...

A: (a) F(x,y,z) = y(x’ + (x + y)’)

question_answer

Q: I want to see how one can add 80 elements into an array without manually entering in each element.  ...

A: Given,The name of the first array is numberArray1 and the size of the array is 80.The name of the se...

question_answer

Q: PLEASE EXPLAIN ALL STEPS: simplify the boolean equations: xz + (xy + ~z) ~xyz + yz + x~y

A: 1)xz + (xy + ~z)For simplifying the Boolean expression, use Karnaugh Map and follow the below steps-...

question_answer

Q: First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ...

A: Program:  import java.util.Scanner; public class AtmSimDoLoop{public static void main(String[] args)...

question_answer

Q: Please explain how you solve the follwing problem:

A: a) CHAIN set for each variable:CHAIN(S) = {B, C, A}CHAIN(A) = {A}CHAIN(B) = {B}CHAIN(C) = {C, A}

question_answer

Q: Active Directory metadata describes the actual Active Directory data, not the Active Directory datab...

A: Active Directory:The Microsoft Technology used to manage computers and the other devices in a networ...

question_answer

Q: Explain pipelining and think of a real-world analogy to the concept as if you were explaining it to ...

A: Pipelining:Pipelining is the technique of dividing a sequential process into sub-processes, each sub...

question_answer

Q: for C++ write a progam for the greatest common divisor of integers x and y is the largest integer th...

A: program to find the greatest common divisor of x and y.if x is 0 then answer is y.if y is 0 then the...

question_answer

Q: in python program4_4.pyWrite a program that prompts the user to enter a series of strings, but with ...

A: Program code: