Class Note
Class Note
WARISHA AAMIR
02-235231-044
BSIT 1(A)
WARISHA AAMIR
02-235231-044 BSIT 1(A)
FUNCTIONS OVERLOADING
Exercise 1
int comparison():
o this function determine the
smallest and largest number o
print the smallest and largest
number
2
WARISHA AAMIR
02-235231-044 BSIT 1(A)
CODE:
#include <iostream>
using namespace std;
void comparison(int a,int b)
{
if(a>b)
{ cout<<a<<" is the greatest number among first two "<<endl<<b<<" is the
smallest number among first two "<<endl;
}
else
{
cout<<b<<" is the greatest number among first two "<<endl<<a<<" is the smallest
number among first two "<<endl;
}
}
3
WARISHA AAMIR
02-235231-044 BSIT 1(A)
}
{
if ( (a>b&&a>c&&a>d) && (d<b&&d<c))
{
cout<<a<<" is the greatest number from list "<<endl<<d<<" is the
smallest number from list "<<endl;
}
else if ((a>b&&a>c&&a>d) && (c<b&&c<d))
{
cout<<a<<" is the greatest number from list "<<endl<<c<<" is the
smallest number from list "<<endl;
}
else if ( (a>b&&a>c&&a>d) && (b<c&&b<d))
{
cout<<a<<" is the greatest number from list "<<endl<<b<<" is the
smallest number from list"<<endl;
}
else if((b>a&&b>c&&b>d) && (d<a&&d<c))
{
cout<<b<<" is the greatest number from list "<<endl<<d<<" is the smallest number
from list"<<endl;
4
WARISHA AAMIR
02-235231-044 BSIT 1(A)
else if((b>a&&b>c&&b>d) && (c<a&&c<d))
{
cout<<b<<" is the greatest number from list "<<endl<<c<<" is the smallest
number from list "<<endl;
}
else if((b>a&&b>c&&b>d) && (a<c&&a<d))
{
cout<<b<<" is the greatest number from list "<<endl<<a<<" is the smallest number
from list "<<endl;
}
5
WARISHA AAMIR
02-235231-044 BSIT 1(A)
int main()
{
int num1,num2,num3,num4;
cout<<"Enter four numbers"<<endl;
cin>>num1;
cin>>num2;
cin>>num3;
cin>>num4;
comparison(num1,num2);
comparison(num1,num2,num3);
comparison(num1,num2,num3,num4);
return 0;
}
OUTPUT:
6|Page
WARISHA AAMIR
02-235231-044 BSIT 1(A)
Exercise 2
CODE:
#include<iostream>
int fab(int n)
{
if((n==1)||(n==0))
{
return(n);
}
else
{
7|Page
WARISHA AAMIR
02-235231-044 BSIT 1(A)
8|Page
WARISHA AAMIR
02-235231-044 BSIT 1(A)
return(fab(n-1)+fab(n-2));
}
}
int main()
{
int n,i=0;
cout<<"Input the number of terms for Fibonacci
Series:"; cin>>n;
cout<<"--------Fibonacci Series is as follows-----"<<endl;
while(i<n)
{
cout<<" "<<fab(i);
i++;
}
return 0;}
OUTPUT:
9|Page
WARISHA AAMIR
02-235231-044 BSIT 1(A)
Exercise 3
CODE:
#include<iostream>
}
}
int main()
10 | P a g
e
WARISHA AAMIR
02-235231-044 BSIT 1(A)
{
int n;
cout<<"Enter a number"<<endl;
cin>>n;
OUTPUT:
11 | P a g
e