0% found this document useful (0 votes)
49 views

C++ Lab 10 Alpha

This lab manual provides exercises for students to practice defining and calling functions in C++. The objectives are to practice function declaration, definition, calling built-in and void functions. The questions include writing functions to find the maximum of two numbers, perform arithmetic on three inputs, generate a number table, count characters in a string, and calculate clothing sizes using functions. The final question has errors to indicate and a function call to demonstrate.

Uploaded by

Attia Batool
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

C++ Lab 10 Alpha

This lab manual provides exercises for students to practice defining and calling functions in C++. The objectives are to practice function declaration, definition, calling built-in and void functions. The questions include writing functions to find the maximum of two numbers, perform arithmetic on three inputs, generate a number table, count characters in a string, and calculate clothing sizes using functions. The final question has errors to indicate and a function call to demonstrate.

Uploaded by

Attia Batool
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

LAB MANUAL # 10

Course: Computer Programming (CP-107)


Session: 22CP (alpha)

C++ Functions

This lab has been designed to enable students to define their own function and call them in
main(). In this lab students will practice declaring function, defining function and calling
function. Students will also use built-in functions provided in c++. Clear concept about C++
functions has already been provided in the class along with examples.
Objectives:
In this lab, you will practice:
• Function declaration.
• Function definition.
• Calling function.
• Using bulit in functions of c++.
• Defining void functions.

Lab Tasks:
Question # 1:
Write a function that accepts two numbers as arguments and returns maximum number.

Question # 2:
Write a function which accepts three arguments, two numbers and one arithmetic
operator and returns the result.

Question # 3:
Write a function which accepts one integer number as an argument and generates table
of that number.

Question # 4:
Write a function that takes string as input. The function should return the number of
characters in the string.
Question # 5:
Write a program that asks for the user’s height, weight, and age, and then computes
clothing sizes according to the formulas:
• Hat size = weight in pounds divided by height in inches and all that multiplied by 2.9.
• Jacket size = height times weight divided by 288 and then adjusted by adding 1/8 of an
inch for each 10 years over age 30. (Note that the adjustment only takes place after a full
10 years. So, there is no adjustment for ages 30 through 39, but 1/8 of an inch is added
for age 40.)
LAB MANUAL # 10
Course: Computer Programming (CP-107)
Session: 22CP (alpha)

• Waist in inches = weight divided by 5.7 and then adjusted by adding 1/10 of an inch for
each 2 years over age 28. (Note that the adjustment only takes place after a full 2 years.
So, there is no adjustment for age 29, but 1/10 of an inch is added for age 30.)

Use functions for the calculation of hat, jacket and waist size.

Question # 6:
Write a program that applies the following built-in functions to a number, square root,
ceil, floor, round and power.

Question # 7:
Do as directed:

void total(int value1, value2, value3) Indicate errors


{
return value1 + value2 + value3;
}
void area(int length = 30, int width) Indicate errors
{
return length * width;
}
int cube(int num) Write a statement that passes the value
{
return num * num * num; 4 to this function and assigns its return
} value
to the variable result.
void func1(double, int); Output
int main()
{
int x = 0;
double y = 1.5;
cout << x << " " << y << endl;
func1(y, x);
cout << x << " " << y << endl;
return 0;
}
void func1(double a, int b)
{
cout << a << " " << b << endl;
a = 0.0;
b = 10;
cout << a << " " << b << endl;
}

****************

You might also like