0% found this document useful (0 votes)
126 views8 pages

Function Exercise

The document provides examples of function definitions for problems involving determining if a number is even or odd, getting a student's grade based on their mark, calculating the price of petrol based on the amount in liters, and finding the output of programs using functions that perform operations like addition, modulo, and returning values. It also provides a discussion question involving writing function definitions to calculate ticket prices and discounts for a kids' playland.

Uploaded by

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

Function Exercise

The document provides examples of function definitions for problems involving determining if a number is even or odd, getting a student's grade based on their mark, calculating the price of petrol based on the amount in liters, and finding the output of programs using functions that perform operations like addition, modulo, and returning values. It also provides a discussion question involving writing function definitions to calculate ticket prices and discounts for a kids' playland.

Uploaded by

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

Function

Write function definition for the following


problems:
Function findNum( ) receives a variable named num. Identify whether
the number is odd or even and display the output “EVEN NUMBER” or
“ODD NUMBER”.
Write function definition for the following
problems:
Function getGrade( ) receives a variable named mark. Identify and
display the students’ grades based on the following table.
Mark Grade
Greater than 80 A
70 – 79 B
50 – 69 C
Less than 50 F
Write function definition for the following
problems:
Function calPetrol( ) receives the amount of petrol in litres. Calculate
and return the price that needs to be paid if 1 litre of petrol costs
RM2.85.
Find the output for the following program:
int compute(int, int);
Void main( )
{
int y = 4, z = 6;
y = compute(y, z);
cout<<y<<endl;
}
int compute(int y, int z)
{
int a = 0;
y = y + 1;
a = y – z;
return a;
}
Find the output for the following program:
void display (int, char)
int main()
{
display (3, ‘@’);
}
Void display(int m, char n)
{
for (int i = 10; i>m; i--)
cout << n;
}
Find the output for the following program:
int funct1(int i)
{
int a, b; a = 1 * 3;
if (a < 10)
b = i % 2;
else
b = i % 3;
return b + 1;
}
Discussion Question
KidsPlayland offers great discounts for entrance ticket during the school holidays. The
following are the prices and discounts
Category
given for children and adults.
Normal Price (RM) Discount
Children (C) 45.00 20%
Adult (A) 5.00 5%

a. Write a function definition for a function named price( ) that receives categories in
character code and quantity. The function will calculate and return the totalPrice.
b. Write a function definition for a function named Discount( ) that receives categories
in character code and total price. The function will calculate and return PriceDisc.
c. Write a main function which prompts the user to input the category and quantity.
The program will call the above functions to calculate the total price after discount.
Print the receipt which displays the quantity and the total price that needs to be
paid by each customer

You might also like