Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 17, Problem 8PC
Program Plan Intro
Member Insertion by Position
Program Plan:
- Include the required specifications into the program.
- Declare a class ListNode.
- Declare the member variables “value” and “*p” in structure named “ListNode”.
- The data value of node is stored in variable v and address to next pointer is stored in pointer p
- Declare the constructor, destructor, and member functions in the class.
- Declare the structure variable “next” and a friend class Linked List
- Declare a class LinkList.
- Function to check whether a particular node with a data value n is a part of linked list or not “bool isMember(double n)”.
- A recursive print method is defined to print all the data values present in the link list “void rPrint()”.
- A link list method to insert elements into the link list called “void LinkedList::insert(double x, int pos)” is called that insert elements into the link list at specific positions.
- A method to search for an element present in the link list called “ int LinkedList::search(double x)” is called that returns the position of the element present in the link list.
- A destructor is called to delete the desired data value entered by the user called “LinkedList::~LinkedList( )”.
- A method to remove the element passed as a parameter from the link list is called “void LinkedList::remove(double x)”.
- Declare a method “void reverse( )” to reverse the elements present in the link list by traversing through the list and Move node at end to the beginning of the new reverse list being constructed.
- Declaration of structure variable head to store the first node of the list “ListNode * head” is defined.
- A function “void LinkedList::add(double n)” is defined which adds or inserts new nodes into the link list.
- A function “bool LinkedList::isMember(double n)” is defined which searches for a given data value within the nodes present in the link list.
- A destructor “LinkedList::~LinkedList()” deallocates the memory for the link list.
- A function “void LinkedList::print()” is used to print all the node data values present in the link list by traversing through each nodes in the link list.
- A recursive member function check is defined called “bool LinkedList::rIsMember(ListNode *pList,double x)” .
- If the data value entered is present within the link list, it returns true, else it returns false.
- Declare the main class.
- Create an empty list to enter the data values into the list.
- Copy is done using copy constructor.
- Input “5” numbers from user and insert the data values into the link list calling “void LinkedList::add(double n)” function.
- Print the data values of the nodes present in the link list.
- “int LinkedList::search(double x)” function is called to search the element present in the link list and prints the position of the element.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
True or False The objects of a class can be stored in an array, but not in a List.
Scores Class
Write a class named Scores which should have the following attribute:
• _scores (a list to hold test scores, 0 - 100. Initially empty. )
The Scores class should have an _init__ method that creates the _scores attribute. It should also have the following methods:
• add_score: this method adds a score to the __scores list. It accepts a single score as it's' only argument.
• get_average: this method accepts no arguments. If _scores is empty, this method returns -1. Otherwise, it returns the average of all scores in _scores.
• get_high_score: this method accepts no arguments. if scores is empty, this method returns -1. Otherwise, it returns the highest score in __scores.
• get_low_score: this method accepts no arguments. if scores is empty, this method returns -1. Otherwise, it returns the lowest score in scores.
• _str_: This method returns a string similar to the following (assuming the _scores contains 89, 77, 93):
Once you have written the class, write a program that…
C++ function Linked list
Write a function, to be included in an unsorted linked list class, called replaceItem, that will receive two parameters, one called olditem, the other called new item. The function will replace all occurrences of old item with new item (if old item exists !!) and it will return the number of replacements done.
Chapter 17 Solutions
Starting Out With C++: Early Objects (10th Edition)
Ch. 17.1 - Prob. 17.1CPCh. 17.1 - Prob. 17.2CPCh. 17.1 - Prob. 17.3CPCh. 17.1 - Prob. 17.4CPCh. 17.2 - Prob. 17.5CPCh. 17.2 - Prob. 17.6CPCh. 17.2 - Why does the insertNode function shown in this...Ch. 17.2 - Prob. 17.8CPCh. 17.2 - Prob. 17.9CPCh. 17.2 - Prob. 17.10CP
Ch. 17 - Prob. 1RQECh. 17 - Prob. 2RQECh. 17 - Prob. 3RQECh. 17 - Prob. 4RQECh. 17 - Prob. 5RQECh. 17 - Prob. 6RQECh. 17 - Prob. 7RQECh. 17 - Prob. 8RQECh. 17 - Prob. 9RQECh. 17 - Write a function void printSecond(ListNode ptr}...Ch. 17 - Write a function double lastValue(ListNode ptr)...Ch. 17 - Write a function ListNode removeFirst(ListNode...Ch. 17 - Prob. 13RQECh. 17 - Prob. 14RQECh. 17 - Prob. 15RQECh. 17 - Prob. 16RQECh. 17 - Prob. 17RQECh. 17 - Prob. 18RQECh. 17 - Prob. 1PCCh. 17 - Prob. 2PCCh. 17 - Prob. 3PCCh. 17 - Prob. 4PCCh. 17 - Prob. 5PCCh. 17 - Prob. 6PCCh. 17 - Prob. 7PCCh. 17 - Prob. 8PCCh. 17 - Prob. 10PCCh. 17 - Prob. 11PCCh. 17 - Prob. 12PCCh. 17 - Running Back Program 17-11 makes a person run from...Ch. 17 - Read , Sort , Merge Using the ListNode structure...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Basic javaarrow_forward8. 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_forwardData structure & Algorithum java program 1) Add a constructor to the class "AList" that creates a list from a given array of objects.2) Add a method "getPosition" to the "AList" class that returns the position of a given object in the list. The header of the method is as follows : public int getPosition(T anObject)3) Write a program that thoroughly tests all the methods in the class "AList".4) Include comments to all source code.arrow_forward
- Data structures find_color(colors:set, values:list) -> list The function will have two parameters. The first parameter is a set of strings known as Colors. A second parameter is a list of tuple-2 known as Values. Colors will contain a set of randomly selected colors. Values will contain a list of tuples of size 2. Each tuple will contain color (str) and a number (int). The function should look at each tuple in Values. For each tuple, add the number (the second value in the tuple) to a list of numbers if the color in the tuple (the first value in the tuple) is in Colors. In other words, find all tuples that have a color in the Colors and add the tuples numbers to a list. Finally, the function should return the list of numbers collected in the order they are found in the values list. Example: Colors: {'black', 'pink', 'yellow'} values: [('green', 100), ('yellow', 13), ('red', 6)] Expected: [13] Colors: {'yellow'} values: [('black', 54), ('pink', 5)] Expected: [] Colors: {'black',…arrow_forwardRemove Duplicates This function will receive a list of elements with duplicate elements, this function should remove the duplicate elements in the list and return a list without duplicate elements. The elements in the returned list must be in the same order that they were found in the list the function received. A duplicate element is an element found more than one time in the specified list.arrow_forwardstruct Node { int data; Node * next; }; Node • head; a. Write a function named addNode that takes in a variable of type int and inserts it at the head of the list. b. Write a function named removeNode that removes a node at the head of the list.arrow_forward
- Computer Engineering lab Assignment 3:- Apex (Salesforce) - Create an apex class - In the apex class we have to create 1 method. - Method return type is void & the argument is null. - Method : - Map<String,String> static 4 values---- Put the value at the time of initialization---- Put the value using the map method PUT.arrow_forwardComputer engineering question Assignment 3:- Apex (Salesforce)- Create an apex class - In the apex class we have to create 1 method.- Method return type is void & the argument is null.- Method : - Map<String,String> static 4 values---- Put the value at the time of initialization---- Put the value using the map method PUTarrow_forwardC++ Programming Language ::::::: Redo the same functions this time as nonmember functions please : NOTE: You can add only one function into the linked list class get_at_position which will return value of element at given position. 1) Insert before tail : Insert a value into a simply linked list, such that it's location will be before tail. So if a list contains {1, 2, 3}, insert before tail value 9 is called, the list will become {1, 2, 9, 3}. 2) Insert before value : Insert a value into a simply linked list, such that it's location will be before a particular value. So if a list contains {1, 2, 3}, insert before 2 value 9 is called, the list will become {1, 9, 2, 3}. 3)Count common elements : Count common values between two simply linked lists.So if a list1 contains {1, 2, 3, 4, 5}, and list2 contains {1, 3, 4, 6}, number of common elements is 3. 4) Check if sorted : Check if elements of simply linked lists are sorted in ascending order or not.So if a list contains {1, 3, 7, 8, 9}…arrow_forward
- CLASSES, DYNAMIC ARRAYS AND POINTERS Define a class called textLines that will be used to store a list of lines of text (each line can be specified as a string). Use a dynamic array to store the list. In addition, you should have a private data member that specifies the length of the list. Create a constructor that takes a file name as parameter, and fills up the list with lines from the file. Make sure that you set the dynamic array to expand large enough to hold all the lines from the file. Also, create a constructor that takes an integer parameter that sets the size of an empty list. in C++ Write member functions to: remove and return the last line from the list add a new line onto the end of the list, if there is room for it, otherwise print a message and expand the array empty the entire list return the number of lines still on the list take two lists and return one combined list (with no duplicates) copy constructor to support deep copying remember the destructor!arrow_forward#include using namespace std; struct ListNode { string data; ListNode *next; }; int main() { ListNode *p, *list; list = new ListNode; list->data = "New York"; p new ListNode; p->data = "Boston"; list->next = p; p->next = new ListNode; p->next->data = "Houston"; p->next->next = nullptr; // new code goes here Which of the following code correctly deletes the node with value "Boston" from the list when added at point of insertion indicated above? O list->next = p; delete p; O p = list->next; %3D list->next = p->next; delete p; p = list->next; list = p->next; delete p; O None of these O p = list->next; %3D list->next = p; %3D delete p;arrow_forwardArithmetic progression def arithmetic_progression(items): An arithmetic progression is a numerical sequence so that the stride between each two consecutive elements is constant throughout the sequence. For example, [4, 8, 12, 16, 20] is an arithmetic progression of length 5, starting from the value 4 with a stride of 4.Given a non-empty list items of positive integers in strictly ascending order, find and return the longest arithmetic progression whose all values exist somewhere in that sequence. Return the answer as a tuple (start, stride, n) of the values that define the progression. To ensure unique results to facilitate automated testing, if there exist several progressions of the same length, this function should return the one with the lowest start. If several progressions of equal length emanate from the lowest start, return the progression with the smallest stride. items Expected result [42] (42, 0, 1) [2, 4, 6, 7, 8, 12, 17] (2, 2, 4) [1, 2, 36, 49, 50, 70, 75, 98,…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 LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr