MABS Institution
11th Computer Science Monthly Test -1 ( Polymorphism )-Aug 2020
-
-
-
-
-
How will you invoke the function dispchar() for the following input?
To print Dollar for 10 times
void dispchar(char ch='$';int size=10)
{
for(int i=1;i < = size;i++)
cout << ch
}
dispchar ();
dispchar( ch,size);
dispchar($,10);
dispchar('$',10 times);
-
Which of the following provides flexibility of creating multiple type of objects for a class?
function overloading
operator overloading
constructor overloading
object overloading
-
Which of the following not considered in overloading?
Default argument
return type
constructor
furictions
a and b.
-
Which of the following statement is true or false?
(i) Polymorphism means many shapes
(ii) Polymorphism is acheived through overloading
(iii) Overloading means a name having only one distinct meaning
(iv) Overload resolution means not' selecting appropriate overloaded functioni-true, ii-true, iii-false, iv-false
i-true, ii-false, iii-true, iv-false
i-false, ii-false, iii-true, iv-true
i-false, ii-true, iii-true, iv-false
-
#include< iostream >
using namespace std;
class Point {
private:
int x, y;
public:
point(int x1,int y1)
{
x=x1;y=y1;
}
void operator+(Point&pt3);
void showO {cout << "x=" << x << " ,y=" << y;}
};
void Point::operator+(point &pt3)
{
x + =pt3.x;
y+=pt3.y;
}
int main ()
{
point ptl(3,2),pt2(5,4);
pt1+pt2;
pt1.show ();
return 0;
}
Which of the following statement invoke operator overloading?pt1+pt2
Pointpt1(3,2),pt2(5,4)
pt1.showt);
return 0;
-
Does the return type of a function help in overloading a function?
-
What is functions signature?
-
When the two function can not be overloaded?
-
What is overload resolution?
-
What is the use of overloading a function?
-
List the operators that cannot be overloaded.
-
How the compiler identifies a given function is a constructor?
-
class add{int x; public: add(int)}; Write an outline definition for the constructor.
-
What is overloaded function?
-
Define polymorphism.
-
Write a short note on operator 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;
} -
How does a compiler decide as to which function should be invoked when there are many functions? Give an example.
-
class sale ( int cost, discount ;public: sale(sale &); Write a non inline definition for constructor specified;
-
-
What is function signature?
-
Discuss the benefit of constructor overloading?
-
-
What is operator overloading? Give some example of operators which can be overloaded.
-
What are the rules for function overloading?
-
Give the output of the following program.
-
Write a c++ program to find Addition and Subtraction of complex number using 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 the coding for the following output using constructor overloading.
Output:
Constructor without parameters ...
Parameterized constructor ...
Copy Constructor ....
Enter data ... 20 30
Object a:
The numbers are ..20 30
Thesum of the numbers are .. 50
Object b:
The numbers are..10 20
The sum of the numbers are .. 30
Object c..
The numbers are ..10 20
The sum of the numbers are .. 30 -
Write a program to find the area of a rectangle using constructor overloading in a class.
-
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;
} -
#include< iostream >
using namespace std;
class add
{
int num 1, num2, sum;
public:
add()
{
cout << "\n Constructor without parameters ..";
num1=0;
num2=0;
sum =0:
}
add (int s1, int s2)
{
cout << "\nParameterized constructor ..";
num1 = s1;
num2=s2;
sum=0;
}
add (add &a)
{
cout << "\n Copy Constructor ...";
num1 = a.num1;
num2 = a.num2;
sum=0;
}
void getdatat)
{
cout<<"\nEnter data ...";
cin>>num1 >>num2;
}
void addition()
{
sum=num 1+num2;
}
void putdata()
{
cout << "\n The numbers are ..";
cout << num1<< '\t' << nurn2;
cout << "\n The sum of the numbers are .." << sum;
};
int main()
{
add a, b(10,20), c(b);
a.getdata();
a.addition();
b.addition();
c.addition();
cout << "\n Object a:";
a.putdata();
cout << "\n Obect b:";
a.putdata();
cout << "\n Obect c..";
c.putdata();
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.
-
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.