Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Bartleby Related Questions Icon
Related questions
Question
thumb_up100%
C++
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
Check Markarrow_forward
Step 1
Given ,
the answer is given below
bartleby
Step by stepSolved in 2 steps with 1 images
Knowledge Booster
Background pattern image
Similar questions
- Dear sir/madam, Please, I need to solve the problems using C++ programming language. Thank you. Babu ------------------------------------------------------------------------ Programming assignment: Prompt the user for a length in inches, and let them enter a value. Then convert to centimeters and print the information in the following form. For instance, if the user entered 28.9, the output would be: 28.9 inches = 73.406 centimeters NOTE: 1 in = 2.54 cm Prompt for and get the user’s number of donuts to buy and the number of people who will be attending a meeting. Then print the information as shown below: Number of donuts = 23 Number of people = 6 Each person gets 3 donuts There will be 5 donuts left Prompt for and get a basketball player's name, the number of free throws attempted (an int), and the number of free throws made (an int). Then calculate the free throw average according to this formula: number of...arrow_forwardWhat is the role of "final" or "const" keywords in various programming languages when defining variables or constants?arrow_forwardWhy is it even necessary to design functions in computer programming?arrow_forward
- Why is it even necessary to design functions in computer programming?arrow_forwardC++ What one topic did you learn about that was most noteworthy What was your favorite topic? What was your least favorite topic? Why? What other topics (s) would you like to see covered in this course(c++)? What topic(s) would you like to see removed from the course?arrow_forwardHow are these programming languages dissimilar?arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Text book imageComputer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONText book imageComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceText book imageNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Text book imageConcepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningText book imagePrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationText book imageSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY