
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
Question
![/*
(name header)
#include <iostream>
// Function declaration
int main()
{
int al[]
int a2[] = { 7, 2, 10, 9 };
int a3[] = { 2, 10, 7, 2 };
int a4[] = { 2, 10 };
int a5[] = { 10, 2 };
int a6[] = { 2, 3 };
int a7[] = { 2, 2 };
int a8[] = { 2 };
int a9[] % { 5, 1, б, 1, 9, 9 };
int al0[] = { 7, 6, 8, 5 };
int all[] = { 7, 7, 6, 8, 5, 5, 6 };
int al2[] = { 10, 0 };
{ 10, 3, 5, 6 };
%3D
std::cout
« ((difference (al, 4)
« ((difference(a2, 4)
<« ((difference (a3, 4)
« ((difference(a4, 2)
<« ((difference (a5, 2)
<« ((difference (a6, 2)
<« ((difference (a7, 2)
<« ((difference(a8, 1)
« ((difference (a9, 6)
« ((difference(a10, 4)
" <« ((difference(al1, 7)
« ((difference (al2, 2) == 10) ? "OK\n" : "X\n");
<< "al:
<< "a2:
%3D
7)? "OK" : "X") << std::endl
== 8) ? "OK\n" : "X\n")
8) ? "OK\n" : "X\n")
== 8) ? "OK\n" : "X\n")
== 8) ? "OK\n" : "X\n")
== 1) ? "OK\n" : "X\n")
== 0) ? "OK\n" : "X\n")
0) ? "OK\n" : "X\n")
== 8) ? "OK\n" : "X\n")
== 3) ? "OK\n" : "X\n")
== 3) ? "OK\n" : "X\n")
==
<< "a3:
==
<< "a4:
<< "a5:
<< "a6:
<< "a7:
<< "a8:
==
<< "a9:
<< "a10:
<< "all:
<« "a12: "
std::cout « "\n";
return 0;
}
//Function definition](https://content.bartleby.com/qna-images/question/9859e9ed-c97b-4c21-87da-644d627e752c/d6f82310-58e8-47bf-ac6c-7b769910c217/ilqefcc_thumbnail.jpeg)
Transcribed Image Text:/*
(name header)
#include <iostream>
// Function declaration
int main()
{
int al[]
int a2[] = { 7, 2, 10, 9 };
int a3[] = { 2, 10, 7, 2 };
int a4[] = { 2, 10 };
int a5[] = { 10, 2 };
int a6[] = { 2, 3 };
int a7[] = { 2, 2 };
int a8[] = { 2 };
int a9[] % { 5, 1, б, 1, 9, 9 };
int al0[] = { 7, 6, 8, 5 };
int all[] = { 7, 7, 6, 8, 5, 5, 6 };
int al2[] = { 10, 0 };
{ 10, 3, 5, 6 };
%3D
std::cout
« ((difference (al, 4)
« ((difference(a2, 4)
<« ((difference (a3, 4)
« ((difference(a4, 2)
<« ((difference (a5, 2)
<« ((difference (a6, 2)
<« ((difference (a7, 2)
<« ((difference(a8, 1)
« ((difference (a9, 6)
« ((difference(a10, 4)
" <« ((difference(al1, 7)
« ((difference (al2, 2) == 10) ? "OK\n" : "X\n");
<< "al:
<< "a2:
%3D
7)? "OK" : "X") << std::endl
== 8) ? "OK\n" : "X\n")
8) ? "OK\n" : "X\n")
== 8) ? "OK\n" : "X\n")
== 8) ? "OK\n" : "X\n")
== 1) ? "OK\n" : "X\n")
== 0) ? "OK\n" : "X\n")
0) ? "OK\n" : "X\n")
== 8) ? "OK\n" : "X\n")
== 3) ? "OK\n" : "X\n")
== 3) ? "OK\n" : "X\n")
==
<< "a3:
==
<< "a4:
<< "a5:
<< "a6:
<< "a7:
<< "a8:
==
<< "a9:
<< "a10:
<< "all:
<« "a12: "
std::cout « "\n";
return 0;
}
//Function definition

Transcribed Image Text:Lab 7: Arrays
Using the Lab07.cpp file, implement a function named difference that returns the difference between
the largest and smallest values in an array.
Example:
Sequence given: 7, 2, 10, 9
Largest value: 10
Smallest value: 2
Return value: (10 - 2) = 8
The main function already contains test cases.
Write function comments as shown in lesson 5.
What does the function return? Which parameters to pass? Examine the code provided to determine
return type and parameters.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

Knowledge Booster
Similar questions
- // MichiganCities.cpp - This program prints a message for invalid cities in Michigan. // Input: Interactive // Output: Error message or nothing #include <iostream> #include <string> using namespace std; int main() { // Declare variables string inCity; // name of city to look up in array const int NUM_CITIES = 10; // Initialized array of cities string citiesInMichigan[] = {"Acme", "Albion", "Detroit", "Watervliet", "Coloma", "Saginaw", "Richland", "Glenn", "Midland", "Brooklyn"}; bool foundIt = false; // Flag variable int x; // Loop control variable // Get user input cout << "Enter name of city: "; cin >> inCity; // Write your loop here // Write your test statement here to see if there is // a match. Set the flag to true if city is found. // Test to see if city was not found to determine if // "Not a city in Michigan" message should be printed.…arrow_forwardIn visual basic Write the code that will sequentially search through the array strFirstNames and will print out the word "Found" if the name "Brian" is in the array.arrow_forwardQUESTION 8 1) Write an InsertFirst function for a partially filled array. This function should accept all required data as input parameters. Example If an array contains 7,10,3,9,5 and the InsertFirst function is called with a value of 20, the array will become 20,7,10,3,9,5.arrow_forward
- # Declare a named constant for array size here. MAX_AVERAGES = 8 # Declare array here. # Write a loop to get batting averages from user and assign to array. averageString = input("Enter a batting average: ") battingAverage = float(averageString) # Assign value to array. # Assign the first element in the array to be the minimum and the maximum. minAverage = averages[0] maxAverage = averages[0] # Start out your total with the value of the first element in the array. total = averages[0] # Write a loop here to access array values starting with averages[1] # Within the loop test for minimum and maximum batting averages. # Also accumulate a total of all batting averages. # Calculate the average of the 8 batting averages. # Print the batting averages stored in the averages array. # Print the maximum batting average, minimum batting average, and average batting average. This is on mindtap pyton what needs to be fixarrow_forwardCreate Array of Random Dates In this task you are required to write a function that will generate a column array (a variable called dates) containing N random dates. N is an integer (whole number) entered by the user and will indicate to the function how many random dates the user requires. The dates array will be structured as follows: • The array shall have two columns; column 1 will contain numbers indicating the day of each month (1-31) and column 2 will contain numbers indicating the month (Jan 1, Feb=2, Mar = 3.... Dec = 12). . Each day must be randomly generated (using the randi() function) taking into account the maximum number of days in each month (i.e. Jan, Mar, May, Jul, Aug. Oct and Dec have 31 days, Apr. Jun, Sep and Nov have 30 days and Feb will have 28 days). You must use an if-elseif-else statement to decide this. • We are assuming no leap years (e. February can only have days between 1-28). For example, the output from calling the function: output = dategen (3) could…arrow_forwardCalculate average test score: Write a program that reads 10 test scores in an array named testScores. Then pass this array to a function to calculate the average test scores, return the average to main function and display it. Input Validation: The test scores should be between 0 and 100 (inclusive). Add comments and version control.arrow_forward
- 8. Grade Book A teacher has five students who have taken four tests. The teacher uses the following grading scale to assign a letter grade to a student, based on the average of his or her four test scores: Test Score Letter Grade 90–100 A 80-89 B 70-79 C 60-69 D 0-59 Write a class that uses a String array or an ArrayList object to hold the five students' names, an array of five characters to hold the five students' letter grades, and five arrays of four doubles each to hold each student's set of test scores. The class should have methods that return a specific student's name, the average test score, and a letter grade based on the average. Demonstrate the class in a program that allows the user to enter each student's name and his or her four test scores. It should then display each student's average test score and letter grade. Input Validation: Do not accept test scores less than zero or greater than 100.arrow_forwardC++ Visual 2019 Write a program that uses a two identical arrays of at least 100 randomly generated integers. It should call a function that uses the bubble sort algorithm to sort one of the arrays in ascending order. The function should keep a count of the number of exchanges it makes. The program then should call a function that uses the selection sort algorithm to sort the other array. It should also keep count of the number of exchanges it makes. Display these values on the screen with appropriate descriptions.arrow_forward1- Write a user-defined function that accepts an array of integers. The function should generate the percentage each value in the array is of the total of all array values. Store the % value in another array. That array should also be declared as a formal parameter of the function. 2- In the main function, create a prompt that asks the user for inputs to the array. Ask the user to enter up to 20 values, and type -1 when done. (-1 is the sentinel value). It marks the end of the array. A user can put in any number of variables up to 20 (20 is the size of the array, it could be partially filled). 3- Display a table like the following example, showing each data value and what percentage each value is of the total of all array values. Do this by invoking the function in part 1.arrow_forward
- 1. Display Function Implement a function to display the contents of the patient_list array. Add code to call this function. Note that there are multiple places where this function needs to be called. Look for the // TODO comments to find the correct locations. 2. Sorting the array by Age Implement the code to sort the contents of the patient_list array based on the value stored in the age field. To do this you will need to implement code that relies on the qsort function from the C Standard library A function that compares two patient elements, based on the value stored in the age field. A call to the qsort function, which includes the array to be sorted, the number of elements in the array, the size of each array element and the function used to compare the array elements. Add code to call the qsort function, using the age comparison function that you implemented. This code should be placed just under the appropriate // TODO comment in main(). Sorting the array by…arrow_forwardWrite code for a sequential search that determines whether the value −1 is stored in an array with a reference variable named values. The code should display a message indicating whether the value was found.arrow_forwardWrite a function to determine the resultant force vector R of the two forces F₁ and F2 applied to the bracket, where 0₁ and 0₂. Write R in terms of unit vector along the x and y axis. R must be a vector, for example R = [Rx, Ry]. The coordinate system is shown in the figure below: F₁ y 0₂ 0₁ 1 ►x F2arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

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 Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

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
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY