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
Transcribed Image Text:In this assignment you are to use pointers to manipulate dynamically created arrays.
An array's name is basically a pointer to the fisrt element of the array. Dynamic arrays are created using pointer syntax, but
can subsequently use array syntax, which is the best practice approach.
Instructions (main.cpp)
Inside main.cpp implement the following functions:
int makeArray (const int size);
This function dynamically allocates an int array of the specified size.
• size the size of the dynamically allocated array.
• returns - a dynamically allocated integer array of size elements.
void initializeArray (int * array, const int size, const int initValue);
This function initializes an array of size elements with the initValue.
array-The array whose elements are to be initialized.
size the size of the array.
initValue the value with which to initialize each element.
int
duplicateArray (const int const sourceArray, const int size);
This function duplicates an array of size elements. When copying dynamic instances of any kind you must be careful not
to perform a shallow copy when a true duplicate is desired.
A shallow copy simply assigns the contents of one pointer to another, i.e. ptr1= ptr2; A duplicate is a deep copy and
requires memory allocation, i.e. ptr1 = new ....
• sourceArray - The array being duplicated. Notice how neither the pointer nor the array are allowed to change (both
const).
• size - the size of the array being duplicated.
• returns - a dynamically allocated array which is a duplicate of the source array.
Note: The function mush dynamically create a new array and initialize each element with the corresponding source array's
elements.
string describeArray (const int const array, const int size);
This function returns a formatted description of the array.
. array- the constant pointer to a constant int. Neither the elements nor the pointer can be changed.
size - the size of the array.
returns-returns a formatted description of the instance, i.e. [v1, v2...], where v1, v2... are the values of each
element.
This function uses the seekp() method of the ostringstream class to remove one character from the end of the
stream. This removes the last, before the ] is added to complete the formatting.
Example
The following code:
int sourceArray makeArray (5);
initializeArray (sourceArray, 5, 5);
int targetArray duplicateArray (sourceArray, 5);
cout << "source: " << describeArray (sourceArray, 5) << ", " << sourceArray << endl
<< "target: " << describeArray (targetArray, 5) << ", " << targetArray;
produces the output:
source: [5,5,5,5,51, 0x7f9fa4405aa0
target: [5,5,5,5,5], 0x7f9fa4405ac0
Notice how the two arrays, sourceArray and targetArray are two distinct memory locations rather than the same
location. This implies a deep copy rather a shallow copy.
Expert Solution
Check MarkThis question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
bartleby
This is a popular solution
bartleby
Trending nowThis is a popular solution!
bartleby
Step by stepSolved in 3 steps with 2 images
Knowledge Booster
Background pattern image
Similar questions
- Problem Statement Average function: Please complete the following function. The function has two parameters which are an integer array and an integer as a size of the array. The function computes the average value by adding all values from each element of an array and dividing them by the size of the array. The function returns an integer of the average value. Example 1 average({1, 2, 3, 4, 5}, 5) → 3 Example 2 average({2, 4, 6, 8, 10, 12, 14, 16, 18}, 9) → 10 Example 3 average({5, 5, 5, 5, 5}, 5) → 5 Partial Solution Please try to implement the full source code in your IDE first. The solution is partially provided below. Fill in the blanks to complete the missing parts and make sure to not add an empty space before and after the answer. } int sum = for(int i = } sum 0; 0; i return sum/ average(int array[], int size) { array size; i++){arrow_forwardUsing C++ Programming language: Assume you want a function which expects as parameters an array of doubles and the size of the array. Write the function header that accepts these parameters but is defined in such a way that the array cannot be modified in the function. You can use your own variable names for the parameters.arrow_forwardWhen calling a function, what exactly does it imply to say that you need the "base address of an array"?arrow_forward
- /)9. Given an array of integers, write a PHP function to find the maximum element in the array. PHP Function Signature: phpCopy code function findMaxElement($arr) { // Your code here } Example: Input: [10, 4, 56, 32, 7] Output: 56 You can now implement the findMaxElement function to solve this problem. Keep it and.arrow_forwardWritten in code C and with clear and concise comments Extend your addition, subtraction, multiplication and division program to now present the user with an option to display only one of the results or to display them all, as demonstrated in Figure 2.3. Your program should accept two numbers from the user and carry out all four mathematical operations as before. The results will then be stored in an array and the user will be asked which operation they actually prefer to see displayed on the screen. When the option has been selected, the corresponding mathematical operation should be displayed using printfembedded in various if else statements. Since there are five different cases (display results for +, -, *, / and all of these) you should include five consecutive if (else if) statements, one for each option. In fact, you should also notify the user in case a non-valid option entry is typed, i.e. a number that is not within 1 – 4.This should be the final else statement.Your program...arrow_forwardIn C Programming: You will need all the functions from the previous assignment, as well as the structure course:• Department (string, 15 characters)• Course number (integer, 4 digits, leading 0 if necessary)• Course title (string, 30 characters)• Credits (short, 1 digit) Write a function saveAllCoursesText() which receives an array of course pointers and the array’s size, then outputs the content of the array in text format to a file named "courses.txt".• Save the entire structure on 1 line (all the members of the structure should be saved in 1 fprintf() command)arrow_forward
- please help me step by step solve all option and please add the output screen please thank you againarrow_forwardASSEMBLY It is preferable to pass Arrays by reference when calling subroutines. True Falsearrow_forwardAssume the binarySearch() function works correctly as demonstrated in the bookarrow_forward
- Two dimension array in C:Create a two dimension array of integers that is 5 rows x 10 columns.Populate each element in the first 2 rows (using for loops) with the value 5.Populate each element of the last three rows (using for loops) with the value 7.Write code (using for loops) to sum all the elements of the first three columns and output thesum to the screen.arrow_forwardWrite the main program to create an array of size 10. Create two integer variables called max and min. Write a function to accept this array and its size. This function must populate the array with random numbers in the range -400 to 300. Write a different function to accept this array, its size and the address of the two variables max and min. The function must find the max and min of this array and write it to the min and max using pointer notation. Print the array and the values of max and min in the main program. in C++ visual studioarrow_forwardAssignment #6 - Array Practice Due: Wed, Nov 16 Objective To gain practice with arrays and common array algorithms, as well as the use of array parameters in functions. Task This assignment will consist of writing several functions that manipulate arrays or access data from arrays, as well as a test program that will allow interactive testing of the array functions. Part 1: Functions Write the following functions. Each one takes in an integer array as a parameter, and other necessary parameters are returns are described. Make sure the parameters are in the order specified. Make sure to use the const qualifier on the array parameter on any function where it is appropriate. A sample CALL is given for each function. • Insert Write a function called Insert that takes in four parameters: o an integer array o the size of the array o the new value to be inserted into the array o the index at which to insert the new value This function should insert a a new value into the array, at the...arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
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