Coding Challenge: Modeling Complex Objects and Relationships (2)

Task 6: Coding challenge

Now we have all the pieces needed to open a TFlowerShop, which we’ll add to the flower shops list using the function from Task 4. We’ll initialize the two flowers using the function from Task 5.

Write a function called openFlowerShop, which will allocate, initialize, and return a pointer to a TFlowerShop structure.

The function header is:

TFlowerShop* openFlowerShop(TFlowerBusiness* flowerBusiness, int continentId, char* name, char* address, int openingYear)
  • flowerBusiness is the current business.
  • continentId is the ID of the continent where we want to open the business.
  • name, address, and openingYear are used to initialize some of the members inside the TFLowerShop.
  • The function must return NULL on failure.
  • It must also make sure to allocate and initialize all the members correctly.
  • After we allocate the flower shop, we must add it to the flower shops list of that continent. You may want to use the function from Task 4, but check its return value and guard against realloc fails.
  • What happens if this shop is the first shop in the continent? In other words, this is the first time our business opens a shop in the new continent. You may want to use the function allocContinent from Task 3.

This task is the most challenging task in the whole project. Make sure to pay special attention to it.

Get hands-on with 1200+ tech skills courses.