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

Concept explainers

Question
Book Icon
Chapter 16, Problem 8PC
Program Plan Intro

Modification of “SearchableVector” class

Program plan:

SimpleVector.h:

  • Include the required header files in the program.
  • Define the template class “SimpleVector”:
    • Declare the required class data members and exception function under “private” access specifier.
    • Declare the required class member functions and class constructor under “public” access specifier.
  • Define the “SimpleVector” function:
    • Get the array size and allocate the memory for corresponding array size
    • If allocation gets fail, then call the “memError()” function.
    • Else initialize the array elements.
  • Define the copy constructor of the “SimpleVector” function:
    • Copy the array size and allocate the memory for corresponding array size
    • If allocation gets fail, then call the “memError()” function.
    • Else copy the array elements.
  • Define the “~SimpleVector” class destructor:
    • Delete the allocated memory for the array.
  • Define the “getElement” function:
    • Get the array subscript and check it is in the array range.
    • If not then call the exception function.
    • Return the subscript.
  • Define the operator overload for “[]” operator
    • Get the array subscript and check it is in the array range.
    • If not then call the exception function.
    • Return the subscript.
  • Define the “push_back()” function:
    • Get the element which is going to insert.
    • Create a new array and allocate the memory for the array which is greater than 1 from an old array.
    • Copy the elements from old array to new array.
    • Insert the new element at the last of the array.
    • Delete the old array and make the pointer points the new array
    • Finally adjust the array size.
  • Define the “pop_back()” function:
    • Save the last element which is going to delete.
    • Create a new array and allocate the memory for the array which is lesser than 1 from an old array.
    • Copy the elements from old array to new array.
    • Delete the old array and make the pointer points the new array
    • Finally adjust the array size.
    • Return the deleted value.

SearchableVector.h:

  • Include the required header files in the program.
  • Define the template class “SearchableVector”, which is derived from the above class template “SimpleVector”:
    • Declare the required class member functions and class constructor under “public” access specifier.
  • Define the copy constructor of the “SearchableVector” function:
    • Call the base class copy constructor for copying the array size and allocate the memory for corresponding array size.
    • Copy the array elements.
  • Define the function “findItem”
    • Declare the required variables in the function.
    • Get the element from the function call.
    • Using while loop
      • Find the middle element of the array.
      • Check the middle element is the searching element.
        • If so, then return the array subscript.
      • Else, check the middle element is greater than the searching element.
        • If so, decrease the last index value.
      • Else, increase the starting index value.
    • If the element is not found, then return -1 as the array subscript.

Main.cpp:

  • Include the required header files in the program.
  • Create an object for the class “SearchableVector” for integer type.
  • Create an object for the class “SearchableVector” for double type.
  • Use for loop to iterate array elements
    • Insert the integer value on integer array.
    • Insert the double value on double array.
  • Using for loop, display an integer array on the output screen.
  • Using for loop, display the double array on the output screen.
  • Call the function “findItem” using the searching element which is integer.
  • Compare the result of the function and display the message according to the condition.
  • Do the same again using double value.

Blurred answer
Students have asked these similar questions
Unique Words Summary Specifications:You are tasked to implement an abstract data type class which takes in a given input file called input.txt, and processes, identifies and sorts all unique word instances found in the file. Sample InputHi hello hi good bye goodbye Bye bye good say Sample OutputBye Hi bye hello hi say The input.txt file is found along with the zip folder where this instructions file also came along with. Note: you are not allowed to use pythonic lists, and its methods and functions, and string methods. However the use of the file handling methods (read readlines and readline) are allowed for this project.
Unordered Sets |As explained in this chapter, a set is a collection of distinct elements of the same type. Design the class unorderedSetType, derived from the class unorderedArrayListType, to manipulate sets. Note that you need to redefine only the functions insertAt, insertEnd, and replaceAt. If the item to be inserted is already in the list, the functions insertAt and insertEnd output an appropriate message, such as 13 is already in the set. Similarly, if the item to be replaced is already in the list, the function replaceAt outputs an appropriate message. Also, write a program to test your class.
Use the array based list headers for queue. Call your function to test its functionality. Here are the headers: #ifndef H_arrayListType #define H_arrayListType #include <iostream> using namespace std;   template <class elemType> class arrayListType { public: const arrayListType<elemType>& operator=(const arrayListType<elemType>&); //Overloads the assignment operator bool isEmpty() const; //Function to determine whether the list is empty //Postcondition: Returns true if the list is empty; // otherwise, returns false. bool isFull() const; //Function to determine whether the list is full //Postcondition: Returns true if the list is full; // otherwise, returns false. int listSize() const; //Function to determine the number of elements in //the list. //Postcondition: Returns the value of length. int maxListSize() const; //Function to determine the maximum size of the list //Postcondition: Returns the value of maxSize. void print() const; //Function to…

Chapter 16 Solutions

Starting Out With C++: Early Objects, Student Value Edition (9th Edition)

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