Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
build
9 changes: 3 additions & 6 deletions experiment/aim.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
A computer program can be thought of as a sequence of instructions which are followed by a computer to solve a problem. However, the sequence in which they are written and the sequence in which they are executed may not be the same. If the execution of every program was sequential, it would run exactly the same way each time. Hence, to write programs of greater complexity, which can take decisions based on user input or values of variables, we need a decision making mechanism which can alter the sequential order of execution of statements. The order of execution of statements in a program is called Control Flow (or flow of control).
A computer program is a sequence of instructions that a computer follows to solve a problem. However, the order in which instructions are written and the order in which they are executed may differ. If every program executed instructions strictly in sequence, it would always run the same way. To create more complex programs that can make decisions based on user input or variable values, we need mechanisms to alter the flow of execution. This is known as control flow.

An example where we need to alter the sequential flow of control is when we want a set of instructions to be executed in one situation, and an entirely different set of instructions in another situation. A real life example of this sort of "decision-making" could be: If the traffic light is green, keep moving; if yellow, then wait; if red, then stop. In the case of programmming, decision-making essentially means deciding from which statement the execution should be resumed. This decision about where the execution should be resumed is made based on the value of a variable or an expression.

The if construct, for example, excecutes a set of instructions only if a condition is true. A switching construct, on the other hand, allows decision-making based on the state of a variable or an expression. Its purpose is to allow the value of a variable or an expression to control the flow of program execution via a multiway branch. Constructs like these can be placed inside another to create more complex flow of control. This enclosing of structures into one another is called nesting. These constructs are known as conditionals because they alter the flow of control based on a condition.

Apart from this, there is another class of constructs called loops, which can be used to repeat a set of instructions.This repetition can be done a fixed number of times or until some specific condition is met. Just like the conditionals, the loops can also be nested. Loops and conditionals can also be nested inside each other. In this lab, we shall see the working of conditional constructs.
For example, consider a real-life scenario: "If the traffic light is green, keep moving; if yellow, then wait; if red, then stop." In programming, decision-making means choosing which statement to execute next based on the value of a variable or an expression. Constructs like 'if' and 'switch' allow programs to make decisions and change the flow of execution. These are called conditional statements, and they can be nested to create more complex control flows.

