«On Point Second Edition»

By Franz Ostendorff on Mar 08, 2024

«On Point Second Edition» — це серія навчальних матеріалів, випущених видавництвом Compass, ретельно розроблених для тих, хто вивчає англійську мову на рівнях вищого середнього та просунутого. Він складно розроблений, щоб задовольнити студентів, які прагнуть досягти CEFR (Загальноєвропейські рамки володіння мовами) рівнів від C1 до C1+.

#include <iostream>

// Base class for geometric shapes
class Shape {
public:
    // Virtual function to calculate area
    virtual double calculateArea() const = 0;

    // Virtual function to display information about the shape
    virtual void displayInfo() const = 0;
};

// Derived class representing a rectangle
class Rectangle : public Shape {
private:
    double length;
    double width;

public:
    // Constructor
    Rectangle(double l, double w) : length(l), width(w) {}

    // Implementation of the virtual function to calculate area
    double calculateArea() const override {
        return length * width;
    }

    // Implementation of the virtual function to display information
    void displayInfo() const override {
        std::cout << "Rectangle - Length: " << length << ", Width: " << width << std::endl;
    }
};

// Derived class representing a circle
class Circle : public Shape {
private:
    double radius;

public:
    // Constructor
    Circle(double r) : radius(r) {}

    // Implementation of the virtual function to calculate area
    double calculateArea() const override {
        return 3.14159 * radius * radius;
    }

    // Implementation of the virtual function to display information
    void displayInfo() const override {
        std::cout << "Circle - Radius: " << radius << std::endl;
    }
};

int main() {
    // Create instances of geometric shapes
    Rectangle rectangle(5.0, 3.0);
    Circle circle(2.5);

    // Display information and calculate areas
    rectangle.displayInfo();
    std::cout << "Area: " << rectangle.calculateArea() << std::endl;

    circle.displayInfo();
    std::cout << "Area: " << circle.calculateArea() << std::endl;

    return 0;
}

Comments

Sign in to comment.
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.