1.
#include <iostream>
using namespace std;
class Animal
{
public:
Animal() {}
virtual void perform() = 0;
};
class Lion:public Animal
{
public:
Lion() {}
void perform()
{
cout << "lion" << endl;
}
};
class Monkey:public Animal
{
public:
Monkey() {}
void perform()
{
cout << "monkey" << endl;
}
};
class Cat:public Animal
{
public:
Cat() {}
void perform()
{
cout << "cat" << endl;
}
};
int main()
{
Animal *p;
Lion lion;
Monkey monket;
Cat cat;
p = &lion;
p->perform();
p = &monket;
p->perform();
p = &cat;
p->perform();
return 0;
}
#include <iostream>
using namespace std;
template <typename T>
void fun(T &a, T &b)
{
T temp;
temp = a;
a = b;
b = temp;
}
int main()
{
int a = 10 , b = 20;
fun(a,b);
cout << a << " " << b << endl;
string c = "f" , h = "y";
fun(c,h);
cout << c << " " << h << endl;
return 0;
}
3.