Simple Program Construction with Pseudocode » Laundry!
We haven’t figured out when we should do laundry or even if we have enough clothes to wear for today. How are we going to make that happen?
Let’s assume that we don’t need to track individual pieces of clothing. We just need to track how many of each type of clothing we have. We could also then track how many of each type of clothing is still clean. It is really nice to think of your wardrobe as a table of data.
Tops
Bottoms
Short-sleeved
Long-sleeved dress
T-shirt
Long-sleeved
Shorts
Pants
Athletic shorts
Pajama pants
6
3
3
2
5
5
3
2
The first row of the table is unnecessary, but is here to make it clearer what each column is referring to. One could also make two separate tables, one for tops and one for bottoms. It is more efficient to use only one table, but it may be harder to think about that framework if this is your first time programming.
When we pick out an outfit, we would then need to subtract those pieces of clothing from our wardrobe. Let’s assume that if we get down to zero clean individual pieces of clothing, we would want to do laundry. So we would then also want to send a message to ourselves to do the laundry to make sure we do some before the next day.
Question 1 of 2
Using the pseudocode we have written so far, where would you put the subtraction from the wardrobe for the most efficient coding/least repetition of the same pseudocode? Type into the code in the box to add your subtraction text.
Although you may have been tempted to place the subtraction immediately after the selection of that piece of the outfit, it is making you repeat the pseudocode. Instead, it is best to place the subtraction at the end of the program so you would only have to do the subtraction once and you wouldn’t have to repeat the pseudocode four separate times.
Our pseudocode for the entire program we have so far is this:
1. Use app to gather forecast high temperature for today. 2. Use calendar to find whether it is a workday or weekend. 3. Catalog your entire wardrobe into short-sleeved, long-sleeved dress, t-shirt, and long-sleeved tops, and shorts, pants, athletic shorts, and pajama pants. 4. If today is a weekend a. If the forecast temperature is at or above 70°F, select a t-shirt, else select a long-sleeved top. b. If the forecast temperature is above 60°F, select athletic shorts, else select pajama pants. else (today is a workday) a. If the forecast temperature is at or above 70°F, select a short-sleeved top, else select a long-sleeved dress top. b. If the forecast temperature is above 60°F, select shorts, else select pants. 5. Subtract today’s outfit from your clean wardrobe.
There are other ways to do this, like nesting the socks and underwear into the if statements, or subtracting socks and undergarments before the outfit is ever populated with tops and bottoms. In the end, subtracting out the outfit as a whole is the easiest way to make the pseudocode and thus code as efficient as possible.
1. Use app to gather forecast high temperature for today. 2. Use calendar to find whether it is a workday or weekend. 3. Catalog your entire wardrobe into short-sleeved, long-sleeved dress, t-shirt, and long-sleeved tops, and shorts, pants, athletic shorts, pajama pants, socks, and undergarments. 4. If today is a weekend a. If the forecast temperature is at or above 70°F, select a t-shirt, else select a long-sleeved top. b. If the forecast temperature is above 60°F, select athletic shorts, else select pajama pants. else (today is a workday) a. If the forecast temperature is at or above 70°F, select a short-sleeved top, else select a long-sleeved dress top. b. If the forecast temperature is above 60°F, select shorts, else select pants. 5. Select socks and undergarments from wardrobe for outfit 6. Subtract today’s outfit from your clean wardrobe.