
Kenneth L. answered 01/13/20
Experienced Computer Science Instructor
TLDR: While this answer does not include a specific solution to the problem, it does highlight some steps in developing an algorithmic or pseudocode solution to the problem.
To approach this sort of problem, I often consider that nearly every algorithm can be broken into the following set of phases:
- Collect the input.
- Perform transformative calculations (transform the input into the output).
- Produce the output.
Keep in mind that these phases may overlap depending upon the nature of the problem. For instance, in this case it appears there will be multiple inputs which are accumulated into a total which implies that there will be some overlap between the first and second phases. I recommend reducing the problem to a single input in your first draft of the solution, and then expand the solution to accommodate multiple inputs later. I think you'll find that it simplifies the process and helps understanding repetition (looping) easier.
So without giving away an actual algorithm for this problem, a basic outline of this simplified version of the problem (not really an true algorithm yet, and definitely not pseudocode) might look something like this (I've identified the phases described above)...
Collect dimensions from user (phase 1)
Determine area based on selected shape (phase 2)
Add area to total area (phase 2)
Determine costs for each service based on total area (phase 2)
Determine total cost (phase 2)
Output cost for each service (phase 3)
Output total cost (phase 3)
I recommend going into much further detail than this before moving on. An algorithm and pseudocode should clearly define each step or action of the solution to the problem. "Determine area based on selected shape" does not fully describe how the area is to be calculated or the shape determined, but those details should be included in your answer. Likely you will need at least 20-30 instructions to adequately get those details.
Of course, this outline still does not allow for multiple shapes to be entered, but the purpose of creating a starting draft solution is to work out all the details before complicating the solution by allowing repetition. Once you have all those instructions worked out, consider which instructions would need to be duplicated in order to allow for multiple inputs.
Now instead of just copying and pasting those duplicated instructions, you should incorporate some sort of repetition or looping structure into your psuedocode. In order to do that, you need to consider how to control the repetition. Do you ask the user how many shapes will be involved, thus count the number of inputs as they are entered? Or do you use some sentinel technique like having the user type "quit" when they are done? Determining what kind of repetition is to be done will change how your solution will be structured.
Writing a well thought out algorithm/pseudocode will eventually save lots of time when coding, so expect this process to take a while. Also, there will likely by multiple ways of solving this problem, so your solution would probably vary quite a bit from anyone else's (including my own) for this problem.