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

Concept explainers

Question
Book Icon
Chapter 15, Problem 20RQE
Program Plan Intro

Algorithm:

  • Start a program.
  • Declare a class named “Sorter”.
    • Declare a required member variables and pure virtual function.
    • In public, define the member function “set_Array()”.
      • Inside the function set the array and size of an array.
    • Define the “sort” function.
      • Inside the function, call the “sort()” function with an argument size.
  • Define the “sort” function.
    • If the size is less than 1, the condition will ended.
    • Find the position of largest value in array and put it at the end of the array.
      • Use the “compare ()” function for sorting the given array.
      • Swap a pair of array elements.
      • Decrement the size by 1.
  • Define the derived class “Incr_Sorter” from the class “Sorter”.
    • In private, define the pure virtual function “compare()”.
      • If the “x” value is greater than “y” value return true.
  • Define the derived class “Decr_Sorter” from the class “Sorter”.
    • In private, define the pure virtual function “compare()”.
      • If the “x” value is less than “y” value return true.
  • Inside the “main” function,
    • Create the objects for the classes.
    • Declare and initialize an array of 5 values.
    • Call the “Incr_Sorter” function.
    • Call the “print_Array()” function for displaying the output.
    • Call the “Decr_Sorter” function.
    • Call the “print_Array()” function for displaying the output.
  • Define the “print_Array()” function.
    • Display the array.

Blurred answer
Students have asked these similar questions
Using C++, design a class named sortedArray. In this class include three data members: capacity, size, and arr (a pointer that points to the first element of the array in the heap). In addition, design a member function named insert that adds elements to the end of the array and a function print that prints the elements of the array, which is equal to size. The elements of the array should be sorted. Create a member function called moveTowardEnd to be able to insert a new element and move the rest towards the end of the array. Likewise, create a member function called moveTowardFront to move the elements of the array towards the front after an element of the array is deleted. Create a member function named remove to delete an element of the array using “pass by value” and consequently moves the left-over elements to the front of the array to take place of the deleted element of the array. Output a message if an element not present in the array is attempted to be removed. Test your…
Object Oriented Programing: Create a class template for a class named GeneralStackthat holds  • A single data member as an array named stack of size 50 to store certain elements • Three member functions i.e. push(type) to add elements in the Stack, pop() to remove elements from the stack, and currentStatus() to check whether the array is filled or not. (A filled array is an array that has non-zero value at all of its indexes). In the main() function, create three objects with different data types of class General Stack and test the functionality of member functions for various values of data members for these objects.
write a c++ program

Chapter 15 Solutions

Starting Out With C++: Early Objects (10th 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