Question

In: Computer Science

Assume m=5 and n=2 in each case. Answer the questions.. What are the output of the...

Assume m=5 and n=2 in each case. Answer the questions..

What are the output of the codes:

1) m*=n++; cout<<(--m)++<<","<<--n<<'\n';

2) Values of m and n after execution of codes: m*=n++;

3) What values of m, n will be after the statement: m+=--n; ?

4) What values of m and n will be after the statement: m*=n; ?

5) What values of m and n will be after the statement: m /=++n; ?

Solutions

Expert Solution

The output of the following programs are as follows:

1. 9,2

It is beacause initially the value of m = 5 and then m = m*n++

                                                                         -> m = 5*2++

                                                                                  = 10

        This is use then increment operator as ++ comes after the operand. Now, we execute the statement --m which means that decrement and then use. So, the current value of m is 10 which will be decremented to 9 due to the operator --m.

Regarding the second output after 9 that is 2. It comes because --n is in the pattern "--n", Now in the first statement that is

m*=n++, the value of n is 2 because it is post increment use and increment. Now, after this --n comes. As a result, the value of n will be decremented and then it will be suddenly decremented again due to pre-increment operator.

In other words, m*=n++;

                      The value of m is 10 and n is 2

                      cout<<(--m)++;   The value of m is 9 (pre increment ie, increment comes first).

                      Also, cout<<--n<<'\n';   The value of n is 2 (because now n is incremented due to n++ in the statement [ m*=n++] to 3 and again decremented to 2 [due to --n] in the statement.

2. values of m and n after execution of codes m*=n++ is

   m =   5*2   =   10

    because initial value of m is 5 and n will not increment and remain as 2 in this step .

The value of n is 2 itself.

3. The value of m and n after the statement m+=--n; is as follows:

    Let us say the current (initial value of m and n is 5 and 2 respectively)

     m = m+--n;

          = 5+(--2)

= 5 + 1

= 6 ,

The value of n is n=n-1=2-1=1

m=6 and n=1

because the value of n will be decremented ( decrement and use pre increment strategy).

4. The value of m and n after the statement m*=n; is as follows:

   Let us say the initial values of m and n are 5 and 2 respectively.

   m = m*n;

        = 5*2

       =   10

   n = 2

m = 10 and n =2

5. The values of m and n after statement m /=++n is as follows:

   Let us say the initial values of m=5 and n=2. Then,

   m = m/++n

       = 5/ (++2)

       = 5/ (2+1)     /* Pre Increment ie increment and then use */

        = 5/3

        = 1.6 , but

   if m is declared as int then the value of m is 1

if m is declared as float, then the value of m is 1.6

   However, the value of n is 3 ( n=n+1).

In general, questions from 1 to 5 is based on the concepts of post and pre increment/decrement operators.

The concept is this, in case of pre increment/decrement operator, initially the operand will be performed by the operation and the we will use it. As far as post increment/dcrement is concerned, the operand will be used first and then only increment or decrement will be done on the operand. You just understand these concepts.

       

     


Related Solutions

Illustrate each of the following scenarios. In each case, assume that the corresponding output market is...
Illustrate each of the following scenarios. In each case, assume that the corresponding output market is competitive. a. Equilibrium in a perfectly competitive labor market (be sure to draw both a market and a firm graph). b. Equilibrium in a monopsony labor market. c. Equilibrium in a monopoly labor market (for example, a labor market with a union maximizing economic rent).
Assume a normal distribution of the form N(100, 100), answer the following questions: What proportion of...
Assume a normal distribution of the form N(100, 100), answer the following questions: What proportion of the distribution falls within 1 standard deviation of the mean (e.g., within -1 and 1 standard deviation)? What is the probability of a single draw from that distribution has a value greater than 115? What is the range that captures the middle 95% of the population distribution? If I randomly sample 10 observations from this distribution and calculate a mean, what is the probability...
Identify all allowable combinations of quantum numbers for an electron. n=3,n=3, ?=2,?=2, m?=2,m?=2, ms=−12ms=−12 n=5,n=5, ?=4,?=4,...
Identify all allowable combinations of quantum numbers for an electron. n=3,n=3, ?=2,?=2, m?=2,m?=2, ms=−12ms=−12 n=5,n=5, ?=4,?=4, m?=−1,m?=−1, ms=−12ms=−12 n=3,n=3, ?=−2,?=−2, m?=2,m?=2, ms=+12ms=+12 n=6,n=6, ?=6,?=6, m?=1,m?=1, ms=+12ms=+12 n=4,n=4, ?=3,?=3, m?=4,m?=4, ms=+12ms=+12 n=2,n=2, ?=0,?=0, m?=0,m?=0, ms=−1
Q 2) Read the case and answer the questions below.                                  &
Q 2) Read the case and answer the questions below.                                        (Marks: 10)     Case: Toyota Motor Corporation is a Japanese multinational automotive manufacturer headquartered in Toyota, Aichi, Japan. Recently a conflict arises from the management styles of two managers, Ralph and George, who head two different departments in the same organization. Ralph’s problem with George is that the latter is taking staff from his department without his approval. On the other hand, George feels that he is doing the right thing...
Based on the five case studies, answer the questions in your own words for each case...
Based on the five case studies, answer the questions in your own words for each case study, using complete sentences, and providing examples, if applicable. Case Study 1 During an appendectomy, the patient, a 16-year-old male, exhibits decreased oxygen saturation, hypotension, decreased breath sounds, and increased airway pressures during ventilation. What is most likely happening with this patient? What should you do as a surgical tech in the scrubbed role? What will the anesthesia provider most likely do? Case Study...
This is for a research paper for each of the below topics answer the 5 questions  ...
This is for a research paper for each of the below topics answer the 5 questions   For each topic do you anticipate using an experimental or a non-experimental approach in your research? Explain the basis for your choice. for each topic state a research hypothesis, purpose, or question for the research you are planning. for each topic Name the major variables you will be studying. Define each variable for each topic are you  conducting “qualitative” or “quantitative” research? Explain the basis...
This is for a research paper for each of the below topics answer the 5 questions  ...
This is for a research paper for each of the below topics answer the 5 questions   For each topic do you anticipate using an experimental or a non-experimental approach in your research? Explain the basis for your choice. for each topic state a research hypothesis, purpose, or question for the research you are planning. for each topic Name the major variables you will be studying. Define each variable for each topic are you  conducting “qualitative” or “quantitative” research? Explain the basis...
Prove via induction the following properties of Pascal’s Triangle: •P(n,2)=(n(n-1))/2 • P(n+m+1,n) = P(n+m,n)+P(n+m−1,n−1)+P(n+m−2,n−2)+···+P(m,0) for all...
Prove via induction the following properties of Pascal’s Triangle: •P(n,2)=(n(n-1))/2 • P(n+m+1,n) = P(n+m,n)+P(n+m−1,n−1)+P(n+m−2,n−2)+···+P(m,0) for all m ≥ 0
I have a M&A case presentation and I need to know how to answer these questions...
I have a M&A case presentation and I need to know how to answer these questions (I’ve done all the calculations already but really new to the subject and don’t know how to transform the numbers into verbal economic analysis): - What is the value of operational and financial synergies of the merger? Are they meaningful? Do you see risks in attaining them? Highlight the main pros and cons for the whole deal for company A shareholders. - What is...
Use the distribution below to answer the next 5 questions:   X                  f    10          &n
Use the distribution below to answer the next 5 questions:   X                  f    10                     8                                                                        9                    6                                                                        8                    6                                                                        7                    7                                                                        6                    1                                                                      40                    28 1 n=? 40 5 28 237 4 2. What is the relative frequency associated with X=7? Group of answer choices 7 8 .25 .32 1 3. The mean of the distribution is Group of answer choices 8.464 5.6 1.429 47,4 8 4.   The median...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT