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
Question
Book Icon
Chapter 15, Problem 2PC
Program Plan Intro

Analysis of Quicksort

Program Plan:

  • Include the required header files to the program.
  • Define “AbstractSort” class.
    • In public, declare the pure virtual function.
      • In the “get_comparison” function return the total number of comparison.
    • In protected, declare the “compare” function.
      • In the “reset_comparison” function reset the comparison value to “0”.
    • In private, declare the required variable.
  • Define the “compare” function outside the class definition.
    • Inside the function, increment the comparison count and return the number of comparison.
  • Define the derived class “Quicksort”.
    • In public, declare the “sort” function.
    • In private, declare the “quick” function and “partition” function.
  • Define the “quick” function.
    • If the least number is greater than the highest number, return the value to the function.
    • Call the “partition”, quick” functions.
  • Define the “partition” function.
    • Set the pivot value.
    • Declare and set the “front” variable.
    • If the “front” value is less than “u”, swap the values and increment the pivot variable.
    • Increment the “front” variable.
  • Define the “main()” function.
    • Declare and initialize the required variables.
    • Get the array value from the user.
    • Check the array value with array index.
      • If the array value is greater than index value exits the program.
    • Initialize the random number generator and generate the random numbers.
    • Create the object for the class “Quicksort”.
    • Call the “sort” function.
    • Display the result.

Blurred answer
Students have asked these similar questions
JAVA LANGUAGE
Don't use vector array .using c++ language
C++ programming Recall that in C++, there is no check on an array index out of bounds. However, during program execution, an array index out of bounds can cause serious problems. Also, in C++, the array index starts at 0. Design and implement the class myArray that solves the array index out of bounds problem and also allows the user to begin the array index starting at any integer, positive or negative. Every object of type myArray is an array of type int. During execution, when accessing an array component, if the index is out of bounds, the program must terminate with an appropriate error message. Consider the following statements: myArray list(5);                 //Line1 myArray myList(2, 13);    //Line 2 myArray yourList(-5, 9);   //Line 3 The statement in Line 1 declares list to be an array of five components, the component type is int, and the components are: list[0], list[1], ..., list[4]; The statement in Line 2 declares myList to be an array of 11 components, the component…

Chapter 15 Solutions

Starting Out with C++: Early Objects

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning