Question 1
#include <iostream>
using namespace std;
class Point
{
int x, y;
public:
Point(const Point &p) { x = p.x; y = p.y; }
int getX() { return x; }
int getY() { return y; }
};
int main()
{
Point p1;
Point p2 = p1;
cout << \"x = \" << p2.getX() << \" y = \" << p2.getY();
return 0;
}
Question 2
#include <iostream>
using namespace std;
class Point
{
int x, y;
public:
Point(int i = 0, int j = 0) { x = i; y = j; }
int getX() { return x; }
int getY() { return y; }
};
int main()
{
Point p1;
Point p2 = p1;
cout << \"x = \" << p2.getX() << \" y = \" << p2.getY();
return 0;
}
Question 3
#include<iostream>
#include<stdlib.h>
using namespace std;
class Test
{
public:
Test()
{ cout << \"Constructor called\"; }
};
int main()
{
Test *t = (Test *) malloc(sizeof(Test));
return 0;
}
Question 4
<br>
#include < iostream ><br>
using namespace std;<br><br>
class Test<br>
{<br>
public:<br>
Test() { cout << \"Hello from Test() \"; }<br>
} a;<br><br>
int main()<br>
{<br>
cout << \"Main Started \";<br>
return 0;<br>
}
Question 5
#include<iostream>
#include<string.h>
using namespace std;
class String
{
char *str;
public:
String(const char *s);
void change(int index, char c) { str[index] = c; }
char *get() { return str; }
};
String::String(const char *s)
{
int l = strlen(s);
str = new char[l+1];
strcpy(str, s);
}
int main()
{
String s1(\"geeksQuiz\");
String s2 = s1;
s1.change(0, \'G\');
cout << s1.get() << \" \";
cout << s2.get();
}
Question 6
#include<iostream>
using namespace std;
class Point {
int x;
public:
Point(int x) { this->x = x; }
Point(const Point p) { x = p.x;}
int getX() { return x; }
};
int main()
{
Point p1(10);
Point p2 = p1;
cout << p2.getX();
return 0;
}
Question 7
Question 8
#include<iostream>
using namespace std;
class Test
{
public:
Test();
};
Test::Test() {
cout << \" Constructor Called. \";
}
void fun() {
static Test t1;
}
int main() {
cout << \" Before fun() called. \";
fun();
fun();
cout << \" After fun() called. \";
return 0;
}
Question 9
#include <iostream>
using namespace std;
class Test
{
private:
int x;
public:
Test(int i)
{
x = i;
cout << \"Called\" << endl;
}
};
int main()
{
Test t(20);
t = 30; // conversion constructor is called here.
return 0;
}
Question 10
#include<iostream>
using namespace std;
class Test
{
public:
Test(Test &t) { }
Test() { }
};
Test fun()
{
cout << \"fun() Called\\n\";
Test t;
return t;
}
int main()
{
Test t1;
Test t2 = fun();
return 0;
}
There are 26 questions to complete.