The Henry Used Car Dealership
March 15, 2019
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.
- The program will determine the profit on any car sold. Input includes the sale price and actual purchase price for a car.
- The output is the profit, which is the sale price minus the purchase price.
- Use three modules. The main program declares global variables and calls housekeeping, detail, and end-of-job modules.
- 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.
HIPO charts are so 1970s. A more modern exercise would require an 11-way multiple-inheritanced class hierarchy.
It does seem a little old-fashioned. This book seems to be the source: https://books.google.co.uk/books?id=s72HJL9Z-4AC&pg=PT97
Here’s a Haskell version. Its only trick is that it will prompt repeatedly until you enter a valid amount.
Here’s a solution in Python.
Example Usage: