MABS Institution
11th Computer Science Weekly Test - 1 ( Polymorphism )-Aug 2020
-
-
-
-
-
-
-
-
-
-
-
-
-
-
What is the use of overloading a function?
-
What is operator overloading? Give some example of operators which can be overloaded.
-
What is the output of the following program:
#inclue
using namespace std;
void print(int i)
{cout << " it is Integer" << l << endl;}
void print(double f)
{cout << '' It is fioat" << f << endl;}
void print(string c)
{cout << '' it is string'' << c << endl;}
int main 0 {
print(10);
print(10.10);
print("Ten ");
return 0;
} -
-
Discuss the benefit of constructor overloading?
-
How does a compiler decide as to which function should be invoked when there are many functions? Give an example.
-
-
Write a short note on operator overloading.
-
Answer the question (i) to (v) after going through the following class.
classBook
{
intBookCode ; char Bookname[20];float fees;
public:
Book( ) //Function 1
{
fees=1000;
BookCode=1;
strcpy (Bookname,"C++");
}
void display(float C) //Function 2
{
cout< }
~Book( ) //Function 3
{
cout << "End of Book Object"< }
Book (intSC,char S[ ],float F) ; //Function 4
};
(i) In the above program, what are Function 1 and Function 4 combined together referred as?
(ii) Which concept is illustrated by Function3? When is this function called/ invoked?
(iii) What is the use of Function3?
(iv) Write the statements in main to invoke function1 and function2
(v) Write the definition for Function4. -
Write the output of the following program.
// constructor declared as outline member function
#include< iostream >
using namespace std;
class Perimeter
{
int 1, b, p;
public;
Perimeter 0;
Perimeter (int);
Perimeter (int,int);
Perimeter (Perimeter&);
void Calculate();
};
Perimeter:: Perimeter()
{
cout << "\n Enter the value of length and breath";
cin >> I >> b;
cout<<"\n \nN onParameterized constructor";
}
Perimeter::Perimeter(int a)
{
I=b=a;
cout << "\n\n Parameterized constructor. with one
argument";
}
Perimeter::Perimeter(int 11, in b1)
{
cout << "\n\n Parameterized constructor with 2 argument";
1=11;
b=b1;
}
Perimeter: :Perimeter(perimeter &p)
{
1=p.1;
b=p.b;
cout << "\n \n copy constructor";
}
void Perimeter ::CalculateO{
p = 2*(1+b);
cout<<p;
}
int main ()
{
Perimeter Obj;
cout << "\n perimeter of rectangle is";
Obj.Calculate 0;
Perimeter Obj 1(2);
cout << "\n perimeter of rectangle";
Obj lCalculatet);
Perimeter Obj2 (2,3);
cout << "\n perimeter of rectangle";
Objz.Calculatet);
perimeter obj3 (Obj2);
cout << "\n perimeter of rectangle";
obj3.CalculateO;
return 0;
} -
Write the output of the following program
include < iostream >
using namespace std;
class Seminar
{
int Time;
public:
Seminar()
{
Time=30;cout << "Seminar starts now"<}
void Lecture()
{
cout << "Lectures in the seminar on"<}
Seminar(int Duration)
{
Time=Duration;cout << "Welcome to Seminar "<}
Seminar(Seminar &D)
{
Time=D.Time;cout << "Recap of Previous Seminar Content "<}
~Seminar()
{
cout << "Vote of thanks"<}
};
int main()
{
Seminar s1,s2(2),s3(s2);
s1.Lecture();
return 0;
} -
-
Write a C++ program to concatenate two strings using operator overloading.
-
What are the rules for operator overloading?
-