Question: Lab Function Program CSCI 111 Programming and Algorithms I NEW CONCEPTS: Successful completion of this lab incorporates the following new concepts. Creating and calling a

Lab

Function Program

CSCI 111 Programming and Algorithms I

NEW CONCEPTS: Successful completion of this lab incorporates the following new concepts. Creating and calling a function

// function example #include using namespace std;

int addition (int a, int b) {

int r; r=a+b; return r;

}

int main () {

int z; z = addition (5,3); cout << "The result is " << z << endl;

}

Task list: 1. Create a source code file named lab.cpp.

2. From the main function, start by prompting the user for a choice (type char) of what math operation to perform (see trace output below for details).

3. Prompt the user for 2 additional numeric values of type int. 4. Create and call a function by passing the 3 variables as arguments that the user just entered.

5. The function should use the switch statement to calculate the result. Please use the sample function declaration shown above.

6. Refer to the expected output listing below.

SAMPLE OUTPUT

/user/faculty/CSCI111/Labs/lab $ ./lab 
What action do you want to perform? (a=add, s=subtract, m=multiply, d=divide, x=mod) a Enter first number 9 

Enter second number 4 The result is 13

/user/facultyCSCI111/Labs/lab $ ./lab

What action do you want to perform? (a=add, s=subtract, m=multiply, d=divide, x=mod) s

Enter first number 9 Enter second number 4 
The result is 5 
/user/faculty/CSCI111/Labs/lab $ ./lab 
What action do you want to perform? (a=add, s=subtract, m=multiply, d=divide, x=mod) m Enter first number 9 

Enter second number 4 The result is 36

/user/facultyCSCI111/Labs/lab $ ./lab

What action do you want to perform? (a=add, s=subtract, m=multiply, d=divide, x=mod) d

Enter first number 9 Enter second number 4 
The result is 2 
/user/faculty/CSCI111/Labs/lab $ ./lab 
What action do you want to perform? (a=add, s=subtract, m=multiply, d=divide, x=mod) x Enter first number 9 

Enter second number 4 The result is 1

/user/faculty/CSCI111/Labs/lab $ ./lab

What action do you want to perform? (a=add, s=subtract, m=multiply, d=divide, x=mod) g

Enter first number 9 Enter second number 4 

Wrong choice. I am returning zero The result is 0

/user/faculty/CSCI111/Labs/lab $ ./lab

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!