Index
Sr.
Contents Page No.
No.
Annexure I– Micro Project Proposal 1-2
1.Aims/Benefits of the Micro-Project 1
2. Course Outcome Addressed 1
1 3.Proposed Methodology 1
4. Action Plan 2
5. Resources Required 2
6. Name of Team Members with Roll No.’s 2
Annexure II – Micro Project Report 3-8
1.Rationale 3
2.Aims/Benefits of the Micro-Project 3
3.Course Outcome Achieved 3
4. Literature Review 3
2 5.Actual Methodology Followed 4
5.1 Flow chart 5
5.2 Source code 4-6
6.Actual Resources Used 7
7.Outputs of Micro-Projects 8
8. Skill developed / Learning out of this Micro-Project 8
9. Applications of this Micro-Project 8
Annexure I
i
Micro Project Proposal
SWITCH CASE STATEMENT
1. Aims/Benefits of the Micro-Project:
To study Switch case Statement.
2. Course Outcome Addressed:
a. Develop flowchart and algorithm to solve problems logically.
b. Write simple ‘C’ programs using arithmetic expressions.
c. Develop ‘C’ Programs using control structure.
d. Develop ‘C’ programs using arrays and structures.
e. Develop/Use functions in C programs for modular programming approach.
f. Develop ‘C’ programs using pointers.
3. Proposed Methodology:
Switch Statement in C
Switch case statements are a substitute for long if statements that compare a variable
to several integral values
The switch statement is a multi-way branch statement. It provides an easy way
to dispatch execution to different parts of code based on the value of the
expression.
Switch is a control statement that allows a value to change control of
execution.
4. Action Plan :(Sequence and time required for major activities)
Sr. Planned Planned Name of Responsible
Details of Activity
No. Start date Finish date Team Members
1
2
3
4
5
6
7
1
8
5. Resources Required:
Sr.
No Name of resource / material Specification Quantity Remarks
.
1 Computer WINDOWS 7,2GB RAM, 1
160GB HDD
2 Operating System WINDOWS 7 1
3 Compiler Turbo C/GCC 1
4 Browser Chrome 1
Names of Team Members with Roll No.’s:
Sr.
No Enrollment No. Name of Team Member Roll No.
.
1
2
4
5
Name and Signature of the Teacher
2
Annexure – II
Micro-Project Report
SWITCH CASE STATEMENT
1. Rationale:
In computer programming languages, a switch statement is a type of selection
control mechanism used to allow the value of a variable or expression to
change the control flow of program execution via search and map.
Switch statements function somewhat similarly to the if statement used
in programming languages like C/C++, C#, Visual Basic .NET, Java and
exists in most high-level imperative programming languages such as Pascal,
Ada, C/C++, C#, Visual Basic .NET, Java, and in many other types of
language, using such keywords as switch, case, select or inspect.
Switch statements come in two main variants: a structured switch, as in
Pascal, which takes exactly one branch, and an unstructured switch, as in C,
which functions as a type of goto. The main reasons for using a switch include
improving clarity, by reducing otherwise repetitive coding, and (if the
heuristics permit) also offering the potential for faster execution through easier
compiler optimization in many cases.
2. Aims/Benefits of the Micro-Project:
Easier to read than equivalent if-else statement
More efficient than equivalent if-else statement (destination can be
computed by looking up in table).
Easier to debug.
Easier to maintain.
Fixed depth: a sequence of "if else if" statements yields deep nesting, making
compilation more difficult (especially in automatically generated code).
Faster execution potential.
3
Additionally, an optimized implementation may execute much faster than the if-
else statements, because it is often implemented by using an indexed branch table.
3. Course Outcomes Achieved:
a. Develop flowchart and algorithm to solve problems logically.
b. Write simple ‘C’ programs using arithmetic expressions.
c. Develop ‘C’ Programs using control structure.
d. Develop ‘C’ programs using arrays and structures.
e. Develop/Use functions in C programs for modular programming approach.
f. Develop ‘C’ programs using pointers.
4. Literature Review:
Syntax:
switch (n)
case 1: // code to be executed if n = 1;
break;
case 2: // code to be executed if n = 2;
break;
default: // code to be executed if n doesn't match any cases
Important Points about Switch Case Statements:
4
1. The expression provided in the switch should result in a constant
value otherwise it would not be valid.
Valid expressions for switch:
2. // Constant expressions allowed
3. switch(1+2+23)
4. switch(1*2+3%4)
5.
6. // Variable expression are allowed provided
7. // they are assigned with fixed values
8. switch(a*b+c*d)
switch(a+b+c)
9. Duplicate case values are not allowed.
10. The default statement is optional. Even if the switch case statement do not
have a default statement,
it would run without any problem.
11. The break statement is used inside the switch to terminate a statement
sequence. When a break statement is reached, the switch terminates, and the
flow of control jumps to the next line following the switch statement.
12. The break statement is optional. If omitted, execution will continue on into the
next case. The flow of control will fall through to subsequent cases until a break
is reached.
13. Nesting of switch statements are allowed, which means you can have switch
statements inside another switch. However nested switch statements should be
avoided as it makes program more complex and less readable.
5 Actual Methodology Followed:
5
5.1 Flow Chart:
5.2 Source Code:
// Following is a simple C program to demonstrate syntax of switch.
#include <stdio.h>
int main()
{
int x = 2;
switch (x)
{
case 1: printf("Choice is 1");
break;
case 2: printf("Choice is 2");
break;
case 3: printf("Choice is 3");
break;
default: printf("Choice other than 1, 2 and 3");
break;
}
return 0;
}
6
6. Actual Resources Used:
Sr. Name of resource /
Specification Quantity Remarks
No. material
1 Computer WINDOWS 7,2GB RAM, 1
160GB HDD
2 Operating System WINDOWS 7 1
3 Compiler Turbo C/GCC 1
4 Browser Chrome 1
7. Outputs of Micro-Projects:
Output:
Choice is 2
8. Skill developed / Learning out of this Micro-Project:
There are so many thing that we learn from this project of
1. We learn that how to make the project in c programming.
2. How to do the testing of program in turbo c.
3. How to collect the information and how to make the presentation that we learn
from this project.
4. We develop our logic implementation for programing and coding.
5. This all thing we learn from this project.
9. Applications of this Micro-Project:
There is one potential problem with the if-else statement which is the complexity of
the program increases whenever the number of alternative path increases. If you use
multiple if-else constructs in the program, a program might become difficult to read
and comprehend. Sometimes it may even confuse the developer who himself wrote
the program. The solution to this problem is the switch statement.
*********