0% found this document useful (0 votes)
47 views2 pages

Computer Programming Lab 9: Purpose

This document contains instructions for Lab 9 in a Computer Programming course. It outlines 5 questions to be answered involving writing C++ programs that utilize functions of different types: void functions without parameters, void functions with pass by value and reference parameters, and functions that return values. It provides examples of functions that print temperature opinions based on input, print dates in a specific format, calculate and display rectangle areas by calling separate functions for input, calculation and output, convert cups to fluid ounces, and calculate falling distance using a formula. The lab is overseen by instructors Fatima and Zainab.

Uploaded by

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

Computer Programming Lab 9: Purpose

This document contains instructions for Lab 9 in a Computer Programming course. It outlines 5 questions to be answered involving writing C++ programs that utilize functions of different types: void functions without parameters, void functions with pass by value and reference parameters, and functions that return values. It provides examples of functions that print temperature opinions based on input, print dates in a specific format, calculate and display rectangle areas by calling separate functions for input, calculation and output, convert cups to fluid ounces, and calculate falling distance using a formula. The lab is overseen by instructors Fatima and Zainab.

Uploaded by

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

Air University, Islamabad.

Computer Programming

Lab 9

PURPOSE

1. To introduce the concept of functions (procedures)


2. To work with void functions (procedures) that has no parameters
3. To introduce and work with void functions (procedures) that have pass
by value and pass by reference parameters
4. To introduce and work with functions (procedures) that returns some
value.
5. To introduce the concept of functions that return a value
6. To introduce the concept of overloading functions
7. To introduce the concept of scope
8. To understand the difference between static, local and global variables

Question: 1
Write a program in C++ that has function printTempOpinion (int temp) which prints "Cold"
on if the temperature is below 10, "OK" if the temperature is in the range 20 - 30, "Hot" if
the temperature is above 30.

Question: 2
Write a C++ program which has a printdate (int, int, int) function. Get month, day & year
from user in main ( ). Call the function printDate(int, int, int), Put a check in printDate()
using if statement (month < 1 || month > 12 || day < 1 || day > 31 || year < 0) & if it violates
the rule display ―Must Enter a Valid Date, otherwise display the date in this format
(dd,mm,yyyy)

Lab Instructor: Fatima and Zainab


Air University, Islamabad.

Question: 3
Write a program that asks the user to enter the width and length of a rectangle and then
display the rectangle’s area. The program calls the following functions,
 getLength – This function should ask the user to enter the rectangle’s length and
then return that value as a double .
• getWidth – This function should ask the user to enter the rectangle’s width and
then return that value as a double .
• getArea – This function should accept the rectangle’s length and width as
arguments and return the rectangle’s area. The area is calculated by multiplying the
length by the width.
• displayData – This function should accept the rectangle’s length, width, and area as
arguments and display them in an appropriate message on the screen.

Question: 4
Your friend Michael runs a catering company. Some of the ingredients that his recipes
require are measured in cups. When he goes to the grocery store to buy those ingredients,
however, they are sold only by the fluid ounce. He has asked you to write a simple program
that converts cups to fluid ounces.
You design the following algorithm:
1. Display an introductory screen that explains what the program does.
2. Get the number of cups.
3. Convert the number of cups to fluid ounces and display the result.

Question: 5
When an object is falling because of gravity, the following formula can be used to determine
the distance the object falls in a specific time period:
d=1/2gt2
The variables in the formula are as follows: d is the distance in meters, g is 9.8, and t is the
amount of time, in seconds, that the object has been falling. Write a function named
fallingDistance that accepts an object’s falling time (in seconds) as an argument. The
function should return the distance, in meters, that the object has fallen during that time
interval. Write a program that demonstrates the function by calling it in a loop that passes
the values 1 through 10 as arguments and displays the return value.

Lab Instructor: Fatima and Zainab

You might also like