Assignment 9 CPP
Assignment 9 CPP
// Class definition
class Number {
private:
int value;
public:
// Default constructor
Number() : value(0) {}
// Parameterized constructor
Number(int val) : value(val) {}
// Copy constructor
Number(const Number& other) {
value = other.value;
}
int main() {
// Create two Number objects
Number num1(5);
Number num2(10);
// Base class
class Shape {
protected:
int width;
int height;
public:
void setWidth(int w) {
width = w;
}
void setHeight(int h) {
height = h;
}
};
// Derived class
class Rectangle : public Shape {
public:
int getArea() {
return width * height;
}
};
int main() {
Rectangle rect;
return 0;
}
Output:
int main() {
int num1 = 5, num2 = 10, num3 = 15;
float num4 = 2.5, num5 = 3.7;
return 0;
}
Output: