Today’s exercise is simple, but leads me to ask a question. Here is the exercise, taken directly from /r/learnprogramming:

Draw the hierarchy chart and then plan the logic for a program needed by the sales manager of The Henry Used Car Dealership.

  1. The program will determine the profit on any car sold. Input includes the sale price and actual purchase price for a car.
  2. The output is the profit, which is the sale price minus the purchase price.
  3. Use three modules. The main program declares global variables and calls housekeeping, detail, and end-of-job modules.
  4. The housekeeping module prompts for and accepts a sale price. The detail module prompts for and accepts the purchase price, computes the profit, and displays the result. The end-of-job module displays the message Thanks for using this program.

I have written the actual program, but I am struggling with the hierarchy chart. Can someone give me any guidance on this one?

Is this for real? Separate modules for each statement? Why does the detail module get input, compute profit and display the result? If you have to have separate modules to ask for the purchase price and say thank you, why not split getting the sale price, computing the profit, and printing the result into separate modules? Is this how programming students are taught these days? To take a fundamentally simple program and make it ridiculously complex by splitting it into modules? What would David Parnas say about this modularization?

Your task is to write a program to compute profit for The Henry Used Car Dealership; you might also help me understand the way this program is intended to be modularized. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

Advertisements

Pages: 1 2