Lab Functions 2 Topics covered: C++ Program Development Practice, Loops, Functions and Arrays Lab Elements A. Factorial Calculation Use filename: factorial.cpp write a function that computes the factorial for given integer value by loop iteration. Note - for a given number n, its factorial value is given by n! = 1*2*3*...*(n-1)*n By definition, 0! = 1! = 1 The function prototype is given by int factorial(const int &); Function should do following tests on argument value: • If argument < 0, return -1. After the function returns, your main() should check the return value. If return value == -1, output an error message and halt program execution by using the statement: return 1; The code in main() would look something like - int factorialValue if(factorialValue == -1) { factorial(-1); // trying to compute (-1)! %3D cout « "Error: factorial value for negative number is not defined" <« endl; return 1; If (argument==0) || (argument==1), immediately return 1; • For argument > 1, compute its factorial by iteration and return factorial value

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

C++ Programming

EECE1080C/CS1021C
Lab Functions 2
Topics covered: C++ Program Development Practice, Loops, Functions and Arrays
Lab Elements
A. Factorial Calculation
Use filename: factorial.cpp
Write a function that computes the factorial for given integer value by loop
iteration. Note - for a given number n, its factorial value is given by
n! = 1*2*3*...*(n-1)*n
By definition, e! = 1! = 1
The function prototype is given by
int factorial(const int &);
Function should do following tests on argument value:
• If argument < 8, return -1. After the function returns, your main()
should check the return value. If return value == -1, output an error
message and halt program execution by using the statement: return 1; The
code in main() would look something like -
int factorialValue = factorial(-1); // trying to compute (-1)!
if(factorialValue
-1) {
==
cout « "Error: factorial value for negative number is not
defined" <« endl;
return 1;
• If (argument==0) || (argument==1), immediately return 1;
• For argument > 1, compute its factorial by iteration and return factorial
value
For testing, include a main() in your code and call your factorial function.
You can use an online factorial calculator to check your code outputs (For
example, see: https://www.factorial-calculator.com)."
DELIVERABLES FOR GRADING - This lab element wil1 be auto-graded in zyBooks.
Copy and paste the contents of only your factorial function into the
main.cpp Window for zyLabs using link provided on CANVAS site for lab (do
not copy your main() function into the window).
Transcribed Image Text:EECE1080C/CS1021C Lab Functions 2 Topics covered: C++ Program Development Practice, Loops, Functions and Arrays Lab Elements A. Factorial Calculation Use filename: factorial.cpp Write a function that computes the factorial for given integer value by loop iteration. Note - for a given number n, its factorial value is given by n! = 1*2*3*...*(n-1)*n By definition, e! = 1! = 1 The function prototype is given by int factorial(const int &); Function should do following tests on argument value: • If argument < 8, return -1. After the function returns, your main() should check the return value. If return value == -1, output an error message and halt program execution by using the statement: return 1; The code in main() would look something like - int factorialValue = factorial(-1); // trying to compute (-1)! if(factorialValue -1) { == cout « "Error: factorial value for negative number is not defined" <« endl; return 1; • If (argument==0) || (argument==1), immediately return 1; • For argument > 1, compute its factorial by iteration and return factorial value For testing, include a main() in your code and call your factorial function. You can use an online factorial calculator to check your code outputs (For example, see: https://www.factorial-calculator.com)." DELIVERABLES FOR GRADING - This lab element wil1 be auto-graded in zyBooks. Copy and paste the contents of only your factorial function into the main.cpp Window for zyLabs using link provided on CANVAS site for lab (do not copy your main() function into the window).
Expert Solution
Step 1

Given ,

the answer is given below

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY