...
/Coding Challenge: Modeling Complex Objects and Relationships (1)
Coding Challenge: Modeling Complex Objects and Relationships (1)
Practice everything learned so far by building an application to handle a flower business.
Introduction
We aim to practice working with pointers, structures, and dynamic memory allocations by building a mini-project to manage a flower business.
Our business is quite the hit with flower enthusiasts, so we want to be able to expand in different continents and keep track of each continent individually.
Each continent can have multiple flower shops, depending on how many we decide to open in that continent.
Each flower shop sells only two types of flowers since they are exotic flowers and quite expensive. It is a very focused business, quality over quantity. In reality, the restriction of selling only two flowers is here to simplify our code.
Suppose you’re familiar with object-oriented programming (OOP). In that case, you may recognize that we’re defining a hierarchy using structures similar to how we would with classes in an OOP language.
Note: This lesson has two parts, which appear to be pretty long. The complete solution at the end takes the most time to read. We promise the text doesn’t take an hour to read! In fact, without the playground code widget, the lessons take around 24 minutes to read. It may take a few hours to solve all the challenges.
Lesson structure
This lesson is interactive by providing a mix of a tutorial, a follow-along session, and a coding challenge. We’ll build the project bit by bit, incrementally.
- Some functions will be provided as a tutorial.
- You will have to complete other functions and pass the test cases.
Note: Tasks marked with “demo task” are tutorial tasks. You don’t have to write any code. Make sure to understand the code. However, if you want, you can attempt to write the code on your own in any text editor or IDE and then compare it with the provided solution.
Structures
We’ll use the following structures to model the objects in our business.
Flower
We represent a flower using the TFlower
structure. It contains: ...