oop lab 1
oop lab 1
REG NO.FA24B1-SE-081
COURSE TITLE: OBJECT ORIENTED
PROGRAMMING
SUBMITTED TO: SIR REHAN
BSSE 1-A
LAB 01
Lab 01
Task 1 :
Q1. Write the prototype of a function named fnct() which accepts an int by value, a float by
Q2.Using three variables a,b & c, call the function: double power(double, double);
Q4.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.
Ans: We can solve this problems in 3 ways i.e using structures, using pointers or passing value by
reference.
Q5.What are inline functions?
Ans:Inline functions are functions whose body is substituted directly into the code where they’re called,
potentially improving performance by reducing function call overhead.
Task 2 :
Int cube(int);
Int main()
For(int i=0;i<10;i+=3)
Return 0;
Int cube(int a)
Return a*a*a;
}
Output:
Int larger(int,int);
Int main()
Int x=10,y=5;
Int m = larger(x,y);
Cout<<m<<endl;
Return 0;
{
If (a>b)
Return a;
Else
Return b;}
Output:
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:
Task 3:
COMPILE a program with a function isPrime() which takes
an integer as an argument and returns true if the
argument is a prime number.
#include "stdafx.h"
#include<iostream>
using namespace std;
if (isPrime(number))
cout << number << " is a prime number." << endl;
else
cout << number << " is not a prime number." << endl;
system("pause");
return 0;
}
Task 4:
Write a program having a inline function average() which
takes 5 float values as argument and return the average
of them.
#include "stdafx.h"
#include<iostream>
using namespace std;
inline float average(float a, float b, float c, float d, float e) {
return (a + b + c + d + e) / 5.0;
}
cout << "The average is: " << average(num1, num2, num3, num4, num5) << endl;
system("pause");
return 0;
}
//