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 2PC
Program Plan Intro

List Copy Constructor

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.
    • A constructor to copy the link list member elements is called.
      • LinkedList(LinkedList &list1);
    • A function “makeCopy(ListNode *pList)” is created to make copy of distinct elements in the list.
    • 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.
  • 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.
    • Check whether a data value is a member of the linked list or not by calling the “bool LinkedList::isMember(double n)” function.
    • Print whether the data value entered is present within the link list or not.

Blurred answer
Students 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…
addCourse: accepts an object of type Course as the first parameter and the idNum of the Student as the second parameter. The Course can be added only if the Student object with the specified idNum exists in the studentsList, Course does not exist in the coursesRegistered list for the Student, After adding the course, the number of credits, do not exceed 18. If the course is added successfully, return true, else return false.
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