0% found this document useful (0 votes)
87 views11 pages

If Switch If If Switch

The document contains details of a programming fundamentals practical work session, including: 1) Assessment criteria for evaluating students' practical programming skills and their reports. 2) Objectives and theory about selection statements in C language such as if, if-else, and switch. 3) Practical exercises for students to complete including fixing errors, completing, and writing programs using selection statements to calculate circuit measurements.

Uploaded by

Iman Athirah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views11 pages

If Switch If If Switch

The document contains details of a programming fundamentals practical work session, including: 1) Assessment criteria for evaluating students' practical programming skills and their reports. 2) Objectives and theory about selection statements in C language such as if, if-else, and switch. 3) Practical exercises for students to complete including fixing errors, completing, and writing programs using selection statements to calculate circuit measurements.

Uploaded by

Iman Athirah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

ELECTRICAL ENGINEERING DEPARTMENT

ACADEMIC SESSION: _____________

DEC20012: PROGRAMMING FUNDAMENTALS

build programs written in C language for assigned mini project during


CLO2
practical work session ( P4 , PLO 5 )
PRACTICAL WORK 2 : Selection Statements
PRACTICAL WORK DATE :
LECTURER’S NAME:

NAME : TOTAL
STUDENT ID : MARKS
1. Fixes
2. Complete
3. Manipulates
Practical Skill 4. Builds
Assessment 5. Display
[CLO2] 6. Lab Participation
7. Efficiency
Total Practical Skill Assessment
A. Total Practical Skill Assessment (70%) = /35 *70
1. Theory
Report 2. Discussion
Assessment 3. Conclusion
Total Report Assessment
B. Total Report Assessment (30%) = /15*30
Total A+B (100%)
DATE SUBMIT : DATE RETURN :
1 LEARNING OUTCOMES (LO):
1. Understand selection statements.
2. Apply selection statements.
2 OBJECTIVE
1. To fixes, Complete and Manipulates the selection statement.
2. To builds flowchart of selection statement.
3. To display the output of selection statement.
3 THEORY
 The C statements that are used for altering the normal flow of a program are called control statements.
 Various control statements, such as selection and looping statements, are available in C.
 Selection statements are used to execute a set of instructions, just once, when the specified condition is
satisfied.
 The types of selection statements available in C are if and switch.
 The if statement is used for checking conditions and transferring the control to the body of the if statement
based on the condition.
 The selection statement, which allows you to choose from a number of choices, is the switch statement.
4 EQUIPMENT / TOOLS
Computer, C programming language ( Dev-cpp, codeblock, dll)

PART A : Independent Learning (NF2F)


(Student must do this task at home or before entering a computer lab)
Define control statements.
Answer:

List the types of control statements.


Answer:

Define selection statement


Answer:

list selection statements


Answer:

Define IF statement
Answer:

Define IF-ELSE statement


Answer:
Define SWITCH statement
Answer:

PART B: Laboratory PW5 (Dependent Learning (F2F)


(To be done in a computer lab)
Write the syntax for Simple IF Statement Draw flowchart for IF Statement
Answer: Answer:

Write the syntax for IF-ELSE Statement Draw flowchart for IF-ELSE Statement
Answer: Answer:

Write the syntax for SWITCH Statement Draw flowchart for SWITCH Statement
Answer: Answer:
PART B: PRACTICAL WORK AT LABORATORY
Practical Assignments 1 (Fixes Program)
To calculate series and parallel circuits.

Series parallel
Find an errors and correct the programme to illustrate the working of IF-ELSE statements to calculate the
total resistance for series and parallel circuit. Get the output after fixes all errors
#include <stdio> Correction:
main()
{
int selection;
float series, parallel;
float R1=100,R2=300, R3=500;
printf("1: Series Circuit\n");
printf("2. Parallel Circuit \n");
printf("Please Select your choice \n ");
scanf("%d", $selection);
IF (selection==1)
{
series = R1+R2+R3;
printf(" Total resistance = %.2d Ohm\n",series);
}
else if (selection==2)
{
PARALLEL = 1/(1/R1 +1/R2+1/R3) ;
printf(" Total resistance = %.6f Ohm\n",parallel);
}
else
{
printf(" wrong choice \n ");
}
return 0;
}
Output:
If selection =2
Practical Assignments 2 (Complete Program)

RT = R1 + R2 + R3
Series parallel
Complete all statements in the programme below to illustrate the working of SWITCH statements to
calculate the total resistance for series and parallel circuit. Get the output after fixes all errors
#include <stdio.h>
main()
{
Int____________________________________;
float series, parallel,R1,R2,R3;
printf("******************************************");
printf("\nEnter the value of R1= ");
scanf( _______________________________);
printf("\nEnter the value of R2= ");
scanf("%f",&R2);
printf("\nEnter the value of R2= ");
scanf ( _______________________________);
printf("******************************************");
printf("\n1: Series Circuit");
printf("\n2. Parallel Circuit ");
printf("\nPlease Select your choice ");
printf("******************************************");
scanf("%d",&selection);
switch(selection)
{
case 1:
series = R1+R2+R3;
printf(" _______________________________________”, ______________);
break;
case 2:
parallel = 1/(1/R1 +1/R2+1/R3) ;
printf(" _______________________________________”, ______________);
break;
default:
printf(" wrong choice \n ");
}
return 0;
}
Output:
If choice =2 If choice =1

Practical Exercise 1: Manipulates Program 1


By referring to the Practical Assignments 2, draw flowchart and write a C program using SWITCH
statements to calculate the total capacitance of three capacitors of series and parallel connected. Get the
output of the programme. ( the formula of series and parallel capacitors are given below

Series parallel
Ask input from user the value of C1,C2 and C3
Flowchart :
Program:

Output:
If choice =1 If choice =2
Practical Exercise 2: Manipulates Program 2:
By referring to the Practical Assignments 2, draw flowchart and write a C program using IF-ELSE
statement to make a choice for calculate :
Choice 1: Total resistance of the circuit,

Choice 2: Current, I

Choice 3: Voltage drop across resistor 8Ω,

Choice 4: Current through resistor 4Ω,

referring to the circuit below

Ask input from user R1,R2,R3 and E


Flowchart :
Program:

Output:
Case 1

Case 3
Discussion for practical work 2
Knowledge: IF, IF-ELSE, and SWITCH statements work
Understanding: Concepts and Relate theory to practice

Conclusion for practical work 2


1. The conclusion thoroughly and accurately explains the results of the experiment and why they
occurred.
2. The explanations of all variables are clear and support the conclusion.
3.
4. Findings are based on the experimental process.
5. Analyze or explain the connections.

You might also like