Question: Lab 16 Calculator (with function) Program CSCI 111 Programming and Algorithms I Due Sunday March 7, 11:59pm on turnin 10 Points NEW CONCEPTS: Successful completion

Lab 16

Calculator (with function) Program

CSCI 111 Programming and Algorithms I

Due Sunday March 7, 11:59pm on turnin

10 Points

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 num1, int num2)

{

int result;

result = num1+num2;

return result;

}

int main ()

{

in myresult;

myresult = addition (5,3);

cout<<"The result is"<

}

Task list:

1. Create a source code file named lab16.cpp.

2. From the main function, start by prompting the user for a choice as: What action do you want to perform? (a=add, s=subtract, m=multiply, d=divide, x=mod) and save the response in a variable of type char (will contain either a, s, m, d, or x).

3. Prompt the user for 2 additional numeric values of type int.

4. Create and call a function and pas the 3 argument variables that the user just entered. Notice that the sample function above has only 2 argument variables.

5. The function should use the switch statement to calculate the result.

6. Refer to the expected output listing below.

7. Submit your lab16.cpp file on https://turnin.ecst.csuchico.edu/ and get a successful message.

SAMPLE OUTPUT

/user/faculty/jraigoza/CSCI111/Labs/lab16 $ ./lab16

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/faculty/jraigoza/CSCI111/Labs/lab16 $ ./lab16

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/jraigoza/CSCI111/Labs/lab16 $ ./lab16

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/faculty/jraigoza/CSCI111/Labs/lab16 $ ./lab16

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/jraigoza/CSCI111/Labs/lab16 $ ./lab16

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/jraigoza/CSCI111/Labs/lab16 $ ./lab16

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/jraigoza/CSCI111/Labs/lab16 $

GRADING

To achieve a maximum score, students will need to clearly prove that they completed the goal.

Points lost for incompleteness, sloppiness, lateness, or failure to follow instructions.

Refer to syllabus for late policy.

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!