MABS Institution
11th Computer Science Monthly Test - 2 ( Polymorphism )-Aug 2020
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Does the return type of a function help in overloading a function?
-
Write a program for function overloading.
-
What is the use of overloading a function?
-
How does a compiler decide as to which function should be invoked when there are many functions? Give an example.
-
Discuss the benefit of constructor overloading?
-
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;
} -
-
Write a short note on operator overloading.
-
What is operator overloading? Give some example of operators which can be overloaded.
-
-
class sale ( int cost, discount ;public: sale(sale &); Write a non inline definition for constructor specified;
-
What are the rules for function overloading?
-
Give the output of the following program.
-
What are the rules for operator overloading?
-
Answer the questions based on the following program
#include < iostream >
#include < string.h >
using namespace std;
class comp {
public:
chars[10];
void getstring(char str[10])
{
strcpy(s,str);
}
void operator==(comp);
};
void comp::operator==(comp ob)
{
if(strcmp(s,ob.s)==0)
cout << "\nStrings are Equal";
else
cout << "\nStrings are not Equal";
}
int main()
{
comp ob, ob1;
char string1[10], string2[10];
cout << "Enter First String:";
cin>>string1;
ob.getstring(string1);
cout << "\nEnter Second String:";
cin >> string2;
ob1.getstring(string2);
ob==ob1;
return 0;
}
(i) Mention the objects which will have the scope till the end of the program.
(ii) Name the object which gets destroyed in between the program
(iii)Name the operator which is over loaded and write the statement that invokes it.
(iv) Write out the prototype of the overloaded member function
(v)What types of operands are used for the overloaded operator?
(vi) Which constructor will get executed? Write the output of the program. -
Write a C++ program to concatenate two strings using 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 a c++ program to find Addition and Subtraction of complex number using operator overloading.
-
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;
}