LABORATORY ACTIVITY 6 Ict
LABORATORY ACTIVITY 6 Ict
LABORATORY ACTIVITY 6 Ict
:
Name: Section:
Date Performed:
Date Submitted:
Instructor:
FUNCTIONS
1. Objective(s):
The activity aims to perform a certain task a small blocks using analytical tools such as algorithm, flowchart
and program to evaluate the output based on the requirement.
3. Discussion:
A function is a block of code that has a name and it has a property that it is reusable i.e. it can be executed
from as many different points in program. Function groups a number of program statements into a unit and
gives it a name. The name of the function is unique and global.
Structure of a Function
Function Prototypes
The prototype of a function provides the basic information about a function which tells the compiler that the
function is used correctly or not. It contains the same information as the function header contains. The
prototype of the function must have a semicolon at the end of the prototype.
prototype of the function
int sum (int x, int y);
NOTE: The only difference between the header and the prototype is the SEMICOLON (;)
Syntax:
#include<iostream>
using namespace std;
void MyPrint()
{
cout << "Printing from a function.\n";
}
int main()
{
MyPrint();
return 0;
}
cout << "Give a integer number:"; user can input two whole (integer)
numbers. These numbers are used as
cin >> input1; input of function Add().
cout << "Give another integer number:";
cin >> input2;
Input1 is stored in output1 and input2 is stored in output2
answer = Add(input1,input2);
cout << input1 << " + " << input2 << " = " << answer;
return 0;
} The number stored in answer is then printed onto the screen
Syntax:
#include<iostream>
using namespace std;
int Add()
{
return A + B;
}
int main()
{
int answer; Local Variables
A = 2;
B = 2;
answer = Add();
cout << A << " + " << B << " = " << answer;
return 0;
}
4. Resources:
DevC++
5. Procedure and Output
EXERCISE No.1
A young boy wants to create a program in block of code that will compute for the quadratic
equation then print the result. The main function composes of the input variables.
The formula is given below:
-B ± √ B ^2 – 4AC
---------------------------------
2A
If the user inputs zero (0), the program will display “Invalid Entry” and return to main menu to input another
valid numbers.
QUESTIONS
1. If the first input is higher than the second input but lower than the third input, what will be the output
results? Write on the space provided the input values and the results.
_____________________________________________________________________
_____________________________________________________________________
2. If the third input is first than the second input but lower than the first input, what will be the output
results? Write on the space provided the input values and the results.
_____________________________________________________________________
_____________________________________________________________________
3. If the second input is higher than the first input but lower than the third input, what will be the output
results? Write on the space provided the input values and the results.
_____________________________________________________________________
_____________________________________________________________________
4. If the first input is higher than the second input and equal to the third input, what will be the output
results? Write on the space provided the input values and the results.
_____________________________________________________________________
_____________________________________________________________________
5. If the first input is lower than the second input and equal to the third input, what will be the output
results? Write on the space provided the input values and the results.
_____________________________________________________________________
_____________________________________________________________________
EXERCISE No. 2
Juan wanted to create a program that would use block of code (function) to group the student
grades. In each block, it consists of each prelim, midterm and final grade that will required inputting
a student name, course, student grade in quiz, seatwork, laboratory exercises, assignment and
exam. The formula below show the following computation:
Prelim Grade = Quiz * 20% + Seatwork * 10% + Lab. Exercise * 20% + Prelim Exam * 50%
Midterm Grade = Quiz * 20% + Seatwork * 10% + Lab. Exercise * 20% + Midterm Exam * 50%
Total Midterm Grade = 1/3 Prelim Grade + 2/3 Midterm Grade
Final Grade = Quiz * 20% + Seatwork * 10% + Lab. Exercise * 20% + Final Exam *
50%
Total Final Grade = 1/3 Midterm Grade + 2/3 Final Grade
Sample screen layout:
Student Name : Juan dela Cruz
Course : BS CpE
Grades
Quiz :
Seatwork :
Lab. Exercises :
Assignment :
Prelim Exam :
Prelim Grade : __
Quiz :
Seatwork :
Lab. Exercises :
Assignment :
Midterm Exam:
Total Midterm Grade:
Quiz :
Seatwork :
Lab. Exercises :
Assignment :
Final Exam: :
Total Final Grade:
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
SUPPLEMENTAL ACTIVITIES
1. Write a parameter and return program that will require the user to enter a temperature in Celsius
and convert it to degree Fahrenheit and degree Kelvin.
Formula:
Fahrenheit = (9/5) * Celsius + 32
Kelvin = Celsius + 273
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
2. Refer to No. 1, transform the program using function header and function prototype.
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
3. Write a global and local variable program that would require the user to input a value of the Radius
of a circle and then show the output in the diameter, circumference of the circle and area of the
circle.
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
6. Conclusion:
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________