Welcome to the Classes and Operator Overloading in C++ MCQs Page
Dive deep into the fascinating world of Classes and Operator Overloading in C++ with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Classes and Operator Overloading in C++, a crucial aspect of Object Oriented Programming Using C++. In this section, you will encounter a diverse range of MCQs that cover various aspects of Classes and Operator Overloading in C++, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Object Oriented Programming Using C++.
Check out the MCQs below to embark on an enriching journey through Classes and Operator Overloading in C++. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Object Oriented Programming Using C++.
Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Classes and Operator Overloading in C++. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!
Classes and Operator Overloading in C++ MCQs | Page 13 of 39
Explore more Topics under Object Oriented Programming Using C++
#include
using namespace std;
class Distance
{
private:
int feet;
int inches;
public:
Distance()
{
feet = 0;
inches = 0;
}
Distance(int f, int i)
{
feet = f;
inches = i;
}
Distance operator()(int a, int b, int c)
{
Distance D;
D.feet = a + c + 10;
D.inches = b + c + 100 ;
return D
}
void displayDistance()
{
cout << feet << inches << endl;
}
};
int main()
{
Distance D1(11, 10), D2;
cout << "First Distance : ";
D1.displayDistance();
D2 = D1(10, 10, 10);
cout << "Second Distance :";
D2.displayDistance();
return 0;
}
#include
using namespace std;
void duplicate (int& a, int& b, int& c)
{
a *= 2;
b *= 2;
c *= 2;
}
int main ()
{
int x = 1, y = 3, z = 7;
duplicate (x, y, z);
cout << x << y << z;
return 0;
}
#include
using namespace std;
class three_d
{
int x, y, z;
public:
three_d() { x = y = z = 0; }
three_d(int i, int j, int k) { x = i; y = j; z = k; }
three_d operator()(three_d obj);
three_d operator()(int a, int b, int c);
friend ostream &operator<<(ostream &strm, three_d op);
};
three_d three_d::operator()(three_d obj)
{
three_d temp;
temp.x = (x + obj.x) / 2;
temp.y = (y + obj.y) / 2;
temp.z = (z + obj.z) / 2;
return temp;
}
three_d three_d::operator()(int a, int b, int c)
{
three_d temp;
temp.x = x + a;
temp.y = y + b;
temp.z = z + c;
return temp;
}
ostream &operator<<(ostream &strm, three_d op) {
strm << op.x << ", " << op.y << ", " << op.z << endl;
return strm;
}
int main()
{
three_d objA(1, 2, 3), objB(10, 10, 10), objC;
objC = objA(objB(100, 200, 300));
cout << objC;
return 0;
}
#include
#include
using namespace std;
class Complex
{
private:
float real;
float imag;
public:
Complex():real(0), imag(0){}
Complex operator ()(float re, float im)
{
real += re;
imag += im;
return *this;
}
Complex operator() (float re)
{
real += re;
return *this;
}
void display()
{
cout << "(" << real << "," << imag << ")" << endl;
}
};
int main()
{
Complex c1, c2;
c2 = c1(3.2, 5.3);
c1(6.5, 2.7);
c2(1.9);
cout << "c2=";c1.display();
cout << "c2=";c2.display();
return 0;
}
#include
using namespace std;
int operate (int a, int b)
{
return (a * b);
}
float operate (float a, float b)
{
return (a / b);
}
int main ()
{
int x = 5, y = 2;
float n = 5.0, m = 2.0;
cout << operate (x, y);
cout << operate (n, m);
return 0;
}
Suggested Topics
Are you eager to expand your knowledge beyond Object Oriented Programming Using C++? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!