Problem Solving with C++ plus MyProgrammingLab with Pearson eText-- Access Card Package (9th Edition)
Problem Solving with C++ plus MyProgrammingLab with Pearson eText-- Access Card Package (9th Edition)
9th Edition
ISBN: 9780133862218
Author: Walter Savitch
Publisher: PEARSON
Question
Book Icon
Chapter 14, Problem 4PP
Program Plan Intro

Sorting an array of integers

Program Plan:

  • Include requires header file.
  • Declare the function for fill array, sort, swap values and index of smallest.
  • Define main function.
    • Create prompt statement.
    • Declare variables for sample array and number used.
    • Call the function “fillArray”.
    • Prompt statement for index of minimum number.
    • Call the function “indexOfSmallest”.
    • Call the function “sort”.
    • Prompt statement for sorted numbers.
    • Display the sorted number using “for” loop.
  • Define “fillArray” function.
    • This is function is used to read the numbers from user.
  • Define “sort” function.
    • This function is used to sort the number by recursively call the function “sort”.
    • In this function, first declare the variable for index of next smallest.
    • If the start index is less than “numberUsed – 1”, then
      • Compute the index of next smallest number by calling the function “indexOfSmallest” with arguments of array, start index, and number of values in array.
      • Call the function “swapValues” with argument array of start index and array of next element index.
      • Increment the start index.
      • Then recursively call the function “sort” with argument array “a”, starting index and number of values in a given array “a”.
  • Define “swapValues” function.
    • This function is used to swap the two numbers.
  • Define “indexOfSmallest” function.
    • This function is used to compute the index of smallest number by calling the function “indexOfSmallest” recursively.
    • In this function, first assign the minimum to array of starting index.
    • Then if the starting index is equal to “numberUsed – 1”, then returns the starting index value.
    • Otherwise, recursively call the function “indexOfSmallest” with three arguments such as array “a”, increment of start index by “1” and “numberUsed” and this function is assigned to a variable “indexOfMin”.
    • If the value of “min” is greater than “a[indexOfMin]”, then return the minimum index. Otherwise, return the starting index.

Blurred answer
Students have asked these similar questions
Of the five primary components of an information system (hardware, software, data, people, process), which do you think is the most important to the success of a business organization? Part A - Define each primary component of the information system. Part B - Include your perspective on why your selection is most important. Part C - Provide an example from your personal experience to support your answer.
Management Information Systems
Q2/find the transfer function C/R for the system shown in the figure Re ད
Knowledge Booster
Background pattern image
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