Programming Exercise:Arguments, Constants

Video Module 10, 11:Sup’rKlean

Due: In lab for full credit, or by October 15, 1995 by 10:00 pm for 70% credit.

Your instructor or TA may ask you to

do this exercise, possibly modified in some way

work on another assignment

Goal of Exercise

This exercise will illustrate the use of arguments within a VB/DOS program. Arguments are used to "pass" data to a SUB or function so that the SUB or function can carry out its task, based on the data that it has received. You have used arguments before, when passing strings to DisplayMessage and to other library modules. For example, when you use CALL DisplayMessage("Hello world!"), the string constant, "Hello World!" is an argument.

In this lab, you will be passing numeric constants and string constants as arguments to SUBs which you will write. Programs which effectively use arguments are easy to write, easy to understand and easy to modify when change becomes necessary.

The second purpose of this lab is to introduce parameters. In prior labs, you have been "passing" data to SUBs and functions using arguments. This lab illustrates how SUBs and functions "receive" data using parameters which are specified in parenthesis immediately following the name of the SUB or function.

Programs which use the arguments and parameters make it possible to use the same SUBs and functions at many places in the same program (with different data) and in many programs (via libraries.)

Background

The local Sup’rKlean has learned of your extraordinary programming abilities and has asked you to write a small program for them. It seems that the Sup’rKlean has an extremely inefficient clerk named Aligheiri Dante working for them. However, the customers seem to like Dante because he is always coming up with funny poetry to describe each customer , and corporate headquarters has asked you to write a program to simulate him when he is on vacation.

His job involves essentially three tasks.

Welcome the customer to Sup’rKlean.

Tell them when they can expect their laundry/dry cleaning.

Tell them how much the laundry/dry cleaning will cost.

However, things get more complicated. The clerk will only work on Monday, Wednesday, and Friday. Consequentially, the Sup’rKlean is only open on those days. In addition, Dante usually forgets what day it is and must always ask the customer before telling the customer to pick up the laundry/dry cleaning. On top of all that, old Aligheiri is especially lazy on Fridays, so he never tells them to pick up their clothes on a Friday.

In summary:

If the day is / He tells them to pick up their clothes on
Monday / Wednesday
Wednesday / Monday
Friday / Monday

The cost of cleaning clothes is based on the number of items.

Number of items / Total cost
1 / $2.00
2 / $4.00
3 / $5.00

Corporate headquarters has sent you this sample, (which they would like you to simulate as closely as possible), of Aligheiri Dante (the clerk) helping a customer:

"Hey dude, whas up?"

Customer acknowledges by clicking on OK.

"Woe. Hey Bud, what day is it anyway?"

Customer enters Monday.

"Oh yah. I guess your clothes will be ready in 2 days. That's Wednesday."

The customer again acknowledges him.

"Hey Bud, how many pieces of clothing ya got in that bag anyway?"

Customer enters 3.

"Woe, gonzo dude. That's gonna cost you 5 big ones."

The customer again acknowledges him

"Huh, Huh. Cool. Later Dude."

The customer drives away quickly.

Exercise (7 points)

Your assignment is to write a program which will simulate the job Dante does as closely as possible. You must write two SUBs for your program.

The first one, SUB TellWhenToPick will ask the user for the day of the week, and then tell the customer when the clothes will be ready.

The second SUB, TellCostof Cleaning will ask the user about the number of items of clothing and then display the cost of cleaning.

Both SUBs will be called from the Main Module. These SUBs may in turn call SUB DisplayNumInMiddle inside a selection structure. Details about the SUB DisplayNumInMiddle are given below.

Important Information

You should note that in order to simulate Dante’s work as closely as possible, you will need to display messages with a number in the middle. Here is a SUB to do this task. You should use it just as it written.

SUB DisplayNumInMiddle( message1$, number, message2$)

CALL DisplayMessage(message1$ + STR$(number) + message2$)

END SUB

This SUB takes three arguments. The first and last arguments should be strings, and the second should be numeric. You may use this anywhere in your program. (Remember that you do not declare this SUB because it is part of your program, not a Library Module.)

Note that the string constant "Monday" is different from the string constant "monday" which is different from the string constant "MONDAY"

Your program should accept these three strings as a legitimate day of the week. If the user types in "mONday" or any other string which does not match one of the three forms, your program should print a message saying that the user was trying to cheat Dante, and that his/her clothes will not be returned for two weeks.

You will also need to use several of the generic SUBs and functions. Read Appendix C for more information about these.

For information about the STR$() function, please read page B-17 of Appendix B.

Questions (3 points)

You should answer the following questions as REMarks at the bottom of your program.

1. Below are four different CALLs to the SUB DisplayNumInMiddle. Which ones are incorrect? why?

a. CALL DisplayNumInMiddle("That will cost you", "3", "bucks")

b. CALL DisplayNumInMiddle("That's", 2, "items.")

c. CALL DisplayNumInMiddle("You only need", 5)

d. CALL DisplayNumInMiddle( 15, "shirts with", "lots of bad stains.")

2. Rewrite the SUB DisplayNumIn Middle as a new SUB DisplayStringInMiddle so that it takes three arguments, but the first and last parameters should be numbers, and the second parameter should be a string.

Programming Exercise: Arguments, Constants page 1