Class 7  >  C++ Programming for Beginners  >  Test: C++ Function Overloading Download as PDF

Test: C++ Function Overloading


Test Description

15 Questions MCQ Test C++ Programming for Beginners | Test: C++ Function Overloading

Test: C++ Function Overloading for Class 7 2023 is part of C++ Programming for Beginners preparation. The Test: C++ Function Overloading questions and answers have been prepared according to the Class 7 exam syllabus.The Test: C++ Function Overloading MCQs are made for Class 7 2023 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: C++ Function Overloading below.
Solutions of Test: C++ Function Overloading questions in English are available as part of our C++ Programming for Beginners for Class 7 & Test: C++ Function Overloading solutions in Hindi for C++ Programming for Beginners course. Download more important topics, notes, lectures and mock test series for Class 7 Exam by signing up for free. Attempt Test: C++ Function Overloading | 15 questions in 15 minutes | Mock test for Class 7 preparation | Free important questions MCQ to study C++ Programming for Beginners for Class 7 Exam | Download free PDF with solutions
1 Crore+ students have signed up on EduRev. Have you?
Test: C++ Function Overloading - Question 1

What happens when objects s1 and s2 are added?

string s1 = "Hello";
string s2 = "World";
string s3 = (s1+s2).substr(5);

Detailed Solution for Test: C++ Function Overloading - Question 1

string is class in C++, therefore when we do (s1+s2) a temporary object is created which stores the result of s1+s2 and then that object calls the function substr() and as that is an object of string class hence substr is a callable function for that temporary string object.

Test: C++ Function Overloading - Question 2

What is operator overloading in C++?

Detailed Solution for Test: C++ Function Overloading - Question 2

Operator overloading helps programmer to give his/her own meaning to an operator for user defined data types(eg, classes).

Test: C++ Function Overloading - Question 3

How many approaches are used for operator overloading?

Detailed Solution for Test: C++ Function Overloading - Question 3

There are 3 different approaches used for operator overloading:
i. Overloading unary operator.
ii. Overloading binary operator.
iii. Overloading binary operator using a friend function.

Test: C++ Function Overloading - Question 4

Which of the following operator can be overloaded?

Detailed Solution for Test: C++ Function Overloading - Question 4

?:, :: and . cannot be overloaded whereas == can be overloaded.

Test: C++ Function Overloading - Question 5

Which of the following operator can be used to overload when that function is declared as friend function?

Detailed Solution for Test: C++ Function Overloading - Question 5

When an operator overlaoded function is declared as friend function then [], () and -> cannot be overloaded.

Test: C++ Function Overloading - Question 6

Which is the correct example of a binary operator?

Detailed Solution for Test: C++ Function Overloading - Question 6

+(adding two operands) requires two operands whereas ++(increases value by 1), –(decreases value by 1) and *(dereferencing operator used for accessing value of pointers) requires only one operand.

Test: C++ Function Overloading - Question 7

Which is called ternary operator?

Detailed Solution for Test: C++ Function Overloading - Question 7

?: is called ternary operator because it separates three expressions. exp1 ? exp2 : exp3.

Test: C++ Function Overloading - Question 8

What will be the output of the following C++ code?

#include <iostream>
#include <string>
using namespace std;
class complex
{
    int i;
    int j;
        public:
    complex(){}
    complex(int a, int b)
        {
            i = a;
        j = b;
    }
 
    complex operator+(complex c)
        {
        complex temp;
        temp.i = this->i + c.i;
        temp.j = this->j + c.j;
        return temp;
    }
 
    void show(){
        cout<<"Complex Number: "<<i<<" + i"<<j<<endl;
    }
};
 
int main(int argc, char const *argv[])
{
    complex c1(1,2);
    complex c2(3,4);
    complex c3 = c1 + c2;
    c3.show();
    return 0;
}

Detailed Solution for Test: C++ Function Overloading - Question 8

As we have defined in the class complec that when we add the two objects of the class complex then add those two complex numbers and show() displays that result.

Test: C++ Function Overloading - Question 9

