Short Answer Questions (3-4 sentences expected per question) 1) Give a brief description of the three different loop types (for, while, do-while). When is each loop type most useful? Are there certain problems that can only be solved with one type of loop? 2) When we pass an integer into a function as an argument, the value gets copied into the parameter. When we pass an array of integers into a function, does every array element also get copied? Why or why not? 3) There are several reasons we might choose to write a user-function in our program, instead of just using a the main() function. Give two benefits of writing our own functions and explain each in a sentence or two.

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

Short Answer Questions (3-4 sentences expected per question)
1) Give a brief description of the three different loop types (for, while, do-while). When is
each loop type most useful? Are there certain problems that can only be solved with
one type of loop?
2) When we pass an integer into a function as an argument, the value gets copied into the
parameter. When we pass an array of integers into a function, does every array element
also get copied? Why or why not?
3) There are several reasons we might choose to write a user-function in our program,
instead of just using a the main() function. Give two benefits of writing our own
functions and explain each in a sentence or two.
4) In C, we have a special character (NULL character, ‘\0’) for indicating the end of a
string. Would it make sense to have a similar special integer value to indicate the end of
integer arrays? Why or why not?

1) int median_of_three (int a, int b, int c)
This function accepts three integers as input and returns the median (middle value) of
the three. Several examples are given below, along with the expected return value.
Input numbers
2, 3,
Expected return value
1
2, 4, 3
3
5, 5, 5
5
1, 1, 5
1
2) void print_reverse (char str[])
This function will accept a string as an input argument and return nothing. All this
function does is print the string in reverse order. For this question, you may include
string.h and use strlen(), but you may NOT use the string function strrev().
Several examples are given below.
Input string
Expected printout
"H"
"H"
"Hello"
"olleH"
"Hello, World!"
"racecar"
"!dlrow ,olleH"
“racecar"
When attempting this question, remember that a string is nothing more than an array of
characters with the NULL character (\0') as a terminator.
3) int is_ascending (int arr[], int len)
This function will accept an array of integers as input, as well as the length of that array.
It will return an integer. If the elements of the array are in strict ascending order, it will
return the integer 1, and 0 otherwise. Several examples are given below indicating how
your function should behave.
Expected return value
Input array
{-5, 10, 99, 1234}
{2, 3, 3, 4, 5}
{-99}
{4, 6, 7, 3, 7, 9}
{1, 1, 1, 1}
1
(values 3 and 3 are equal, not ascending)
1
(an array with one value is ascending)
How you accomplish this is completely up to you. You'll need a loop, you'll need some
if/else logic, but whatever you do is fine so long as it produces the correct results.
Transcribed Image Text:1) int median_of_three (int a, int b, int c) This function accepts three integers as input and returns the median (middle value) of the three. Several examples are given below, along with the expected return value. Input numbers 2, 3, Expected return value 1 2, 4, 3 3 5, 5, 5 5 1, 1, 5 1 2) void print_reverse (char str[]) This function will accept a string as an input argument and return nothing. All this function does is print the string in reverse order. For this question, you may include string.h and use strlen(), but you may NOT use the string function strrev(). Several examples are given below. Input string Expected printout "H" "H" "Hello" "olleH" "Hello, World!" "racecar" "!dlrow ,olleH" “racecar" When attempting this question, remember that a string is nothing more than an array of characters with the NULL character (\0') as a terminator. 3) int is_ascending (int arr[], int len) This function will accept an array of integers as input, as well as the length of that array. It will return an integer. If the elements of the array are in strict ascending order, it will return the integer 1, and 0 otherwise. Several examples are given below indicating how your function should behave. Expected return value Input array {-5, 10, 99, 1234} {2, 3, 3, 4, 5} {-99} {4, 6, 7, 3, 7, 9} {1, 1, 1, 1} 1 (values 3 and 3 are equal, not ascending) 1 (an array with one value is ascending) How you accomplish this is completely up to you. You'll need a loop, you'll need some if/else logic, but whatever you do is fine so long as it produces the correct results.
Project Description
For this final exam project, you will write a series of functions. For each function, a signature
is given below along with a description of what each function should do. Under no
circumstance should these functions use scanf! Do not read input from the user inside the
function. The functions will operate solely on their input arguments.
0) void promise (char name[])
This function will not return anything. It will accept a string as an argument, and print
out the following message to the screen:
"My name is <your name here>, and I promise that this is entirely my own work"
When I call the function with my own name:
promise("Alex Ufkes");
The message that prints would be:
"My name is Alex Ufkes, and I promise that this is entirely my own work"
Transcribed Image Text:Project Description For this final exam project, you will write a series of functions. For each function, a signature is given below along with a description of what each function should do. Under no circumstance should these functions use scanf! Do not read input from the user inside the function. The functions will operate solely on their input arguments. 0) void promise (char name[]) This function will not return anything. It will accept a string as an argument, and print out the following message to the screen: "My name is <your name here>, and I promise that this is entirely my own work" When I call the function with my own name: promise("Alex Ufkes"); The message that prints would be: "My name is Alex Ufkes, and I promise that this is entirely my own work"
Expert Solution
steps

Step by step

Solved in 3 steps with 4 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