You are on page 1of 6

1.

Function
Overloading
Ques1. 1) Illustrating the concept of function overloading by using the
function volume() .

Ans) #include<iostream.h>

#include<conio.h>

int volume(int s)

return s*s*s;

double volume(double r, int h)

return 3.14*r*r* (double) h;

long volume(long l,intb,int h)

return l*b*h;

int main()
{

cout<<endl<<volume(10);

cout<<endl<<volume(2.5,8);

cout<<endl<<volume(100,75,15);

Output:

Ques1.2)Showing the concept of function overloading by using the


function print()

To print different data types .

Ans) #include<iostream.h>

class printing

public:

void print(int i)

cout<<”Printing int:”<<i<<endl;

void print(double f)
{

cout<<”Printing float:”<<f<<endl;

void print(char c[20])

cout<<”Printing string:”<<c<<endl;

};

int main(void)

printing pd;

pd.print(5);

pd.print(500.263);

pd.print(“Hello C++);

return 0;

Output:
Ques 2.3)illustrating the concept of passing character type default
arguments with function overloading .

Ans) #include<iostream.h>

#include<conio.h>

void draw_line(char ch=’*’,int count=80)

void main()

clrscr();

draw_line();

draw_line(‘#’);

draw_line(‘@’,50);

draw_line(‘*’,60);

getch();

void draw_line(char ch,int count)

cout<<endl;

for(int i=1;i<=count;i++)

cout<<ch;

}
Ques 1.4)explaining the concept of passing default parameter value

Ans) #include<iostream.h>

#include<conio.h>

void func(int x,int y,int z)

void main()

clrscr();

int a=10,b=20,c=30;

func(a,b,c);

func(5,4,3);

func(a,b);

func(1,2);

getch();

void func(int x,int y,int z)

cout<<"@@@entering into the function@@@"<<endl;

cout<<"x:-"<<x<<endl;
cout<<"y:-"<<y<<endl;

cout<<"z:-"<<z<<endl;

cout<<"@@@exiting from the function@@@"<<endl;

You might also like