Question 1 :
#include <iostream>
using namespace std;
class B; // LINE-1
class A {
int a_ = 0;
public:
A(int x) : a_(x) { }
int addB(B&);
int subtractB(B&);
};
class B {
int b_ = 5;
public:
friend class A; // LINE-2
};
Question 2:
Complex operator *(const Complex &c) { // LINE-1
int x, y;
x = re*(c.re) - im*(c.im); // LINE-2
y = im*(c.re) + (c.im)*re; // LINE-3
Complex t1(x, y);
return t1;
}
Question 3:
if(data == m1.data) m.data = 1; // LINE-1
return m;
}
};
void fun(myClass m) { // LINE-2
Question 4:
#include <iostream>
using namespace std;
class myClass {
int data;
static myClass *t; // LINE-1 Complete the declaration
myClass(int x) : data(x) { }
public:
static myClass *create(int x) { // LINE-2 Mention return type of the function
if (!t)
t = new myClass(x); // LINE-3 Allocate memory towards object t
return t;
}
0 Comments:
Post a Comment