iOS Development

Course No. 10-152-139

Assignment 10-1

About rounding…

  • Create a new Xcode command-line project. Name the project Assignment-10-1.
  • Include the math.h library.

Program steps and features.

  • Write a program that has a total of three (3) functions.
    • A main() function.
    • An output function.
    • A calculation function.
  • The main() function will call the output function and send one double argument. It will only contain calls to the output function. No variables or printf statements allowed.
  • The output function will have these features:
    • One parameter which is a double.
    • A descriptive name based on what it does.
    • The following variables, all of type double
      • a variable to hold the ceiling value.
      • a variable to hold the floor value.
      • a variable to hold the truncated value.
      • a variable to hold a value rounded to the hundredths. (two decimal places)
      • a variable to hold a value rounded to the thousandths. (three decimal places)
    • The function will call the calculation function.
    • The function will use a printf statement to output the input value and the calculated values.
  • The calculation function will have these features:
    • The return type for the function will be void.
    • The function will have the following parameters.
      • a double for the input value
      • a pointer to a double for the ceiling value.
      • a pointer to a double for the floor value.
      • a pointer to a double for the truncated value.
      • a pointer to a double for the value rounded to hundredths.
      • a pointer to a double for the value rounded to thousandths.
    • The function will have no printf statements.
    • The function will calculate the following and assign the results to the variables that the pointer parameters are pointing to.
    • The function will perform the following calculations:
      • Use the ceil() function to determine the ceiling value of the input number.
      • Use the floor() function to determine the floor value of the input number.
      • Use the trunc() function to determine the truncated value of the input number.
      • Use the round() function to determine the value of the input number rounded to the hundredths (2 decimal places). This will require an intermediate calculation.
      • Use the round() function to determine the value of the input number rounded to the thousandths (3 decimal places). This will require an intermediate calculation.
    • Assign all results to the appropriate pointer location.
  • In the main() function, call the output function at least 5 times. You must use the following values in 2 of the calls to the output function.
    • 999.999999999999
    • 25.5
  • Sample output for one call to the output function:
  • Remember that this sample data is not accurate. This is for the look of the output only.
  • You will have the above output for at least 5 input values.