Question

Semester 2 & Trimester 3B, 2015 COMP1004 Engineering Programming Q2(b) Explain when you would use a chained if instead of a switch-case Show the logic of them by using pseudo code or a flowchart. 6 marks] Tove

Please answer the above queston (in terms of C programming) and explain answer

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Chained If is used when the condition for the decision is a boolean expression. Switch - case is used on a single integer, enumerated value, or string object. But if we need to decide on the basis of some boolean expression and check on various condition, Chained If is always better.

for eg.

if we need to print the largest of the 3 numbers, we need to use if as follows: -

if(a > b && a > c) {

return a;

} else if(c > b && c > a) {

return c;

} else if(b > a && b > c) {

return b;

}

We cannot use switch in this case

Add a comment
Know the answer?
Add Answer to:
Please answer the above queston (in terms of C programming) and explain answer Semester 2 &...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please answer the above queston (in terms of C programming) and explain answer Semester 2 &...

    Please answer the above queston (in terms of C programming) and explain answer Semester 2 & Trimester 3B, 2015 COMP1004 Engineering Programming Question 3 - Repetition (20 marks) Q3(a) What will be printed when the following code is executed? (5 marks] #include <stdio.h> int main() int i, j; for(i=1;i<17;i=i+2) { printf("%d==", i); for(j=i; j>0;j--) printf("#"); printf("\n"); return 0; == # 3 = = # # # 5 == ### ## 7 #### #

  • Number 20 - C please. The answer is 19.04 but can u explain how Queston 20...

    Number 20 - C please. The answer is 19.04 but can u explain how Queston 20 of 30 625 points Tim Hortons paid its line workers $10 per hour last year when the Consqgmer Instructions: Round your answers to two decimal places. Price Index iwas 100. Suppose over the past year, deflation occurred and the aggregate price level fell to 84 a. Tim Hortons must pay its workers s b. Tim Hortons must pay its workers c.If Tim Hortons keeps...

  • Java Programming. please give me answer and explain in details. Question 1 (c) (4 marks] For...

    Java Programming. please give me answer and explain in details. Question 1 (c) (4 marks] For each of the methods equals and hashCode in the following class, explain whether or not they are implemented correctly (with respect to their specification in the object class and any additional specification in this class). If they are not implemented correctly. show how they may be rewritten to address the problems that you have identified. *An immutable representation of a term in a polynomial....

  • Please answer Question 2! 2. For each of the following stages of the titration described above...

    Please answer Question 2! 2. For each of the following stages of the titration described above (in question 1), calculate and report the pH, (NH3] and [NH4+). For each stage, write the ice table and equilibrium reaction that governs the pH of the solution. Show all relevant calculations and ice tables, and explain any approximations used. (Note: To assist with the grading, at the end of the full solution, please include a summary stating: pH = XXX, (NH3] = XXX,...

  • Please answer c,d,f. also please explain the answers for me to understand. For each of the...

    Please answer c,d,f. also please explain the answers for me to understand. For each of the languages below, draw the state diagram for a nondeterministic finite automaton (NFA) to accept the language. In order to get full marks, your NFA must have the number of states specified, and it must take advantage of nondeterminism. [There must be at least one case where the machine has a choice between two or more next states on some input symbol, or a case...

  • Explain your answer in terms of LeChatelier's principle. c) The above solution is divided equaly into three test tu...

    Explain your answer in terms of LeChatelier's principle. c) The above solution is divided equaly into three test tubes A, B. and Test tube "A is placed in an ice bath kept at 0 "C, test tube "B is kept at room temperature (25 °C) and test tube "C is placed in a boiling hot water bath maintained at 100 "C. The folowing are the colors of the solutions observed in each case. Solution "A" remained pink, solution "B" became...

  • Help with programming in C++ Phase 1 is complete, please help with phase 2. Thank you....

    Help with programming in C++ Phase 1 is complete, please help with phase 2. Thank you. Phase 1 You must design 3 algorithms, and provide both a flow chart and pseudo code for the algorithms.    Algorithm descriptions: Given an integer parameter named current_number and two constant global variables: const int MIN_NUMBER = 1; const int MAX_NUMBER = 8; Create an algorithm named forward, that will advance ONE value through a sequence of numbers 1, 2, 3 ... MAX_NUMBER. In...

  • Hi can you please help me with the question?..thank you.. QUESTION 2 The pipeline in the...

    Hi can you please help me with the question?..thank you.. QUESTION 2 The pipeline in the ARMI1 CPU is shown in Figure Q2(a). There are three possible (a) paths through the pipeline. The path of the execution depends on what type of instruction is executing (b) Instruction Fetoh Write Decode Execute Back Address DCI Dcz WBIS FE1 FE2 Decode Issue Shif ALU Saturate WBes MAC2 МАСI МАСУ Figure Q2(a) (i) Identify the number of stages for the ARMI1 CPU pipelines....

  • hi..can you please help me with this question?..thank you.. QUESTION 2 The pipeline in the ARMI1...

    hi..can you please help me with this question?..thank you.. QUESTION 2 The pipeline in the ARMI1 CPU is shown in Figure Q2(a). There are three possible (a) paths through the pipeline. The path of the execution depends on what type of instruction is executing (b) Instruction Fetoh Write Decode Execute Back Address DCI Dcz WBIS FE1 FE2 Decode Issue Shif ALU Saturate WBes MAC2 МАСI МАСУ Figure Q2(a) (i) Identify the number of stages for the ARMI1 CPU pipelines. [1...

  • Answer Question 10 ONLY please. 7) These equations can be solved in terms of integrals over the retanded source distributions: Acan-sitiAi.-4.. van"in.leidiT-ae.. Et E Explain the physical princip...

    Answer Question 10 ONLY please. 7) These equations can be solved in terms of integrals over the retanded source distributions: Acan-sitiAi.-4.. van"in.leidiT-ae.. Et E Explain the physical principles underlying these expressions. 3 marks Deternine the vector potential due to a short wire running from (0,0,-L/2) to (0, 0, +1/2) carrying a current I -lo cos(t)(consider only points at distancer >>L from the origin). 3 mark Show that the field strength F is invariant under a gauge transformation 2 marks 7)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT