Computer Science flowchart help?

Click For Summary
The discussion focuses on understanding flowcharts related to a computer science exam, specifically regarding the output of variables when using by value and by reference modifiers. The user seeks clarification on how the output values are derived from the flowcharts provided by the teacher. It is explained that passing variables by reference allows changes made within a function to affect the original variable in the calling program. An example illustrates that when the variable K is set to -2 and modified in the function, it results in a final output of -6. The user expresses improved understanding after the explanation.
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

  • CS exam 1.JPG
    CS exam 1.JPG
    30 KB · Views: 574
Technology news on Phys.org
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.
 
Thank you. I understand now:)
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
Replies
2
Views
1K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 0 ·
Replies
0
Views
1K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 32 ·
2
Replies
32
Views
5K
Replies
29
Views
5K
  • · Replies 34 ·
2
Replies
34
Views
4K