Starting Out with C++: Early Objects
Starting Out with C++: Early Objects
8th Edition
ISBN: 9780133360929
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: Addison-Wesley
bartleby

Concept explainers

Question
Book Icon
Chapter 15, Problem 18RQE
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
Write the definition of the function template reverseVector to reverse the elements of a vector object. template<class elemType> void reverseVector(vector<elemType> &list);   //Reverses the elements of the vector list. //Example: Suppose list = {4, 8, 2, 5}. // After a call to this function, list = {5, 2, 8, 4}.   Also, write the (C++) program to test the function reverseVector. When declaring the vector object, do not specify its size. Use the function push_back to insert elements in the vector object.
Binary Search Write a C++ Program for searching an element on a given list of integers using the Binary Search method.Strictly adhere to the Object-Oriented specifications given in the problem statement. All class names, member variable names, and function names should be the same as specified in the problem statement.Initialize the array size in the constructor of the Search class.  Function Description int search(int n, int k) The function defines the logic for searching an element from the given array.If the element is found return '1'. Otherwise, return '0'. Input Format:The first line is an integer 'n' which corresponds to the number of elements in the array.The next 'n' lines correspond to the elements of the array.The last line is an integer 'k' which corresponds to the key element to be searched.Output Format:Print "Element Found" if the element is present in the array otherwise print "Element not Found".[All text in bold corresponds to the input and the rest…
In C++, define a “Conflict” function that accepts an array of Course object pointers. It will return two numbers:- the count of courses with conflicting days. If there is more than one course scheduled in the same day, it is considered a conflict. It will return if there is no conflict.- which day of the week has the most conflict. It will return 0 if there is none. Show how this function is being called and returning proper values. you may want to define a local integer array containing the count for each day of the week with the initial value of 0.Whenever you have a Course object with a specific day, you can increment that count for that corresponding index in the schedule array.

Chapter 15 Solutions

Starting Out with C++: Early Objects

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