Schedule‎ > ‎

Project 8C Sorting - not used

Project A: Sort Function

In this project you write a sort function for two numbers that are input by the user.

Specifications

  1. Start with a new sketch and save the sketch using the name sortfun.
  2. Write a function with the following signature:
    /**
       Swaps values of the parameters provided the first parameter
       is larger than the second.
       @param a first input value
       @param b second input value
    */
    void sort(double& a, double& b)
    
    The function name must be sort. You may use any parameter names but must use the type specified.
  3. The function must swap the two parameters only if the first is greater than the second.
  4. In your loop() function:
    1. Get two numbers from the user and save them in variables
    2. Call the sort() function with the two input variables as arguments
    3. Print the variables after calling the sort() function
  5. Your program must operate like that shown in the Example Output shown below.
  6. In your README.txt show the operation of your program for the following examples and at least two original examples, with the program name "sortfun" as a heading.
    sortfun
    -------
    Enter the first number: 4.00
    Enter the second number: 2.00
    After applying sort() the values are: 2.00, 4.00
    
    Enter the first number: 3.00
    Enter the second number: 4.00
    After applying sort() the values are: 3.00, 4.00
    
  7. Submit your sortfun.ino file as part of this assignment.

Example Output

Sorting Two Numbers

Enter the first number: 4.00
Enter the second number: 2.00
After applying sort() the values are: 2.00, 4.00

Enter the first number: 3.00
Enter the second number: 4.00
After applying sort() the values are: 3.00, 4.00

^ top

Style Requirements

Remember to follow all the style rules from previous assignments, as well as the new rules we recently covered, including:

  1. File comment block (see: File Comment Block)
  2. Function naming conventions (See: Function Names)
  3. Indentation in functions and placement of curly braces (See: Indentation)
  4. Function comment blocks See: Function Comment Block)
  5. Use named constants instead of magic numbers (see: Limit Magic Numbers)
  6. Proper use of spaces around operators (see: Spacing Around Operators
Comments