Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21

DEPARTMENT OF ELECTRICAL ENGINEERING

DEC20012 – PROGRAMMING FUNDAMENTALS (PRACTICAL REPORT)

PRACTICAL WORK 1 2 3 4 5 6

Function
TITLE
SUBMISSION DATE 12/5/2021
GROUP MEMBERS REGISTRATION NUMBER
1.SARAHMEI BINTI ABDULLAH 17DTK20F2005
2.
3.
4.
PROGRAMME
Mr. Mohd Zeid B. Abu
LECTURER/INSTRUCTOR Bakar

Result/Practical Work / 80%


Discussion/Question / 20%
TOTAL / 100%

LECTURER/INSTRUCTOR COMMENT
S RECEIVED DATE
Lab 5.1
Lab5.2
Lab5.3
Lab5.4 TASK A
Rewrite the following program by implementing a user-defined function named myIO().
The program shall make the function call from the main function. The reading and
printing task must be completed in the myIO() function.
TASK B

Write a program that calls a user-defined function named printMessage(). Ask the
users for their annual income in the main function. Then pass the income value to
the printMessage function. In the printMessage() print a congratulatory message if
the user makes more than RM 100,000 a year or an encouragement message if the
user makes less.
TASK C

Write a program with multiple programmer-defined functions that displays the face of a
smiling person as shown in Fig. 1. The structure chart in Fig. 2 shows how the main task
can be broken apart. Different functions must be defined to perform different tasks.
TASK D

Improve the program written for Question 1 so that along with the smiling face, the
following faces may be displayed on request. Since the shape of the hair, the nose, and
the chin is common to all faces, use the same functions as written in the earlier program.
Sample output: H – Happy face S – Sad face A – Angry face I wish to display>
TASK E
TASK E
QUESTION
1. What is function?
a) Function is a block of statements that perform some specific task
b) Function is the fundamental modular unit. A function is usually designed to perform a
specific task
c) Function is a block of code that performs a specific task. It has a name and is reusable.
d) d) All of the above

2. Any C program
(a) Needs input data
(b) Need not contain any function
(c) Must contain at least one function
(d) None of the above

3. The keyword used to transfer control from a function back to the calling function is a) switch
b) goto
c) goback
d) return

4. A function cannot be defined inside another function


a) True
b) False

5. In order to exchange the values of two variables x and y


a) Call swap(x,y)
b) Call swap(&x,&y)
c) Swap(x,y) cannot be used as it does not return any value
d) Swap(x,y) cannot be used as the parameters are passed by value

6. The default parameter passing mechanism is


a) Call by value
b) Call by reference
c) Call by value result
d) None of the above

7. Functions can be called either by value or reference.


a) True
b) False

8. Every function must return a value


a) Yes
b) No

9. If return type for a function is not specified, it defaults to int


a) True
b) False
10. Determine the output.

a) 10
b) 9
c) 11
d) None of these

You might also like