Next: Further User-defined functions in Up: Introduction to User-defined functions Previous: Review Questions

Exercises

  1. Write a function which draws a line of n asterisks, n being passed as a parameter to the function. Write a driver program (a program that calls and tests the function) which uses the function to output an m$\times$ n block of asterisks, m and n entered by the user.

  2. Extend the function of the previous exercise so that it prints a line of n asterisks starting in column m. It should take two parameters m and n. If the values of m and n are such that the line of asterisks would extend beyond column 80 then the function should return false and print nothing, otherwise it should output true and print the line of asterisks. Amend your driver program so that it uses the function return value to terminate execution with an error message if m and n are such that there would be line overflow.

    Think carefully about the test data you would use to test the function.

  3. Write a function which converts a sum of money given as an integer number of pence into a floating point value representing the equivalent number of pounds. For example 365 pence would be 3.65 pounds.



Next: Further User-defined functions in Up: Introduction to User-defined functions Previous: Review Questions