Combine class design, polymorphism, and generics-style type hints in one practical program.
Write a program that:
- Defines a polymorphic
Shapehierarchy (Circle,Rectangle). - Stores shapes in a list of base-class references.
- Calculates each shape area and total area.
- Uses a generic helper to print any numeric list.
- Prints min and max area values.
- Difficulty: Intermediate.
- Estimated Time: 45-60 minutes.
- Prerequisites: All
03-advancedmodules, especiallystructs-and-classes,inheritance-and-polymorphism, andtemplates-basics. - Learning Focus: Prove you can model abstractions, use reusable helpers, and summarize derived values correctly.
python main.pyShape areas:
- Circle: ...
- Rectangle: ...
Total area: ...
Minimum area: ...
Maximum area: ...
Sample counts: [...]
Computed areas: [...]
- Compared with the C++ assessment, this version preserves the same abstraction goal with much lighter syntax and weaker compile-time enforcement.
- Relative to C#, Go, and TypeScript, the shared contract is carried more by design intent than by the type system.
- The comparison to watch is expressive modeling versus static guarantees.
- abstraction or polymorphism is exercised through the language-appropriate shared interface
- derived numeric summaries come from computed values rather than hardcoded text
- the reusable helper works across more than one compatible input shape