Question

•• R5.9We have seen three kinds of variables in C++: global variables, parameter variables, and local...

•• R5.9We have seen three kinds of variables in C++: global variables, parameter variables, and local variables. Classify the variables of Exercise •• R5.8 according to these categories.

1 int a = 0;

2 int b = 0;

3 int f(int c)

4 {

5 int n = 0;

6 a = c;

7 if (n < c)

8 {

9 n = a + b;

10 }

11 return n;

12 }

13

14 int g(int c)

15 {

16 int n = 0;

17 int a = c;

18 if (n < f(c))

19 {

20 n = a + b;

21 }

22 return n;

23 }

24

25 int main()

26 {

27 int i = 1;

28 int b = g(i);

29 cout << a + b + i << endl;

30 return 0;

Homework Answers

Answer #1

1 int a = 0; // global variables
2 int b = 0; // global variables
3 int f(int c) // here c is parameter
4 {
5 int n = 0; // c is local variable
6 a = c; // here a is global variable
7 if (n < c)

8 {

9 n = a + b; // a,b are global variable

10 }

11 return n;

12 }

13

14 int g(int c) // here the c is parameter

15 {

16 int n = 0; // here n is local variable

17 int a = c; // here a is local variable

18 if (n < f(c))

19 {

20 n = a + b; // here a is local variable and b is global variable

21 }

22 return n;

23 }

24

25 int main()

26 {

27 int i = 1; // here i is local variable

28 int b = g(i); // here b is local variable

29 cout << a + b + i << endl; // a,b is global variable

30 return 0;

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath>...
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath> using namespace std; void divisors(int num); int main () {    char repeat;    int num;       while (repeat !='n')    {        cout << "Enter a number: ";        cin >> num;        divisors(num);        cout << "Continue? (y or n): ";        cin >> repeat;    }    return 0; } void divisors(int num) {   ...
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std;...
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std; int theArray[] = { 5, 11, -29, 45, 9, -1}; void sumPos(int ary[], int len, int &sum) {    sum = 0;    for (int i = 0; i < len; i++)            if (ary[i] > 0)                sum = sum + ary[i]; } int main() {    int total;    sumPos(theArray, 6, total);    for (int k=0; k < 6; k++)      cout...
Given the following function in C++: int main(void) { int a = 2; int b =...
Given the following function in C++: int main(void) { int a = 2; int b = myFunction(a); a = b + 1; b = myFunction(a); cout << ”b = ” << b << endl; return 0; } int z = myFunction(int x) { static int n = 0; n = n + 1; int z = x + n; return z; } What is printed by the cout on the screen?
can someone edit my c++ code where it will output to a file. I am currently...
can someone edit my c++ code where it will output to a file. I am currently using xcode. #include <iostream> #include <cctype> #include <cstring> #include <fstream> using namespace std; bool inputNum(int [],int&,istream&); void multiply(int[],int,int[],int,int[],int&); void print(int[],int,int,int); int main() {ifstream input; int num1[35],num2[35],len1,len2,num3[60],len3=10,i; input.open("multiplyV2.txt"); //open file if(input.fail()) //is it ok? { cout<<"file did not open please check it\n"; system("pause"); return 1; }    while(inputNum(num1,len1,input)) {inputNum(num2,len2,input); multiply(num1,len1,num2,len2,num3,len3); print(num1,len1,len3,1); print(num2,len2,len3,2); for(i=0;i<len3;i++) cout<<"-"; cout<<endl; print(num3,len3,len3,1); //cout<<len1<<" "<<len2<<" "<<len3<<endl; cout<<endl;    } system("pause"); } void...
Please write variables and program plan (pseudocode) of the C++ programming code below: #include <iostream> #include...
Please write variables and program plan (pseudocode) of the C++ programming code below: #include <iostream> #include <cmath> using namespace std; int getWeight(); float deliveryCharge(int weight); void displayCharge(int weight); int main () {    displayCharge(getWeight());    return 0; }   int getWeight() {    int weight;    cout << "Enter package weight (oz): ";    cin >> weight;    return weight; } float deliveryCharge(int weight) {    if (weight > 16)    {        return (((weight - 16) / 4) *...
Do While loop on C++ I need to program a do while loop in which the...
Do While loop on C++ I need to program a do while loop in which the user have to choose between option A,a, B,b or C,c. I need a do while loop that if other letter (different from options is choose) the loop print a cout saying "Invalid selection. Plese, enter the selection again.   I have one, but isn't working well int main() { char option; do { cout<<"Please choose one of the following options: "<<endl<<endl; cout<<"Option A - Julian...
Strings The example program below, with a few notes following, shows how strings work in C++....
Strings The example program below, with a few notes following, shows how strings work in C++. Example 1: #include <iostream> using namespace std; int main() { string s="eggplant"; string t="okra"; cout<<s[2]<<endl; cout<< s.length()<<endl; ​//prints 8 cout<<s.substr(1,4)<<endl; ​//prints ggpl...kind of like a slice, but the second num is the length of the piece cout<<s+t<<endl; //concatenates: prints eggplantokra cout<<s+"a"<<endl; cout<<s.append("a")<<endl; ​//prints eggplanta: see Note 1 below //cout<<s.append(t[1])<<endl; ​//an error; see Note 1 cout<<s.append(t.substr(1,1))<<endl; ​//prints eggplantak; see Note 1 cout<<s.find("gg")<<endl; if (s.find("gg")!=-1) cout<<"found...
Explain each line in main (you can put it in the comments) and explain why the...
Explain each line in main (you can put it in the comments) and explain why the output looks how it looks. #include <iostream> using namespace std; class A { public:        A()        {               n=0;        }        A(int x)        {               n=x;        }        void f()        {               n++;        }        void g()        {               f();               n=n*2;               f();        }        int k()        {               return n;        }       ...
The C++ program steps through the array x[]. For each i, if x[i] < x[i+1], i...
The C++ program steps through the array x[]. For each i, if x[i] < x[i+1], i is saved in the array ascend[], in order. Compile and run the program; it should print 0 4 5. In this exercise, you’ll try to translate the C++ program to MIPS. Some of the more tedious parts are already given in Assignment3.F19.s. You won’t have to write the data allocation sections, some of the initializations, and the output loop at the end. So the...
C++ Please and thank you. I will upvote Read the following problem, and answer questions. #include<iostream>...
C++ Please and thank you. I will upvote Read the following problem, and answer questions. #include<iostream> using namespace std; void shownumbers(int, int); int main() { int x, y; cout << "Enter first number : "; cin >> x; cout << "Enter second number : "; cin >> y; shownumbers(x, y); return 0; } void shownumbers(int a, int b) { bool flag; for (int i = a + 1; i <= b; i++) { flag = false; for (int j =...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • In addition to external heat gain, HVAC equipment must remove internally generated heat to maintain comfortable...
    asked 21 minutes ago
  • Write an M-File scripts that converts temperature in degrees Fahrenheit ( °F) to degrees Centigrade (...
    asked 37 minutes ago
  • Two spherical soap bubbles in air (with local pressure P0) come into contact and fuse to...
    asked 37 minutes ago
  • determine the combination of alkaline earth cations and test solution anions that produce a precipitate. Predict...
    asked 41 minutes ago
  • Homework of Unit Three 1. Situational Writing Situation: Value Link Co.,Ltd.(Add.:27 Srinakarin street,Bangkok,Thailand, Zip:10250, Fax:66-02-330-9765), deals...
    asked 52 minutes ago
  • Rothamsted Experimental Station (England) has studied wheat production since 1852. Each year, many small plots of...
    asked 1 hour ago
  • 51. Which of the following type of dementia is the most common among all dementias A.Parkinsons...
    asked 1 hour ago
  • A mad physicist assembled an EM wave generator. He claims that the generator is able to...
    asked 1 hour ago
  • Question # 3: Solve the following conversions: a. %01000101 = ? (Decimal) b. 24510 = %____________...
    asked 1 hour ago
  • 5. The Scientist-Practitioner model A. Focuses on the objective assessment of data only B. Focuses on...
    asked 1 hour ago
  • 7) A disk is initially spinning about its center at 18 rad/s counter-clockwise and a constant...
    asked 1 hour ago
  • -Two restaurants, Epicurean Eats and Dino’s Diner, operate in the same neighborhood. Epicurean Eats is a...
    asked 1 hour ago