C++ How to Program (10th Edition)
10th Edition
ISBN: 9780134448237
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 19, Problem 19.8E
Program Plan Intro
- Include required header files
- Create class list. Define structure , create its members intdata and node *next. Declare pointer to structure *start
- Define one constructor
- Define member functions input, display, addNode and addition
- Create a main function
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(Summing and Averaging Elements in a List) Write a program that inserts 25 random integers from 0 to 100 in order in a linked list object. The program should calculate the sum of the elements and the floating-point average of the elements.
(Online Address Book revisited) Programming Exercise 5 in Chapter 11 could handle a maximum of only 500 entries. Using linked lists, redo the program to handle as many entries as required. Add the following operations to your program:
Add or delete a new entry to the address book.
Allow the user to save the data in the address book.
Topic: 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…
Chapter 19 Solutions
C++ How to Program (10th Edition)
Ch. 19 - Prob. 19.6ECh. 19 - Prob. 19.7ECh. 19 - Prob. 19.8ECh. 19 - Prob. 19.9ECh. 19 - Prob. 19.10ECh. 19 - Prob. 19.11ECh. 19 - (Infix-to-Post fix conversion) Stacks are used by...Ch. 19 - Prob. 19.13ECh. 19 - Prob. 19.14ECh. 19 - Prob. 19.15E
Ch. 19 - Prob. 19.16ECh. 19 - Prob. 19.17ECh. 19 - (Duplicate Elimination) In this chapter, we saw...Ch. 19 - Prob. 19.19ECh. 19 - Prob. 19.20ECh. 19 - Prob. 19.21ECh. 19 - Prob. 19.22ECh. 19 - Prob. 19.23ECh. 19 - Prob. 19.24ECh. 19 - Prob. 19.25ECh. 19 - Prob. 19.26ECh. 19 - Prob. 19.27ECh. 19 - Prob. 19.28E
Knowledge Booster
Similar questions
- 4arrow_forward( JAVA LANGUAGE ) Create and print a linked list with four (4) elements. Ice cream flavors will be the basis of the required values for the linked listarrow_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
- Topic: 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_forward(True/False): Arrays are passed by reference to avoid copying them onto the stackarrow_forwardUse c++ Write a program that uses the STL list container to create a linked list of integers. The program will ask the user to provide a list of integers. When the user is finished, the program will list the integers entered by the user and show the average of those integers. Additionally, you need to add the following code: Display your name (first and last) before you ask the user to enter the integers. You need to do one of the followings: (do not do all three) if the first letter of your last name is between and including A through G, compute the maximum value entered by the userarrow_forward
- C++ 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_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(Attach Python file only) Write a program that does the following 1- Declare the list my_list that has the following integer numbers 6, 5, 1, -3, 10, 0, and 4 as items of the list. 2- Modify the value of list items based on the following If the item of the list is an integer and less than three, increment its value by 2. If the item of the list is an integer is greater than or equal to three, decrement its value by 3. 3- after modification, print out the items of the list that have only the even index in the reverse order. A- В I T Ff ♥ = E E E !arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning