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
A Use-Case diagram is a staticdiagram?
Arte-miy333 [17]

Answer:

No, Use-Case diagram is a not a static diagram.

Explanation:

Only static diagram is not adequate to model a system that is more dynamic than static behavior. In Unified Modeling Language, five diagrams are accessible to model the dynamic nature and use case diagram is one of them.

Use case diagrams is made up of actors, use cases and their interactions. The diagram is used for modeling an application's system / subsystem. A single use case diagram depicts a system's specific features.

4 0
3 years ago
PLEASE HELP WILLL GIVE BRAINLIESTTTTT!
maria [59]

so a description of a mask tool that is used like painters tape to section off a spot so you do not chage that area

hope this helps

-scav

8 0
3 years ago
Read 2 more answers
Write a method that takes three numerical String values and sums their values.
Sphinxa [80]

Answer:

<u>Algorithm</u>:

  1. Take a int variable c=0.
  2. Run the loop from 0 to String length.
  3. Get the each index value using charAt() method which will return the char value.
  4. Convert that char into int by typecasting or any other way.
  5. Now check that ASCII fall into the range of 48-57 for 0-9 int number.
  6. If it matches then first convert that number into integer using Integer.parseInt().
  7. Then add with the c and store to the same variable i.e c.
  8. Repeat from 3-7 till the end of the loop.
  9. At the end of loop , Print c outside the loop.

Explanation:

// Java program to calculate sum of all numbers present  

// in a string containing alphanumeric characters  

class GFG  

{  

   // Function to calculate sum of all numbers present  

   // in a string containing alphanumeric characters  

   static int findSum(String str)  

   {  

       // A temporary string  

       String temp = "";  

       // holds sum of all numbers present in the string  

       int sum = 0;  

       // read each character in input string  

       for(int i = 0; i < str.length(); i++)  

       {  

           char ch = str.charAt(i);  

           // if current character is a digit  

           if (Character.isDigit(ch))  

               temp += ch;  

           // if current character is an alphabet  

           else

           {  

               // increment sum by number found earlier  

               // (if any)  

               sum += Integer.parseInt(temp);  

               // reset temporary string to empty  

               temp = "0";  

           }  

       }  

       // atoi(temp.c_str()) takes care of trailing  

       // numbers  

       return sum + Integer.parseInt(temp);  

   }    

   // Driver code  

   public static void main (String[] args)  

   {      

       // input alphanumeric string  

       String str = "1abc5yz7";  

       System.out.println(findSum(str));  

   }  

}  

4 0
3 years ago
Read 2 more answers
PLS HELP WITH MY PYTHON HW ILL GIVE YOU BRAINLIEST
Nezavi [6.7K]

Answer:

class Cat:

   isHungry = None

play = Cat().isHungry = True

eat = Cat().isHungry = False

if play:

   print("I am hungry, I cannot play")

else:

   play = Cat().isHungry = False

if eat:

   print("I am full, I cannot eat")

else:

   eat = Cat().isHungry = True

Explanation:

Just simple if and else statements.

4 0
3 years ago
What are some other possible causes of an overheating laptop
ella [17]
Too much use, air vents are being covered, dust/dirt/other particles clogging the fan making it struggle too cool the laptop down, the internal battery may be low and struggling to function, etc.


I hope this helps you!
8 0
3 years ago
Other questions:
  • Which Internet appliance can take action to potentially stop a network attack from taking place?
    6·1 answer
  • Are MP3 files are quick to transfer.
    11·1 answer
  • How to find something in the cloud?
    8·1 answer
  • Kash has created a document that needs to be protected. only certain users should be able to open the document. what option shou
    5·1 answer
  • 25 points!!!!!!!!!!!!!!!!!!!!!
    9·2 answers
  • A corporation needs an operating system that allows the various teams in its office to network and collaborate on projects. Whic
    13·2 answers
  • You want to substitute one word with another throughout your document. What tool(s) should you use?
    9·1 answer
  • A network administrator is attempting to troubleshoot an issue regarding certificates on a secure website. During the troublesho
    8·1 answer
  • 4.9 Code Practice: Question 3
    15·2 answers
  • Some people worry that there won’t be enough jobs in the future because computers will be able to do everything better than peop
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!