Assuming there is no error in main() complete the class Rectangle and its functions.
int main()
{
Rectangle rect1(3.4, 5.68);
Rectangle rect2(2.4, 4.68);
if (rect1-- != ++rect2) //increment/decrement will add & subtract by 1 of each data members of class
cout << ”\n Both are not of same size”;
else
cout << ”\n Both are of same size”;
rect1.show(); \\will display values 2.4, 4.68
Rectangle rect3 = rect1 + rect2;
rect3.show(); \\will display values 5.8, 10.36
system(“pause”);
return 0;
}
class Base {
public:
int a;
virtual void func1() = 0;
// Constructor
Base(int i) {
a = i;
}
// Pure Virtual destructor
virtual ~Base() = 0;
};
// Pure virtual destructor is defined
Base :: ~Base() {
cout << "Pure virtual destructor is defined here" << endl;
}
class Derived : public Base {
int b;
public:
// Constructor of derived class
Derived(int x, int y) : Base(y) { b = x; }
// Destructor of derived class
~Derived() {
cout << "Derived class destructor" << endl;
}
//Definition for pure virtual function
void func1() {
cout << "The value of a is " << a << " and b is " << b << endl;
}
};
int main() {
Base *b = new Derived(5,10);
b->func1();
delete b;
}
Comments
Leave a comment