Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 2 . answer in c language ou are given a task to implement a hierarchical data structure rep - resenting cities, regions, countries, and

Problem 2. answer in c language ou are given a task to implement a hierarchical data structure rep-resenting cities, regions, countries, and continents. Your implementation should allow youto create instances of these entities, link them appropriately, and print specific hierarchicalinformation.The structures and relationships are as follows:EachCitybelongs to aRegion.EachRegioncontains multipleCitiesand belongs to aCountry.EachCountrycontains multipleRegionsand belongs to one or moreContinents.EachContinentcontains one or moreCountries.Here are the specific requirements:1. Define structures forCity,Region,Country, andContinent.Cityshould have the variables below:char name[50]->City nameint population->Population of the cityRegionshould have the variables below:char name[50]->Region nameint population->Total population of the cities in the regionint numcities->Number of cities that the region hasCountryshould have the variables below:char name[50]->Country nameint population->Total population of the cities in the countryint numregions->Number of regions that the country hasint numcontinents->Number of continents that the country hasContinentshould have the variables below:char name[50]>Continent nameint population->Total population of the cities in the continentint numcountries->Number of countries that the continent has2. Create instances ofCity,Region,Country, andContinentand establish their rela-tionships.Continentshould point toCountry.4
Countryshould point toContinentandRegion.Regionshould point toCountryandCity.Cityshould point toRegion.3. Populate the data:Include two continents, named Europe and Asia.Asia contains one country, Turkey.Europe contains two countries, Turkey and France.France has multiple regions, Ile-de-France and Nouvelle-Aquitaine.Turkey has multiple regions, Marmara and Ege.Paris and Yvelines (two cities in France) are in Ile-de-France, and the correspond-ing populations are 2161000 and 1437000, respectively.Bordeaux (a city in France with 249712 population) is in Nouvelle-Aquitaine.Izmir (population: 4367000) and Manisa (population: 1430000) are in Ege region,Turkey.Istanbul (population: 15460000) is in Marmara region, Turkey.4. Ensure proper memory allocation for dynamic data.5. Name the variables so that the program will be able to print the following hierarchicalinformation:1p r i n t f ( Continent : %s .
, Europe>name) ;2p r i n t f ( Population : %d .
, Europe>population ) ;3p r i n t f (Number of Countries : %d .
, Europe>numcountries ) ;4p r i n t f (
) ;56p r i n t f (Country : %s .
, Europe>country [0]. name) ;7p r i n t f ( Population : %d .
, Europe>country [0]. population ) ;8p r i n t f (Number of Regions : %d .
, Europe>country [0]. numregions ) ;9p r i n t f (Number of Continents : %d .
, Europe>country [0]. numcontinents ) ;10p r i n t f (
) ;1112p r i n t f (Country : %s .
, Europe>country [1]. name) ;13p r i n t f ( Population : %d .
, Europe>country [1]. population ) ;14p r i n t f (Number of Regions : %d .
, Europe>country [1]. numregions ) ;15p r i n t f (Number of Continents : %d .
, Europe>country [1]. numcontinents ) ;16p r i n t f (
) ;1718p r i n t f (Country : %s .
, Asia>country>name) ;19p r i n t f ( Population : %d .
, Asia>country>population ) ;20p r i n t f (Number of Regions : %d .
, Asia>country>numregions ) ;21p r i n t f (Number of Continents : %d .
, Asia>country>numcontinents ) ;22p r i n t f (
) ;2324p r i n t f (Region : %s .
, Europe>country [0]. region [0]. name) ;25p r i n t f (This region i s in %s .
, IleDeFrance>country>name) ;26p r i n t f (%s and %s are in t h i s region .
, Europe>country [0]. region [0]. city [0]. name , Europe>country [0]. region [0]. city [1]. name) ;27p r i n t f ( Population : %d .
, Europe>country [0]. region [0]. population ) ;28p r i n t f (Number of C i t i e s : %d .
, Europe>country [0]. region [0]. numcities ) ;29p r i n t f (
) ;3031p r i n t f (City : %s
, Asia>country>region [1]. city>name) ;32p r i n t f (This city i s in %s region ,%s .
, Asia>country>region [1]. name , Asia>country>name) ;33p r i n t f ( Population : %d .
, Asia>country>region [1]. city>population ) ;3435struct Citymycity = malloc ( s i z e o f ( struct City )) ;36 mycity = Asia>country>region [1]. city ;37p r i n t f ( Istanbul i s the city that bridges %s and %s .
, mycity>region>country>continent [0].name , mycity>region>country>continent [1]. name) ;38p r i n t f (
) ;3940p r i n t f (Region : %s .
, Asia>country>region [0]. name) ;5
41p r i n t f (%s and %s ar
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions