We are here with you hands in hands to facilitate your learning & don't appreciate the idea of copying or replicating solutions. Read More>>
Study Groups By Subject code Wise (Click Below on your university link & Join Your Subject Group)
Looking For Something at vustudents.ning.com?Search Here
Suppose you are required to write a C/C++ program for a bank in which all transactions of a day will be compared. Keep in mind a huge volume of transactions per day:
Your code should have following features:
Which decision structure (if-else and switch statement) would you choose to achieve above mentioned features of code, and also mention reasons in favor of your choice.
[Note: Answer must be comprehensive with logical reasoning. Confine your answer within 3 to 5 lines]
Share This With Friends......
m also confused about that what type of transaction would be compared
I asked Teacher about it and here is her reply:
Dont Be Confused Keep Keen Attention on Question :)
This is your gdb solution:
Switch statement is much faster than if-else due to the following reasons:
Switch statement is better because
1) compiler generates a jump table during compilation.
2) instead of checking which case is true, it only moves to that case which has to be executed.
3) It is more readable.
4) It is more manageable regarding above scenario.
Regards (Sir G)
CS201 GDB solution
In my opinion, switch statements id better than If-Else. Switch statements have its best uses then there are more environments. As we know that if statements checks for all the conditions and then when the condition is matched then the following body inside it is executed but this is not the case with switch condition as it directly checks for the compatible conditions and executes the code.
The reason behind the selection of switch statement is;
Working speed of switch statement is much faster than if-else.
The reason is that compiler produces a jump table for a switch in the course of assembling. Thus, during accomplishment, as a substitute of testing which case is contented, it only picks which case has to be accomplished.
It is more understandable and in parallel to if-else testimonials.
Switch statement is more manageable for taking higher level of transactions than if-else
if else or switch
CS201 GDB Solution
Solved GDB CS201
According to features of the c/c++ language, switch statement is much faster than simple if-else statement. We know that switch statement uses the cases for switching. So it is more compact for the compiler, so it generate the jump table. This jump table is fix not change. It is also called multiway branch or branch table. So in my opinion switch is the best choice in this scenario. Because of speed, compactness and cases. Switch statement allow the value of a variable or expression to change the control flow of program execution via a multiway branch.