Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

DOKUZ EYLUL UNIVERSITY

Faculty of Engineering
Electrical and Electronics Engineering

Dokuz Eyl
ul Universitesi,
M
uhendislik Fak
ultesi

Elektrik Elektronik M
uhendisli
gi, 35160, Kaynaklar/Buca/IZM
IR

EED1005 Intoduction to Programming Laboratory 3


Objective(s)
To be familiar with if, else if and switch control statements in C language.
Equipments(s)
Personal computers with devcpp installed on will be provided.
Preliminary Work
Task 1 Explain the differences and similarities between if, else if and switch control statements.
Task 2 Write a C program that takes two integers from the user and also asks the user to
choose an operation from a given menu including summation, subtraction, multiplication and
division operators. The program prints the result on the screen corresponding to the chosen
operation. If the user types an operator other than the ones in the given menu, the program
prints an error message saying that an invalid operator has been chosen.
Flowchart of the program is required to be drawn.
Sample outputs of the program is given in Figure 1.

Figure 1: Sample outputs of the program in Preliminary Work Task 2


1

Laboratory Work
Task 1: A function is increasing at a point if the value of the first derivative of the function at
that point is greater than 0 or decreasing if the value of the first derivative of the function at that
point is less than 0. Write a program that determines whether a chosen function is increasing
or decreasing at a given point.The program displays a menu containing four functions and asks
the user to choose a function from the given menu and also a point at which the derivative will
be calculated. The program calculates the derivative at point a using the following formula,
df
f (a + h) f (a)
|x=a =
dx
h
Since in the definition of the derivative h approaches to 0, in the calculation h is taken as
0.000001, an infinitesimal value.
Flowchart of the program is required to be drawn.
Sample outputs of the program is given in Figure 2.

Figure 2: Sample outputs of the program in Laboratory Work Task 1


Task 2: Write a C program that determines whether a student can or cannot pass a course.
The program asks the user to enter his / her midterm1, midterm2, final, lab grades and also
the number of lab hours that he / she was absent and then calculates the course total using the
following grading policy,
course total = %15 midterm1 + %15 midterm2 + %50 f inal + %20 lab

The student fails if,


course total < 40
f inal < 20
absent > 2
The student passes with letter grade,
A, if course total 80
B, if 60 course total < 80
C, if 40 course total < 60
The program has to display the course total grade of the student and the reason(s) why a
student fails or display the corresponding letter grade if a student passes.
Flowchart of the program is required to be drawn.
Sample outputs of the program is given in Figure 3.

Figure 3: Sample outputs of the program in Laboratory Work Task 2

You might also like