1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
BigorU [14]
3 years ago
8

Given the following function definition:

Computers and Technology
1 answer:
neonofarm [45]3 years ago
4 0

The question is incomplete! Complete question along with its step by step answer is provided below!

Question:

Given the following function definition:

void calc (int a, int& b)

{

int c;

c = a + 2;

a = a * 3;

b = c + a;

}

x = 1;

y = 2;

z = 3;

calc(x, y);

cout << x << " " << y << " " << z << endl;

What is the output of the following code fragment that invokes calc?

a. 1 2 3

b. 1 6 3

c. 3 6 3

d. 1 14 9

e. None of these

Answer:

b. 1 6 3

Explanation:

In the given problem we have a function void calc which takes two input arguments a and b and updates its values according to following equations

c = a + 2;

a = a * 3;

b = c + a;

Then we call this function calc(x,y) by providing test values of

int x = 1;

int y = 2;

int z = 3;

and the output returns the values of x, y and z

cout << x << " " << y << " " << z << endl;

Lets find out what is happening here!

When the program runs we provide x=a=1 and y=b=2

c=a+2=1+2=3

a=a*3=1*3=3

b=c+a=3+3=6

So the updated values of a=x=3 and b=y=6?

NO!

The updated values are a=x=1 and b=y=6

WHY?

There are two ways to pass values

1. Pass by values -> value cannot change  (int a)

2. Pass by reference -> value can change (int& b)

Look at the function void calc (int a, int& b) ;

Here we are passing (int a) as a value and (int& b) as a reference, therefore x remains same x=1 and y gets changed to updated value y=6 and z remains same as z=3 since it wasnt used by function calc(x,y)

The right answer is:

b. 1 6 3

x=1, y=6, z=3

You might be interested in
Can i get any information on this website i'd like to know what its for ?
zloy xaker [14]

Explanation: torsearch.org is a safe search engine mainly used for dark wed purposes. It does not track your location nor give any personal information.

8 0
2 years ago
CS160 Computer Science I In class Lab 10
lianna [129]

Answer:

The program in Python is as follows:

fname = input("Enter the translation file name: ")

with open(fname) as file_in:

   lines = []

   for line in file_in:

       lines.append(line.rstrip('\n'))

myDict = {}

for i in range(len(lines)):

x = lines[i].split(":")

myDict[x[0].lower()] = x[1].lower()

print("Enter an English word to receive the Spanish translation.\nPress ENTER to quit.")

word = input("Enter an English word: ")

while(True):

if not word:

 break

if word.lower() in myDict:

 print("The Spanish word is ",myDict[word.lower()])

else:  

 print("I don’t have that word in my list.")

word = input("Enter an English word: ")

Explanation:

This prompts the user for file name

fname = input("Enter the translation file name: ")

This opens the file for read operation

with open(fname) as file_in:

This creates an empty list

   lines = []

This reads through the lines of the file

   for line in file_in:

This appends each line as an element of the list

       lines.append(line.rstrip('\n'))

This creates an empty dictionaty

myDict = {}

This iterates through the list

for i in range(len(lines)):

This splits each list element by :

x = lines[i].split(":")

This populates the dictionary with the list elements

myDict[x[0].lower()] = x[1].lower()

This prints an instruction on how to use the program

print("Enter an English word to receive the Spanish translation.\nPress ENTER to quit.")

This prompts the user for an English word

word = input("Enter an English word: ")

This loop is repeated until the user presses the ENTER key

while(True):

If user presses the ENTER key

if not word:

The loop is exited

 break

If otherwise, this checks if the word exists in the dictionary

if word.lower() in myDict:

If yes, this prints the Spanish translation

 print("The Spanish word is ",myDict[word.lower()])

If otherwise,

else:

Print word does not exist

 print("I don’t have that word in my list.")

Prompt the user for another word

word = input("Enter an English word: ")

5 0
2 years ago
____ is a philosophy and a software and system development methodology that focuses on the development, use, and reuse of small,
LiRa [457]

Answer:

d.) Service-Oriented Architecture

Explanation:

Because its definition matches

4 0
3 years ago
I need help pls, in this code if add row for example :
tankabanditka [31]
I thing is going project experiment everyone make plans and
3 0
3 years ago
01001000 01100101 01101100 01101100 01101111 00100000 01101101 01111001 00100000 01101110 01100001 01101101 01100101 00100000 01
Marianna [84]

You said Hello my name is REE

6 0
2 years ago
Other questions:
  • Identify a major drawback of browsing web pages on mobile devices.
    15·1 answer
  • How can we set the color of a text that acts as a link in a web page​
    10·2 answers
  • 13. You're expecting an important call from Mr. Suarez, a potential customer. While waiting for this call, your supervisor calls
    15·1 answer
  • highlight the possible risks and problems that should be address during the implementation of information system process
    5·1 answer
  • ANYBODY WANNA PLAY FoRnITe
    11·2 answers
  • Write an application that displays the strings in the provided array alphabetically in ascending order.
    9·1 answer
  • How many binary digits does a single hexadecimal digit represent?
    13·1 answer
  • Write an algorithm to sum to values
    11·1 answer
  • How can the two independent clauses below be combined to form a correct complete sentence? Check all that apply.
    5·1 answer
  • What is system software?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!