Computer Science flowchart help?

4 replies · 2K views · last reply
tinker99
Messages
8
Reaction score
0
I have a sample exam in which the teacher provided the answers for, but I am not understanding these flowcharts. I understand actual parameters and formal parameters, but not how I would get the output. Can someone help explain this to me? I have uploaded one of the questions with the answers.
 
Attachments
  • Handwritten exam solution with two flowcharts (Start, assignments to C, D, M, P, then B = C + WAI(D,K), and a WAI(S,B) method) beside memory-box tables for MAIN and METHOD, with answers for parameters and output 3, 4, -6, -5, 5.
    CS exam 1.JPG
    30 KB · Views: 610
We'll start at start, the first few stmts initialize variables, the next calls the wat() function.

So shift over to the second flowchart. Pay attention to the by value and by reference modifiers. By reference means the variable will be changed in the calling program so you need to remember that when you finish with the wat() function. The output stmt prints the answers which the teacher wants to see.
 
Thank you. I understand a little better now. I am just confused as to how we get -6 for k in the main and 8 for s and -8 for p in the method?
 
tinker99 said:
how we get -6 for k in the main
One example. In main, K is set to -2. It is passed by reference to B in WAT, so any change of B in WAT actually changes K. B is changed to B-S=(-2)-4 = -6. That is the final output.