Question

In: Computer Science

Instructions for C++ project This Assignment will Focus on Software Engineering: Using Functions in a Menu...

Instructions for C++ project

This Assignment will Focus on Software Engineering: Using Functions in a Menu Driven Program

Hint: Chapter 6 Program 6-10 is a great example of this type of programs.

Your Task: Write a calculator Program with following functions (lack of function will result in a grade of zero). Your program must have the following menu and depending on the users choice, your program should be calling the pertaining function to display the result for the user.


1 - Add

2 - Subtract

3 - Multiply

4 - Divide

5 - Raise X to the power Y

6 - Finds if a number is even or odd

0 - Quit

Your calculator must:
1. Display a menu with all the options

2- Ask the user to select an option from the menu

3. Based on the user selection, your program must then ask for the operand/s and call the pertaining function.

4. Your program will accept int and the result can be displayed in double (utilize type casting).

5.Once your program is done with the user's option, your program must ask if the user would like to try another option utilizing loops)

Input Validation: Your program should only accepts numbers.

Solutions

Expert Solution

Answer:

Here is the c++ code as per your requriement

Raw code:

//including headers

#include <iostream>

#include <math.h>

//functions for the options

using namespace std;

//addition

int sum(int a,int b){

return a+b;

}

//subtraction

int sub(int a,int b){

return a-b;

}

//mutlitply

int mul(int a,int b){

return a*b;

}

//divioson

double divison(int a,int b){

return (double)a/b;

}

//exponention

double power(int a,int b){

return (double)pow(a,b);

}

//odd or even

string odd_even(int a){

if(a%2==0){

return "Even";

}

return "Odd";

}

int main() {

//main print menu

cout<<"1 - Add\n2 - Subtract\n3 - Multiply\n4 - Divide\n5 - Raise X to the power Y\n6 - Finds if a number is even or odd\n0 - Quit"<<endl;

char cho= 'y';

//do while loop

do{

//get input

int choice;

//if user entered 0 break

cin>>choice;

if (choice==0){

break;

}

//else

else{

// call the functions based on choice

if(choice==1){

int a;int b;

cout<<"Enter values with spaces: ";

cin>>a>>b;

cout<<"Sum: "<<sum(a,b)<<endl;

}

if(choice==2){

int a;int b;

cout<<"Enter values with spaces: ";

cin>>a>>b;

cout<<"Sub: "<<sub(a,b)<<endl;

}

if(choice==3){

int a;int b;

cout<<"Enter values with spaces: ";

cin>>a>>b;

cout<<"Multiplication: "<<mul(a,b)<<endl;

}

if(choice==4){

int a;int b;

cout<<"Enter values with spaces: ";

cin>>a>>b;

cout<<"Divison: "<<divison(a,b)<<endl;

}

if(choice==5){

int a;int b;

cout<<"Enter values with spaces: ";

cin>>a>>b;

cout<<a<<" raises to the power "<<b<<power(a,b)<<endl;

}

if(choice==6){

int a;

cin>>a;

cout<<odd_even(a)<<endl;

}

cout<<"would you like to try other option?(y/n) "<<endl;

cin>>cho;

}

//if user enterd n exit the progrm

}while(cho!='n');

}

Editor:

output:

Hope this helps you! If you still have any doubts or queries please feel free to comment in the comment section.

"Please refer to the screenshot of the code to understand the indentation of the code".

Thank you! Do upvote.


Related Solutions

Please C++ create a program that will do one of two functions using a menu, like...
Please C++ create a program that will do one of two functions using a menu, like so: 1. Do Catalan numbers 2. Do Fibonacci numbers (recursive) 0. Quit Enter selection: 1 Enter Catalan number to calculate: 3 Catalan number at 3 is 5 1. Do Catalan numbers 2. Do Fibonacci numbers (recursive) 0. Quit Enter selection: 2 Enter Fibonacci number to calculate: 6 Fibonacci number 6 is 8 Create a function of catalan that will take a parameter and return...
Model the following in JAVA PROGRAMMING : In a software engineering project we are developing software...
Model the following in JAVA PROGRAMMING : In a software engineering project we are developing software for a Real estate agency. The Real Estate Agency has these types of properties: Shops, Apartments and Villas. All properties have: Property Owner, Address, Property Purpose (Sale/Rent), Area (in m^2) and price. Model these in an inheritance hierarchy considering that: 1. Shops have these fields in addition to properties: Floor (int), Street view (boolean). 2. Apartments have these feilds in addition to properties: Floor,...
Discuss steps required to manage a software engineering project.
Discuss steps required to manage a software engineering project.
I need some ideas for software engineering project
I need some ideas for software engineering project
What are the documentations of an online banking system for a project in software engineering
What are the documentations of an online banking system for a project in software engineering
a) Discuss the main components and utility of the responsibility assignment matrix in a software engineering organization
a) Discuss the main components and utility of the responsibility assignment matrix in a software engineering organizationb) As a software engineer, you are involved in developing a project intended to implement a set of business processes and a software solution for customer relationship management.The project involves a large number of organizations?a major corporation and many suppliers of different sizes. During the project, you observe effects of the differences between the companies’ corporate cultures, which leads to different expectations on how...
Not sure where to begin on this c++ assignment. The instructions are to enclose the current...
Not sure where to begin on this c++ assignment. The instructions are to enclose the current contents of the print_output function into a try block that throws two different exceptions based on which line catches the bad input (shape or color). You will then print an appropriate message based on the type of exception that was thrown. this is what I have so far: #include <stdlib.h> #include <time.h> #include <stdio.h> #include <iostream> namespace color {        enum color{          red  ...
Program Assignment 1 C++ please Instructions This assignment will require the use of three arrays, which...
Program Assignment 1 C++ please Instructions This assignment will require the use of three arrays, which will be used in parallel. Create a program that keeps track of the sales of BBQ sauces for a company. The company makes several different types of sauces, Original, Sticky Sweet, Spicy, Sweet Heat, Hickory Bourbon and Smokey Mesquite. One array will contain the names of the different BBQ sauces. This array will be initialized from a text file with the 6 different names....
Code in C Instructions For this programming assignment you are going to implement a simulation of...
Code in C Instructions For this programming assignment you are going to implement a simulation of Dijkstra’s solution to the Dining Philosophers problem using threads, locks, and condition variables. Dijkstra’s Solution Edsgar Dijkstra’s original solution to the Dining Philosophers problem used semaphores, but it can be adapted to use similar mechanisms: • Each philosopher is in one of three states: THINKING, HUNGRY, or EATING. • Every philosopher starts out in the THINKING state. • When a philosopher is ready to...
A. Write a C++ with a menu (using switch) that asks the user to select one...
A. Write a C++ with a menu (using switch) that asks the user to select one of the following choices to the user: 1. Options ‘S’ or ‘s’ 2. Option ‘T’ or ‘t 3. Options ‘P’ or ‘p’ 4. print in the Matrix format B. When 1 is selected, prompt the user to enter the starting value st (int value). Use a single FOR loop to count numbers from 1 to st. When the loop is finished, find the average...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT