Monday, 26 April 2021

Function overriding in C++

 #include<iostream.h>

#include<conio.h>

class A

{

public:

void show()

{

cout<<"Show-A"<<endl;

}

void display()

{

cout<<"Display"<<endl;

}

};

class B : public A

{

public:

void show()

{

cout<<"Show-B"<<endl;

}

};

int main()

{

clrscr();

B b;

b.show();

A a;

a.show();


b.display();

getch();

return 0;

}

Function Parameter Matching and Overloading Qus - 9

 #include<iostream.h>

#include<conio.h>

void show(char a)

{

cout<<"char - "<<a<<endl;

}

void show(float a)

{

cout<<"float - "<<a<<endl;

}

int main()

{

clrscr();

show('k');

//show(5);      //ambiguity

//show(6.5);    //ambiguity

show((float)6.5);

getch();

return 0;


}

Function Parameter Matching and Overloading Qus - 8

 #include<iostream.h>

#include<conio.h>

void show(float a)

{

cout<<"float - "<<a<<endl;

}

void show(double a)

{

cout<<"double - "<<a<<endl;

}

int main()

{

clrscr();

//show(5);     //coversion - abmiguity(float,double)

//show('k');  // ""

show(6.7);  //double

show((float)6.7);

show((double)5);

show((float)5);

float f=8.5;

show(f);

double f1=9.6;

show(f1);

//show();      //No Match - Error

getch();

return 0;


}

Function Parameter Matching and Overloading Qus - 7

 #include<iostream.h>

#include<conio.h>

void show(int a)

{

cout<<"int - "<<a<<endl;

}

void show(double a)

{

cout<<"double - "<<a<<endl;

}

int main()

{

clrscr();

show(5);     //Exact Match

show('k');  //promotion

show(6.7);  //promotion

//show();      //No Match - Error

getch();

return 0;


}

Function Parameter Matching and Overloading Qus - 6

 #include<iostream.h>

#include<conio.h>

void show(int a)

{

cout<<"int - "<<a<<endl;

}

void show(float a)

{

cout<<"float - "<<a<<endl;

}

int main()

{

clrscr();

show(5);     //Exact Match

show('k');  //promotion

//show(6.7);  //coversion - abmiguity (int, float)

show((float)6.7);

show((int)6.7);

//show();      //No Match - Error

getch();

return 0;


}

Function Parameter Matching and Overloading Qus - 5

 #include<iostream.h>

#include<conio.h>

void show(int a)

{

cout<<"int - "<<a<<endl;

}

void show(char a)

{

cout<<"char - "<<a<<endl;

}

int main()

{

clrscr();

show(5);     //Exact Match

show('k');  //Exact

//show(6.7);  //coversion   - Ambiguity

//show();      //No Match - Error

getch();

return 0;


}

Function Parameter Matching and Overloading Qus - 4

 #include<iostream.h>

#include<conio.h>

void show(double a)

{

cout<<"double - "<<a<<endl;

}

int main()

{

clrscr();

show(5);     //conversion

show('k');  //coversion

show(6.7);  //promotion

//show();      //No Match - Error

getch();

return 0;


}

Function Parameter Matching and Overloading Qus - 3

 #include<iostream.h>

#include<conio.h>

void show(float a)

{

cout<<"float - "<<a<<endl;

}

int main()

{

clrscr();

show(5);     //conversion

show('k');  //conversion

show(6.7);  //Exact Match

//show();      //No Match - Error

getch();

return 0;


}

Function Parameter Matching and Overloading Qus - 2

 #include<iostream.h>

#include<conio.h>

void show(char a)

{

cout<<"char - "<<a<<endl;

}

int main()

{

clrscr();

show(65);     //Conversion

show('k');  //Exact Match

show(66.7);  //coversion

//show();      //No Match - Error

getch();

return 0;


}

Function Parameter Matching and Overloading Qus - 1

 #include<iostream.h>

#include<conio.h>

void show(int a)

{

cout<<"int - "<<a<<endl;

}

int main()

{

clrscr();

show(5);     //Exact Match

show('k');  //promotion

show(6.7);  //coversion

//show();      //No Match - Error

getch();

return 0;


}