| 1. |
Write a pseudocode to solve s=(A+B+C)/Y |
|
Answer» Let’s assume the meaning of the statement is to compute the thing on the right and store the result into the thing on the left. (This matches most common high-level languages, but in some languages, this might just as easily have been a comparison rather than an assignment.) Let’s further assume that all the letters are variables, all of them have the same data type, the data types are numeric, and the +, /, and parentheses operators all have the typical algebraic meanings for numeric expressions. (In some languages and/or with some data types, the + might mean concatenation instead of addition, etc.) If your goal is to implement the assignment statement in a common high-level language, the statement itself should be just fine as pseudocode:
But the variable names here are not very descriptive. Both in pseudocode and in actual code, it would be best to use variable names that reflect what the variables actually contain. Since I don’t know what your formula represents, I won’t suggest specific names. If you want to be explicit about the order in which everything happens, then a pseudocode description might look something like:
I introduced T as a temporary variable. If your goal were to implement the assignment statement in an assembly language, you might want to break it down further into the individual steps, which would better map to your target language. In this case, the pseudocode might be something like:
Or even more detail that gets even closer to what’s actually happening at the low level in your target system:
I introduced two temporaries here, R1 and R2, which might map to CPU registers in the actual assembly language code. Pseudocode can vary widely and be used for many different purposes. So, you need to figure out the goal of the pseudocode, and choose a level of abstraction and detail that serves that goal. And follow the pseudocode guidelines you’ve been given, if any. By the way, writing pseudocode after your write the actual code is like writing an outline an outline after you've written the book report. The act of writing pseudocode has a lot less value, if you’ve already written the actual code. |
|