Starting Out with C++: Early Objects (9th Edition)
Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 17, Problem 3PC
Program Plan Intro

List Print

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 insert elements into the linked list “void add(double n)”is defined.
    • Function to check whether a particular node with a data value n is a part of linked list or not “bool isMember(double n)”.
    • 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.
  • 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.

Blurred answer
Students have asked these similar questions
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.
(Circular linked lists) This chapter defined and identified various operations on a circular linked list.a. Write the definitions of the class circularLinkedList and its member functions. (You may assume that the elements of the circular linked list are in ascending order.)b. Write a program to test various operations of the class defined in (a).
C++The List class represents a linked list of dynamically allocated elements. The list has only one member variable head which is a pointer that leads to the first element. See the following code for the copy constructor to List. List (const List & list) {          for (int i = 0; i <list.size (); i ++)       {                    push_back (list [i]);           } } What problems does the copy constructor have? Select one or more options: 1. List (const List & list) {} does not define a copy constructor. 2. The list parameter should not be constant. 3. The new elements will be added to the wrong list. 4. Copy becomes shallow rather than deep. 5. The copy will create dangling pointers. 6. Copying will create memory leaks. 7. The condition must be: i <size () 8. head is never initialized.
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning