Create a random sized linked list of randomly generated integers. Insert 25 to 75 random integers in the inclusive range 0 to 100 into the linked list. Display the contents, the sum, the count, and average of the integers. Create a program named LastnameFirstname17.c, that does the following: Define a structure named node that stores a single integer and a pointer to another node. You may use the struct definition in linkedlist.c as a template to get started. Keep in mind that the data in the linkedlist.c example was a string implemented as a char[]. For this assignment, the data is an integer, just a single int. You may want to define a typedef to create alias' for the node structure and node pointer for convenience. Setup your program to generate random numbers. Import the necessary includes and seed the random function. Generate a random integer between 25 and 75, inclusive, this number will be the size of the linked list. The size of the linked list: int size = 25 + rand() % 51; Create a node* variable that will be the head of the linked list. For the next part of the program, you will be defining three custom functions to handle specific linked list related tasks. Declare all function prototypes above main and define all functions below main. The function prototypes will not be given because it will be different depending if you created alias's. As with previous assignments, do NOT create any global variables. All variable declarations are either in main() or in the custom functions. Symbolic constants are okay as those are not variables. Define the following 3 custom functions given their descriptions: Define a void function named insertIntoLinkedList that takes in an integer and a node pointer as parameters. The integer is the data of a new node that will be added to the linked list and the node pointer is the head of the linked list. Create a new node using the integer, then insert that node into the linked list in descending order. Descending order for numbers means largest to smallest. Note: Do not generate the random integer in this function. The integer is provided in the parameter. When this function is called, the integer is passed as an argument. Define a void function named displayLinkedList that takes in a node pointer as a parameter and prints the data in the linked list on a single line, comma separated. Define an int function named sumLinkedList that takes in a node pointer as a parameter, calculates the sum of all the data in the list and returns it. The purpose of this function is to calculate the sum and return it, that's all. There should be no average calculation or prints in this function, that happens in the main() function. The sole purpose of this function is to return the sum of the linked list. Back in the main(), use a loop to build the linked list of integers. Generate an integer between 0 and 100, inclusive, then call the insertIntoLinkedList function using the integer and the head of the linked list. To generate the random data: int randomData = rand() % 101; The amount of integers that need to be inserted is the size that was randomly generated at the beginning of the program. In other words, ensure the loop iterates size many times. After building the linked list, call the sumLinkedList function using the head of the linked list to get the sum of all the data. Use the sum and the size of the list to calculate the floating point average of the data. Be aware of integer division! Output the contents, sum, size, and average of the list. See the Example Output below. Display the average to 2 decimal places. Ensure all output is appropriately labeled. Be sure to have a program description at the top and in-line comments.   Please do all the following code in C++ and in your own original code please.

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
  • Create a random sized linked list of randomly generated integers.
    • Insert 25 to 75 random integers in the inclusive range 0 to 100 into the linked list.
  • Display the contents, the sum, the count, and average of the integers.