In this experiment, we focus on basic control flow mechanisms in programming, especially conditional constructs such as if, if-else, and switch-case. The aim is to understand how these constructs enable decision-making in programs and how they can be used to control the order of execution of statements.
239 changes: 153 additions & 86 deletions experiment/posttest.json
Original file line number Diff line number Diff line change
@@ -1,86 +1,153 @@
[
{"question":"1. What will be the output for this code: <br/> <img src='images/code11.png'",
"answers":{
"a":"A",
"b":"B",
"c":"AC",
"d":"BC"
},
"correctAnswer":"c"},

{"question":"2. Float expressions are allowed in switch cases",
"answers":{
"a":"Yes",
"b":"No"
},
"correctAnswer":"b"},

{"question":"3. Switch cases works faster than equivalent if-else ladder",
"answers":{
"a":"True",
"b":"False"
},
"correctAnswer":"a"},

{"question":"4. The case keyword is followed by an integer or a character constant.",
"answers":{
"a":"True",
"b":"False"
},
"correctAnswer":"a"},

{"question":"5. What will be the output for this code: <br/> <img src='images/code15.png'>",
"answers":{
"a":"I",
"b":"Love",
"c":"Programming",
"d":"I Love Programming"
},
"correctAnswer":"d"},

{"question":"6. What will be the output for this code: <br/> <img src='images/code16.png'>",
"answers":{
"a":"I",
"b":"Love",
"c":"Programming",
"d":"I Love Programming"
},
"correctAnswer":"c"},

{"question":"7. What will be the output for this code: <br/> <img src='images/code17.png'>",
"answers":{
"a":"Hi",
"b":"Bye",
"c":"Invalid Syntax",
"d":"HiBye"
},
"correctAnswer":"b"},

{"question":"8. What will be the output for this code: <br/> <img src='images/code18.png'>",
"answers":{
"a":"Hi",
"b":"Bye",
"c":"Invalid Syntax",
"d":"HiBye"
},
"correctAnswer":"b"},

{"question":"9. What will be the output for this code: <br/> <img src='images/code17.png'>",
"answers":{
"a":"Hi",
"b":"Bye",
"c":"HiHello",
"d":"HiBye"
},
"correctAnswer":"b"},

{"question":"10. What will be the output for this code: <br/> <img src='images/code20.png'>",
"answers":{
"a":"Hello",
"b":"World",
"c":"Hello World",
"d":"Invalid Syntax"
},
"correctAnswer":"b"}

]
{
"version": 2.0,
"questions": [
{
"question": "1. What will be the output for this code: <br/> <img src='images/code11.png'>",
"answers": {
"a": "A",
"b": "B",
"c": "AC",
"d": "BC"
},
"correctAnswer": "c",
"explanations": {
"a": "Incorrect, explanation: Only 'A' is printed, not the full output.",
"b": "Incorrect, explanation: Only 'B' is printed, not the full output.",
"c": "Correct. explanation: The code prints 'A' and 'C' as per the logic.",
"d": "Incorrect, explanation: 'B' and 'C' are not printed together."
}
},
{
"question": "2. Are float expressions allowed in switch cases?",
"answers": {
"a": "Yes",
"b": "No"
},
"correctAnswer": "b",
"explanations": {
"a": "Incorrect, explanation: Switch cases only accept integer or character constants.",
"b": "Correct. explanation: Float expressions are not allowed in switch cases."
}
},
{
"question": "3. Switch cases work faster than equivalent if-else ladders.",
"answers": {
"a": "True",
"b": "False"
},
"correctAnswer": "a",
"explanations": {
"a": "Correct. explanation: Switch cases are generally faster due to jump tables.",
"b": "Incorrect, explanation: Switch cases are optimized for speed compared to if-else ladders."
}
},
{
"question": "4. The case keyword is followed by an integer or a character constant.",
"answers": {
"a": "True",
"b": "False"
},
"correctAnswer": "a",
"explanations": {
"a": "Correct. explanation: Case labels must be integer or character constants.",
"b": "Incorrect, explanation: Case labels cannot be float or string values."
}
},
{
"question": "5. What will be the output for this code: <br/> <img src='images/code15.png'>",
"answers": {
"a": "I",
"b": "Love",
"c": "Programming",
"d": "I Love Programming"
},
"correctAnswer": "d",
"explanations": {
"a": "Incorrect, explanation: Only 'I' is printed, not the full output.",
"b": "Incorrect, explanation: Only 'Love' is printed, not the full output.",
"c": "Incorrect, explanation: Only 'Programming' is printed, not the full output.",
"d": "Correct. explanation: The code prints 'I Love Programming' as per the logic."
}
},
{
"question": "6. What will be the output for this code: <br/> <img src='images/code16.png'>",
"answers": {
"a": "I",
"b": "Love",
"c": "Programming",
"d": "I Love Programming"
},
"correctAnswer": "c",
"explanations": {
"a": "Incorrect, explanation: Only 'I' is printed, not the full output.",
"b": "Incorrect, explanation: Only 'Love' is printed, not the full output.",
"c": "Correct. explanation: The code prints 'Programming' as per the logic.",
"d": "Incorrect, explanation: The code does not print all three words together."
}
},
{
"question": "7. What will be the output for this code: <br/> <img src='images/code17.png'>",
"answers": {
"a": "Hi",
"b": "Bye",
"c": "Invalid Syntax",
"d": "HiBye"
},
"correctAnswer": "b",
"explanations": {
"a": "Incorrect, explanation: 'Hi' is not printed in this code.",
"b": "Correct. explanation: The code prints 'Bye' as per the logic.",
"c": "Incorrect, explanation: The code is syntactically correct.",
"d": "Incorrect, explanation: Both 'Hi' and 'Bye' are not printed together."
}
},
{
"question": "8. What will be the output for this code: <br/> <img src='images/code18.png'>",
"answers": {
"a": "Hi",
"b": "Bye",
"c": "Invalid Syntax",
"d": "HiBye"
},
"correctAnswer": "b",
"explanations": {
"a": "Incorrect, explanation: 'Hi' is not printed in this code.",
"b": "Correct. explanation: The code prints 'Bye' as per the logic.",
"c": "Incorrect, explanation: The code is syntactically correct.",
"d": "Incorrect, explanation: Both 'Hi' and 'Bye' are not printed together."
}
},
{
"question": "9. What will be the output for this code: <br/> <img src='images/code17.png'>",
"answers": {
"a": "Hi",
"b": "Bye",
"c": "HiHello",
"d": "HiBye"
},
"correctAnswer": "b",
"explanations": {
"a": "Incorrect, explanation: 'Hi' is not printed in this code.",
"b": "Correct. explanation: The code prints 'Bye' as per the logic.",
"c": "Incorrect, explanation: 'HiHello' is not printed in this code.",
"d": "Incorrect, explanation: Both 'Hi' and 'Bye' are not printed together."
}
},
{
"question": "10. What will be the output for this code: <br/> <img src='images/code20.png'>",
"answers": {
"a": "Hello",
"b": "World",
"c": "Hello World",
"d": "Invalid Syntax"
},
"correctAnswer": "b",
"explanations": {
"a": "Incorrect, explanation: 'Hello' is not printed in this code.",
"b": "Correct. explanation: The code prints 'World' as per the logic.",
"c": "Incorrect, explanation: Both 'Hello' and 'World' are not printed together.",
"d": "Incorrect, explanation: The code is syntactically correct."
}
}
]
}
Loading
Loading