C How to Program (8th Edition)
8th Edition
ISBN: 9780133976892
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 12, Problem 12.8E
Program Plan Intro
Program plan:
- Item, start variablesare used for input. There is structure listnode having data, nextPtr member variables which represents the linked list node.
- void insert(node **head, int value) function inserts the node in the a linked list.
- void calculate (node *flist) functioncalculate the sum of the contents of the linked list and then calculate the average value and display the result.
- void printList(node *head) function display the contents of the linked list.
Program description:
The main purpose of the program is to create linked list of 25 values which are generated randomly. Then sum and average of these values are calculated and displayed.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
please code in python
Forbidden concepts: arrays/lists (data structures), recursion, custom classes
Create a program that takes a password string from the user and encrypts the letters to go up or down the alphabet using a triple-number key. The amount up or down for the encryption of the alphabetical characters will depend on the input from the user.
Input for the encryption key integers will be -25 ≤ key ≤ 25.For example, ‘CHICKEN’ with a 1, 2, -3 would be C up 1 to D, H up 2 to J, I down 3 to F,then C up 1 to D, K up 2 to M, E down 3 to B, and N up 1 to O. Thus the encryption becomes ‘DJFDMBO’.
- Question-2:
Functions, Iterations and List
• Write a function that takes a positive integer n as its parameter.
• Return a list whose
o values are numbers between n and 2n.
TOPIC: Singly Linked ListImplement the following functions using C++
int add(int num)
This will add the element num into the linked list and return the position of the newly-added element. In the above example, having add(60) will return 5 as it is the fifth position in the list.
int remove(int num)
This will remove the first instance of the element and return the position of the removed element. In the above example, having remove(40) will return 3 as 40 was the third element in the linked list before having removed.
int get(int pos)
This method will get the element at the specified position. This will return -1 if the specified position is invalid.
bool addAt(int num, int pos)
This method will add the integer num to the posth position of the list and returns true if the value of pos is valid.
Performing addAt(20, 2) in the example list will add 20 at the 2nd position and the linked list will now look like this: 10 -> 20 -> 30 -> 40 -> 50.
When the value of pos is…
Chapter 12 Solutions
C How to Program (8th Edition)
Ch. 12 - Prob. 12.6ECh. 12 - (Merging Ordered Lists) Write a program that...Ch. 12 - Prob. 12.8ECh. 12 - (Creating a Linked List, Then Reversing Its...Ch. 12 - Prob. 12.10ECh. 12 - Prob. 12.11ECh. 12 - Prob. 12.12ECh. 12 - Prob. 12.13ECh. 12 - Prob. 12.14ECh. 12 - (Supermarket Simulation) Write a program that...
Knowledge Booster
Similar questions
- answer only know else skip sure dislike if copiedarrow_forwardTopic: Singly Linked ListImplement the following functions in C++ program. Read the question carefully. (See attached photo for reference) int removeAt(int pos) Removes the number in the posth position of the list and returns the element removed. Performing removeAt(3) in the example list will remove the 3rd element of the linked list and the updated list will be: 10 -> 30 -> 50 When the value of pos is greater than the size or less than one, return -1. int removeAll(int num) Removes all instances of num in the linked list and returns the number of instances removed. In this list 10 -> 10 -> 20 -> 30 -> 10, performing removeAll(10) will remove all three 10's and the list will look like this: 20 -> 30. Then, it will return the number of instances removed, in this case, 3. int contains(int num) This will return the position of the first instance of the element num in the list. If num is not found, return 0. In the example, having the method contains(30) will…arrow_forwardComplete my C++ program: Instructions: You have to continue on implementing your Array List namely the following functions: Example ArrayList: [10, 30, 40, 50] void addAt(int num, int pos) This method will add the integer num to the posth position of the list. Performing addAt(20, 2) in the example list will add 20 at the 2nd position and the array will now look like this: [10, 20, 30, 40, 50] When the value of pos is greater than the size + 1 or less than one, output "Position value invalid" void removeAt(int pos) Removes the number in the posth position of the list. Performing removeAt(3) in the example list will remove the 3rd element of the list and the updated array will be: [10, 30, 50] When the value of pos is greater than the size or less than one, output "Position value invalid" void removeAll(int num) Removes all instances of num in the array list. In this array [10, 10, 20, 30, 10], performing removeAll(10) will remove all 10's and the list will look like this: [20,…arrow_forward
- Q1) Using Functions and Lists write a program where a function filterEvens takes a list of mix numbers and return it by filtering all the evens out. You can take list items from user or create static, and then passed it to function. The output should be the list with only evens example input_list = [12, 5, 7, 8, 2, 4, 1] output = [12, 8, 2, 4]. Please do in python. Thanksarrow_forwardTopic: Singly Linked ListImplement the following functions in C++ program. Read the question carefully. Below are the "CODE THAT NEEDS TO BE IMPROVED" or "NOT FINAL CODE" (See attached photo for reference) int add(int num) This will add the element num into the linked list and return the position of the newly-added element. In the above example, having add(60) will return 5 as it is the fifth position in the list. int remove(int num) This will remove the first instance of the element and return the position of the removed element. In the above example, having remove(40) will return 3 as 40 was the third element in the linked list before having removed. int get(int pos) This method will get the element at the specified position. This will return -1 if the specified position is invalid. int add(int num) { addTail(num); return index; } int remove(int num) { node* currnode = head; node* prevnode = NULL;…arrow_forwardC++ PROGRAMMING (Linked list) complete the functions: You have to continue on implementing your Array List namely the following functions: Example ArrayList: [10, 30, 40, 50] void addAt(int num, int pos) This method will add the integer num to the posth position of the list. Performing addAt(20, 2) in the example list will add 20 at the 2nd position and the array will now look like this: [10, 20, 30, 40, 50] When the value of pos is greater than the size + 1 or less than one, output "Position value invalid" void removeAt(int pos) Removes the number in the posth position of the list. Performing removeAt(3) in the example list will remove the 3rd element of the list and the updated array will be: [10, 30, 50] When the value of pos is greater than the size or less than one, output "Position value invalid" My incomplete code: #include <cstdlib>#include <iostream>using namespace std; class ArrayList : public List { // : means "is-a" / extend int* array; int index;…arrow_forward
- Matich the following statements with the correct data structure by clicking on the drop down arrow and selecting the correct choice.. You need to store a list of elements and the number of elements in the program is fixed. If most of operations on a list involve retrieving an element at a given index. You have to add or delete the elements at the beginning of a list. Linked List ArrayList Arrayarrow_forward5- Write a python program that takes 5 positive integers from the user and prints the list after removing even numbers from that list. (Don't use built-in functions)arrow_forwardWhich of the following statements are correct (assuming O notation)? 1.Deleting an element is slower for a linked list than for an array 2.Random access of elements in an array is O(1) 3.Linked lists are more memory-efficient than arraysarrow_forward
- Topic: Singly Linked ListImplement the following functions in C++ program. Read the question carefully. Below is the "CODE THAT NEEDS TO BE IMPROVED" or "NOT FINAL CODE" (See attached photo for reference) bool addAt(int num, int pos) This method will add the integer num to the posth position of the list and returns true if the value of pos is valid. Performing addAt(20, 2) in the example list will add 20 at the 2nd position and the linked list will now look like this: 10 -> 20 -> 30 -> 40 -> 50. When the value of pos is invalid i.e. greater than the size + 1 or less than one, return false. bool addAt(int num, int pos) { if (pos == 1) { // case 1: addHead addHead(num); return true; } if (pos == index + 1) { // case 3: addTail addTail(num); return true; } node* currnode = head; //addAt(20, 3) int count = 0; while (currnode…arrow_forwardWrite the following function that returns true if the list is already sorted in increasing order: bool isSorted(const int list[], int size) Write a test program that prompts the user to enter a list and displays whether the list is sorted or not. Here is a sample run. Note that the first number in the input indicates the number of the elements in the list. This number is not part of the list. Assume the maximum list size is 80.arrow_forwardscheme: Q9: Sub All Write sub-all, which takes a list s, a list of old words, and a list of new words; the last two lists must be the same length. It returns a list with the elements of s, but with each word that occurs in the second argument replaced by the corresponding word of the third argument. You may use substitute in your solution. Assume that olds and news have no elements in common. (define (sub-all s olds news) 'YOUR-CODE-HERE )arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education