Create a program named LastnameFirstname17.c, that does the following:

  1. Define a structure named node that stores a single integer and a pointer to another node.
    • You may use the struct definition in linkedlist.c as a template to get started. Keep in mind that the data in the linkedlist.c example was a string implemented as a char[]. For this assignment, the data is an integer, just a single int.
  2. You may want to define a typedef to create alias' for the node structure and node pointer for convenience.
  3. Setup your program to generate random numbers. Import the necessary includes and seed the random function.
  4. Generate a random integer between 25 and 75, inclusive, this number will be the size of the linked list.
    • The size of the linked list: int size = 25 + rand() % 51;
  5. Create a node* variable that will be the head of the linked list.
  6. For the next part of the program, you will be defining three custom functions to handle specific linked list related tasks. Declare all function prototypes above main and define all functions below main. The function prototypes will not be given because it will be different depending if you created alias's.
    • As with previous assignments, do NOT create any global variables. All variable declarations are either in main() or in the custom functions.
    • Symbolic constants are okay as those are not variables.
  7. Define the following 3 custom functions given their descriptions:
    1. Define a void function named insertIntoLinkedList that takes in an integer and a node pointer as parameters.
      • The integer is the data of a new node that will be added to the linked list and the node pointer is the head of the linked list.
      • Create a new node using the integer, then insert that node into the linked list in descending order. Descending order for numbers means largest to smallest.
      • Note: Do not generate the random integer in this function. The integer is provided in the parameter. When this function is called, the integer is passed as an argument.
    2. Define a void function named displayLinkedList that takes in a node pointer as a parameter and prints the data in the linked list on a single line, comma separated.
    3. Define an int function named sumLinkedList that takes in a node pointer as a parameter, calculates the sum of all the data in the list and returns it.
      • The purpose of this function is to calculate the sum and return it, that's all.
      • There should be no average calculation or prints in this function, that happens in the main() function. The sole purpose of this function is to return the sum of the linked list.
  8. Back in the main(), use a loop to build the linked list of integers. Generate an integer between 0 and 100, inclusive, then call the insertIntoLinkedList function using the integer and the head of the linked list.
    • To generate the random data: int randomData = rand() % 101;
    • The amount of integers that need to be inserted is the size that was randomly generated at the beginning of the program. In other words, ensure the loop iterates size many times.
  9. After building the linked list, call the sumLinkedList function using the head of the linked list to get the sum of all the data.
  10. Use the sum and the size of the list to calculate the floating point average of the data.
    • Be aware of integer division!
  11. Output the contents, sum, size, and average of the list. See the Example Output below.
  12. Display the average to 2 decimal places.
  13. Ensure all output is appropriately labeled.
  14. Be sure to have a program description at the top and in-line comments.

 

Please do all the following code in C++ and in your own original code please.

- **Example Output**

```
% make
% ./program
The list is: 96, 95, 91, 90, 88, 88, 86, 86, 80, 78, 69, 66, 65, 57, 56, 53, 44, 41, 40, 36, 36, 32, 30, 30, 26, 25, 18, 16, 16, 12, 9, 3, 1,
sum = 1695
size = 34
average = 49.85

% ./program
The list is: 99, 98, 96, 95, 93, 92, 90, 89, 86, 86, 85, 84, 84, 79, 78, 77, 77, 77, 76, 75, 75, 71, 71, 70, 69, 67, 66, 65, 61, 60, 59, 54, 52, 50, 48, 45, 41, 40, 39, 39, 36, 32, 27, 26, 24, 24, 24, 22, 21, 16, 10, 6, 5, 5, 4, 4, 0,
sum = 3233
size = 58
average = 55.74

% ./program
The list is: 100, 98, 97, 96, 94, 93, 93, 91, 91, 87, 87, 84, 84, 83, 79, 78, 78, 76, 76, 74, 73, 72, 72, 71, 69, 65, 63, 61, 60, 60, 59, 59, 52, 50, 50, 49, 48, 48, 48, 47, 47, 45, 44, 44, 43, 41, 40, 38, 36, 35, 34, 34, 32,
Transcribed Image Text:- **Example Output** ``` % make % ./program The list is: 96, 95, 91, 90, 88, 88, 86, 86, 80, 78, 69, 66, 65, 57, 56, 53, 44, 41, 40, 36, 36, 32, 30, 30, 26, 25, 18, 16, 16, 12, 9, 3, 1, sum = 1695 size = 34 average = 49.85 % ./program The list is: 99, 98, 96, 95, 93, 92, 90, 89, 86, 86, 85, 84, 84, 79, 78, 77, 77, 77, 76, 75, 75, 71, 71, 70, 69, 67, 66, 65, 61, 60, 59, 54, 52, 50, 48, 45, 41, 40, 39, 39, 36, 32, 27, 26, 24, 24, 24, 22, 21, 16, 10, 6, 5, 5, 4, 4, 0, sum = 3233 size = 58 average = 55.74 % ./program The list is: 100, 98, 97, 96, 94, 93, 93, 91, 91, 87, 87, 84, 84, 83, 79, 78, 78, 76, 76, 74, 73, 72, 72, 71, 69, 65, 63, 61, 60, 60, 59, 59, 52, 50, 50, 49, 48, 48, 48, 47, 47, 45, 44, 44, 43, 41, 40, 38, 36, 35, 34, 34, 32,
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
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