Question

In: Computer Science

Describe the difference between passing an argument by value and passing an argument by reference. As...

Describe the difference between passing an argument by value and passing an argument by reference. As part of your answer, include the impact of changing the contents of the parameter variable in the calling part of the program for each argument type.

Using the properly aligned (use spaces instead of tabs) pseudocode format given in the textbook, design a module called GetNumber which uses a reference parameter variable to accept an Integer argument. The module should prompt the user to enter a number and then store the input in the reference parameter variable.

Using the properly aligned (use spaces instead of tabs) pseudocode format given in the textbook, design a nested decision structure to perform the following:

If amount_1 is greater than 100 and amount_2 is less than 500, display the greater of amount_1 and amount_2..

Using the properly aligned (use spaces instead of tabs) pseudocode format given in the textbook, design a For loop that displays the following set of numbers in the order given:

100, 95, 90, 85, . . . , 0

Solutions

Expert Solution

HI,

Q.Describe the difference between passing an argument by value and passing an argument by reference.

Answer: When a function is called, twe can pass the arguments in a function 1. passed by value or 2. passed by reference.

1.Pass by value means that a copy of the actual parameter’s value is made in memory.

Note: Changes made to the passed variable do not affect the actual value in pass by value.

2. Pass by reference (also called pass by address) means to pass the reference of an argument in the calling function to the corresponding formal parameter of the called function so that a copy of the address of the actual parameter is made in memory. refeence means address of the value stored in perticular variable.

Note: Changes to the value have an effect on the original data.if we will fetch the variaable vy refrence then original copy of data will be effected

Program1: Accepting integer by user input and storing integer in reference variable:

#include<iostream> 
using namespace std; 
  
void getNumber (int& first, int x) 
{ 
    cout << "x = " << first << endl ; 
    cout << "refernce = " << x << endl ; 
}   

int main() 
{ 
  int x ;     
  cout << "Type a integer number: ";    
  cin >> x;    
  int& reference = x; 
  getNumber(x, reference );
  
  return 0; 
} 

Program 2: Greated number b/w amount_1 and amount_2:

#include<iostream> 
using namespace std; 
  

int main() 
{ 
  int amount_1, amount_2;
  cout <<  "Please enter amount 1" << endl ; 
  cin>> amount_1;
  cout <<  "Please enter amount 2" << endl ; 
  cin>> amount_2;
  
  if(amount_1>100 && amount_2<500 )
  {
      if(amount_1>amount_2)
      {
          cout<<"Amount 1: "<<amount_1<<" is the largest";
      }
      else
      {
          cout<<"Amount 2: "<<amount_2<<" is the largest";
      }
      
  }
  else
  {
      cout<<" Incorrect input.Enter the correct numbers";
  }
  
  return 0; 
} 

Program 3: For loop to displat series 100, 95, 90, 85, 80, 75,........................, 15, 10, 5, 0,

#include <iostream>
using namespace std;
int main() {
        for (int x=100; x>=0; x=x-5) {
                cout << x << ", ";
        }
        return 0;
}

Thanks


Related Solutions

describe the difference between a relative cell reference, absolute cell reference, and a mixed cell reference...
describe the difference between a relative cell reference, absolute cell reference, and a mixed cell reference in a formula? In or after your explanation, please provide examples either in screenshots or in an attached Excel file that show the practical uses for one or all of these.
Explain the difference between a valid argument and a sound argument, and give an example of...
Explain the difference between a valid argument and a sound argument, and give an example of each.
Using an interneuron as your point of reference, describe the difference between excitatory graded potentials and...
Using an interneuron as your point of reference, describe the difference between excitatory graded potentials and action potentials. Include the following in your answer for EACH type of potential. A) WHERE the potential is generated in the neuron B) WHAT triggers the generation of the potential (“kind of stimulus” and type of ion channels that open/close) C) DISTANCE traveled (short/long) and INTENSITY over that distance (constant/decremental)
describe the difference between euthanasia and physician-assisted suicide. Select an argument for or against either euthanasia...
describe the difference between euthanasia and physician-assisted suicide. Select an argument for or against either euthanasia or physician-assisted suicide. How would you defend your argument?
In your own words, describe the difference between euthanasia and physician-assisted suicide. Select an argument for...
In your own words, describe the difference between euthanasia and physician-assisted suicide. Select an argument for or against either euthanasia or physician-assisted suicide. How would you defend your argument?
In reference to shares, explain the difference between market risk and specific risk. In reference to...
In reference to shares, explain the difference between market risk and specific risk. In reference to bonds, explain the difference between the dirty price of a bond and the clean price of a bond.
Describe the evolution of value-based purchasing. Explain if there is a difference between value-based purchasing (VBP)...
Describe the evolution of value-based purchasing. Explain if there is a difference between value-based purchasing (VBP) and pay-for-performance (P4P).
What is the difference between making an argument to a particular audience in writing; and making...
What is the difference between making an argument to a particular audience in writing; and making the same argument to a particular audience in speech? What changes have to made to the argument in either case? What additional considerations do you have as a speaker that you might not have as a writer?
Describe the difference between inpatient and outpatient facilities. Describe the difference between public, voluntary, and private...
Describe the difference between inpatient and outpatient facilities. Describe the difference between public, voluntary, and private hospitals. Find the hospital closest to your home, and define what type of hospital it is. Minimum 400 words please Intext citations and reference please Ref: An Introduction to Community Health. 8th ed. McKenzie, J.F., Pinger, R.P., Kotecki, J.E. Jones & Bartlett Learning. 2015   ISBN: 978-1284036596
The time value of an option is the difference between the
The time value of an option is the difference between the
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT