Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

Decision Structures
Question Description

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:

  • The processing speed must be high.
  • The logic of the program must be simple.

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]

Views: 5774

Replies to This Discussion

m also confused about that what type of transaction would be compared 

I asked Teacher about it and here is her reply:

Dear Student,
First of all, in GDB coding is not required. You have to select a decision structure according to the given scenario and have to provide the reasons. Then login the VULMS, click on GDB icon and post your comments.
Transaction examples are:
a user deposit cash in his/her account.
A user withdraws some cash from his/her account.
A user checks the balance of his/her account etc.

Instructor CS201
Department of Computer Sciences
VU, Pakistan

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

dear koi to solution file bhej do aj last date he..

if else or switch

confirm batao

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.


© 2021   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service