Given the following C++ code. How would you define the < operator for Box class so that when boxes b1 and b2 are compared in if block the program gives correct result?

#include <iostream>
#include <string>
using namespace std;
class Box
{
    int capacity;
     public:
    Box(){}
    Box(double capacity){
        this->capacity = capacity;
    }
};
 
int main(int argc, char const *argv[])
{
    Box b1(10);
    Box b2 = Box(14);
    if(b1 < b2){
        cout<<"Box 2 has large capacity.";
    }
    else{
        cout<<"Box 1 has large capacity.";
    }
    return 0;
}

Detailed Solution for Test: C++ Function Overloading - Question 9

As we need to give the result after comparing the capacity of two boxes. We use < operator and as this is the first operand and second operand is passed so we need to do this->capacity < b.capacity (passed object) to make the program run.

Test: C++ Function Overloading - Question 10

Pick the incorrect statements out of the following.

Detailed Solution for Test: C++ Function Overloading - Question 10

Arity means a number of operands an operator requires to perform its action and operator overloading does not changes the arity of any operator.

Test: C++ Function Overloading - Question 11

In the case of friend operator overloaded functions how many maximum object arguments a binary operator overloaded function can take?

Detailed Solution for Test: C++ Function Overloading - Question 11

In the case of friend operator overloaded functions binary operator overloaded function should take maximum two object argument.

Test: C++ Function Overloading - Question 12

In case of non-static member functions how many maximum object arguments a binary operator overloaded function can take?

Detailed Solution for Test: C++ Function Overloading - Question 12

In the case of non-static member functions binary operator overloaded function should take maximum one object argument only.

Test: C++ Function Overloading - Question 13

Give the function prototype of the operator function which we need to define in this program so that the program has no errors.

#include <iostream>
#include <string>
using namespace std;
class Box{
    int capacity;
public:
    Box(){}
    Box(double capacity){
        this->capacity = capacity;
    }
};
 
int main(int argc, char const *argv[])
{
    Box b1(10);
    Box b2 = Box(14);
    if(b1 == b2){
        cout<<"Equal";
    }
    else{
        cout<<"Not Equal";
    }
    return 0;
}

Detailed Solution for Test: C++ Function Overloading - Question 13

In this question we are asked to give the function prototypr not the function definition so the answer should not contain {} braces. The correct overloaded function is bool operator==(Box b);

Test: C++ Function Overloading - Question 14

What will be the output of the following C++ code?

#include <iostream>
#include <string>
using namespace std;
class Box{
    int capacity;
    bool operator<(Box b){
        return this->capacity < b.capacity ? true : false;
    }
public:
    Box(){}
    Box(double capacity){
        this->capacity = capacity;
    }
 
};
 
int main(int argc, char const *argv[])
{
    Box b1(10);
    Box b2 = Box(14);
    if(b1 < b2){
        cout<<"Box 2 has large capacity.";
    }
    else{
        cout<<"Box 1 has large capacity.";
    }
    return 0;
}

Detailed Solution for Test: C++ Function Overloading - Question 14

As the operator overloaded function defined is private therfore on comparison the function cannot be called from outside therefore the program gives error.

Test: C++ Function Overloading - Question 15

What will be the output of the following C++ code?

#include <iostream>
#include <string>
using namespace std;
class A
{
    static int a;
 
   public:
    void show()
        {
        a++;
        cout<<"a: "<<a<<endl;
    }
    void operator.()
        {
        cout<<"Objects are added\n";
    }
};
 
class B
{
     public:
};
 
int main(int argc, char const *argv[])
{
    A a1, a2;
    return 0;
}

Detailed Solution for Test: C++ Function Overloading - Question 15

.(dot) operator cannot be overloaded therefore the program gives error.

15 videos|20 docs|13 tests
Use Code STAYHOME200 and get INR 200 additional OFF
Use Coupon Code
Information about Test: C++ Function Overloading Page
In this test you can find the Exam questions for Test: C++ Function Overloading solved & explained in the simplest way possible. Besides giving Questions and answers for Test: C++ Function Overloading, EduRev gives you an ample number of Online tests for practice