After you get with your client they say that our assumptions in the last problem wrong (we did it correctly, they just left out information which is why we review the problem statement with them before we go on to the next step). They now tell us that they charge a different price for walking dogs on the weekend.
You have been asked to write a computer program for a dog walking service. This business provides a unique service walking dogs. They charge $5.00 an hour per dog walked. On the weekends the charge is $10 per hour. They take dogs on walks that can span several hours and many of their clients have more than one dog that will be walked. All dogs for a client are walked at the same time and the same duration. They want to be able to find out after walking a client’s dogs how much they need to charge the owner.
Provide me with:
The problem statement
1. Assumptions:
2. Input
3. Calculations:
4. Output
Scroll down for the answer after you try to do it yourself first
Assumptions:
a. All dogs have the same walking fee
b. All dogs for a client are walked the same amount of hours
c. One client's fee will be calculated at a time
d. If weekday rate is $5
e. If a weekend rate is $10
Input:
a. Number of dogs
b. Hours walked
c. Is it the weekday? Yes/no
Calculations:
a. If Weekday then
Final fee =
number of dogs * hours walked * weekday rate
If not a weekday then
Final fee =
number of dogs * hours walked * weekend rate
Output:
a. "You need to charge the owner" & Final Fee
The human algorithm (step by step process)
Scroll down for the answer after you try to do it yourself first
Remember, we create the human algorithm from the problem statement (although we can go the other way if you find that creating the human algorithm is easier. We start out by declaring our constants (1-2), inputting our data (3-5), doing the math (6-8) then outputting the answer (9)
| Human algorithm
1. weekday rate = $5 |
Problem Statement (from above)
Assumptions Input: a. "You need to charge the owner" & Final Fee
|
The flowchart (using visual logic) Now we need to flowchart the above Human Algorithm. Remember each step is a different flowchart symbol. Don't combine steps.
Scroll down for the answer after you try to do it yourself first
Remember we create the flow chart directly from the human algorithm. 9 steps in the human algorithm, 9 symbols on the flowchart. If you open your human algorithm and visual logic together on the same screen, next to each other, the flowchart should be easy to create since we have already solved the problem.
![]() |
Human algorithm
1. weekday rate = $5 |
The write the visual basic script using html kit
Scroll down for the answer after you try to do it yourself first
We type the code directly from the flowchart since we have already solved the problem. Each symbol is a line of code. We get the DIM values from each assignment (rectangle) and each input. Then we just type the line of code the symbol represents. Assignments are already in vbscript syntax, for input you just add (inputbox(...)), for output you add (document.write....)
| Visual Basic Script <script language = "vbscript"> |
![]() |
<script language = "vbscript">
option explicit
DIM weekdayrate, weekendrate, numdogs, numhours, daytype, finalfee
weekdayrate = 5
'<----1. from flowchart and human algorithm
weekendrate = 10
'<----2. from flowchart and human algorithm
numdogs = inputbox("How many dogs?")
'<----3. from flowchart and human algorithm
numhours = inputbox("How many hours did you walk the dogs?")
'<----4. from flowchart and human algorithm
daytype = inputbox("Is it a weekday? yes or no")
'<----5. from flowchart and human algorithm
if daytype = "yes" then
'<----6. from flowchart and human algorithm
finalfee = numdogs * numhours * 5
'<----7. from flowchart and human algorithm
else
finalfee = numdogs * numhours *10
'<----8. from flowchart and human algorithm
End if
document.write "The fee is $" & finalfee
'<----9. from flowchart and human algorithm
</script>
Things to watch out for: Make sure your code is efficient. We could have placed the output under each calculation. The code would have ran just fine but you were not efficient. You would have had the same line of code twice. This makes it harder to find your errors (debugging) and more difficult for others to maintain. This is BAD code! In addition, you placed the constants 5 and 10 in the code rather than assigning them to weekdayrate and weekend rate. In small programs like this it doesn't see like a big deal but hiding these numbers in your code make it difficult to maintain so when you have values that are constant (we won't be asking users to input them) you want to place them into memory at the start of your program. That's where a code maintainer will expect to find them if they need to change the rates the dog walker charges.
<script language=vbscript>
option explicit
DIM numdogs, numhours, daytype, finalfee
numdogs = inputbox("How many dogs?")
numhours = inputbox("How many hours did you walk the dogs?")
daytype = inputbox("Is it a weekday? yes or no")
if daytype = "yes" then
finalfee = numdogs * numhours * 5 '
the 5 should be placed into memory after the DIM line
document.write "The fee is $" & finalfee
'This line is duplicated below
else
finalfee = numdogs * numhours *10 ' the 10 should be
placed into memory after the DIM line
document.write "The fee is $" & finalfee
'This line is duplicated above
End if
</script>