Sie sind auf Seite 1von 4

Lab Journal – Lab 1

Object Oriented Programming

Lab Journal - Lab 1


Name: _________________________________

Enrollment #: _________________________________

Class: _________________________________

Objective

This lab is intended to provide an overview/recap of C++ functions.

Go through Lab 1 of the manual, attempt the given programs and verify their outputs. Once you
are done, perform the following tasks.

Task 1 :

Give answers to the following.

1. Write the prototype of a function named fnct() which accepts an int by value, a float by
reference and returns a char.

2. Using three variables a,b & c, call the function: double power(double, double);

3. Which of these are valid function declarations:

a. void function();
b. void function(void);
c. void function(int);
d. function(int);
e. int function();

Object Oriented Programming Page 1


Lab Journal – Lab 1

4. A function needs to compute the average as well as the sum of three integers passed to it
and return the answers in the main(). Suggest the prototype for this function.

5. What are inline functions?

Task 2 :

Write the output of the following code fragments.

1. int cube(int);
int main()
{

for(int i=0;i<10;i+=3)
cout << cube(i) << endl;

return 0;
}
int cube(int a)
{
return a*a*a;
}
Output:

2. int larger(int,int);
int main()
{
int x=10,y=5;
int m = larger(x,y);
cout<<m<<endl;
return 0;
}

Object Oriented Programming Page 2


Lab Journal – Lab 1

int larger(int a,int b)


{
if (a>b)
return a;
else
return b;
}

Output:

3. void decrement(int);
int main()
{

int x=10;
cout<< x <<endl;
decrement(x);
cout<< x <<endl;
return 0;
}
void decrement(int x)
{
x--;
cout<< x <<endl;
x--;

Output:

Exercise 1

Write a program with a function isPrime() which takes an integer as an argument


and returns

Object Oriented Programming Page 3


Lab Journal – Lab 1

Exercise 2

Write a program with a function volume() which accepts three sides of a cube
and returns its volume. Provide a default value of 1 for all the three sides of a
cube. Call this function with zero, one, two and three arguments and display the
volume returned in the main().

Do Exercises 1 and 2 and get them checked by your instructor. If you are unable to complete
the tasks in the lab session, deposit this journal alongwith your programs (printed or
handwritten) before the start of the next lab session.

S No. Exercise Checked By:


1. Exercise 1
2. Exercise 2

+++++++++++++++++++++++++

Object Oriented Programming Page 4

Das könnte Ihnen auch gefallen