Question Details

(solution) The following program is an example of very poorly used scope


The following program is an example of very poorly used scope rules. The mixture of local variables, global variables, pass-by-reference, pass-by-value, and repeated variable names makes it difficult to predict what will be printed. Enter the program, without line numbers, then compile and run the program. Save the output to a file using the script command. Edit the output file, by adding text that explains for each line of the output where the variable was declared and where it's value was assigned, using the line numbers to help. For example, part of the explanation of the first line of output would be: x was declared on line 9 and it was assigned the value 0 on line 9".

1 #include 
2 using namespace std;
3 int function1(int x, int &y);
4 int function2(int b, int &x);
5 int g = 4;
6 int main() {
7 int a = 1;
8 int b = 5;
9 int x = 0;
10 cout "Main 1: a = " a " b = " b;

11 cout 12 cout 13 {
14 int a = 7;
15 g = 10;
16 cout "Main 2: a = " a " b = " b;

17 cout 18 cout 19 }
20 x = function1(a,b);
21 cout 22 cout 23 cout 24 x = function2(a,b);
25 cout 26 cout 27 cout 28 }
29
30 int function1(int x, int &y) {

31 int a;
32 a = x-y;
33 g = x+y;
34 y = a+g;
35 cout 36 cout 37 cout 38 return a;
39 }
40

41 int function2(int b, int &x) {
42 int temp;
43 temp = b;
44 b = x;
45 x = temp;
46 temp = function1(b,x);
47 g = temp*x;
48 return temp;
49 }

 


Solution details:

Pay using PayPal (No PayPal account Required) or your credit card . All your purchases are securely protected by .
SiteLock

About this Question

STATUS

Answered

QUALITY

Approved

DATE ANSWERED

Sep 13, 2020

EXPERT

Tutor

ANSWER RATING

GET INSTANT HELP/h4>

We have top-notch tutors who can do your essay/homework for you at a reasonable cost and then you can simply use that essay as a template to build your own arguments.

You can also use these solutions:

  • As a reference for in-depth understanding of the subject.
  • As a source of ideas / reasoning for your own research (if properly referenced)
  • For editing and paraphrasing (check your institution's definition of plagiarism and recommended paraphrase).
This we believe is a better way of understanding a problem and makes use of the efficiency of time of the student.

NEW ASSIGNMENT HELP?

Order New Solution. Quick Turnaround

Click on the button below in order to Order for a New, Original and High-Quality Essay Solutions. New orders are original solutions and precise to your writing instruction requirements. Place a New Order using the button below.

WE GUARANTEE, THAT YOUR PAPER WILL BE WRITTEN FROM SCRATCH AND WITHIN A DEADLINE.

Order Now