Write the output of the following C++ code. Also, write the name of feature
of Object Oriented Programming used in the following program jointly
illustrated by the Function 1 to Function 4.
void My_fun ( ) // Function 1
{
for (int I=1 ; I<=50 ; I++) cout<< "-" ;
cout<<end1 ;
}
void My_fun (int N) // Function 2
{
for (int I=1 ; I<=N ; I++) cout<<"*" ;
cout<<end1 ;
}
void My_fun (int A, int B) // Function 3
{
for (int I=1. ;I<=B ;I++) cout <<A*I ;
cout<<end1 ;
}
void My_fun (char T, int N) // Function 4
{
for (int I=1 ; I<=N ; I++) cout<<T ;
cout<<end1;
}
void main ( )
{
int X=7, Y=4, Z=3;
char C='#' ;
My_fun (C,Y) ;
My_fun (X,Z) ;
}
Answers
Answered by
23
Hey Buddy
Here is the Answer
----------------------------------------
As function with parameters Char, int is called first, so function 4 will be executed first
So, output for function 4 is
####
Now function with parameters int, int is called, so function 3 will be executed
Output for function 3
7 14 21
So, output for this code will be
####
7 14 21
Note :- Function overloading is done only when
- Name of functions are same
- order of parameters are different
- number of parameters are different
I can help you in JAVA, C, C++, HTML, CSS AND JAVA SCRIPT
Peace
:)
Similar questions