SlideShare a Scribd company logo
1 of 6
Download to read offline
/*
The code below doesnt work as its supposed to. Fix the functions so that they work as the
comments describe and dont produce compiler errors or warnings, nor valgrind errors or memory
leaks. The main function has no problems, and it cannot be changed. You can also assume that
there are no mistakes with the road points and their handling in any way. The structures are also
defined correctly, and no includes are missing. In general, the logic of the code is correct.
The program handles map data, more specifically map tiles. The program saves them in a Map
structure, that holds a location name, a MapTile linked list and the number of tiles in the array.
The MapTile structure holds the data for a single map tile, and stores the id of the map tile, the
center coordinate (a latitude-longitude pair) of the tile and the size and the zoom level for the tile.
There are six mistakes in the program, each of them clearly visible either in the compiler
errors/warnings or valgrind output. Note that there might be more than one error/warning per
mistake as a single mistake can create many problems at once.
There are two mistakes in the createMapTile function.
There is one mistake in the createMapTiles function.
There is one mistakes in the createMap function.
There is one mistake in the printTileInfo function.
There is one mistake in the freeMemory function.
*/
//--------------------------------------------------------------------------
#include
#include
#include
// MapTile structure holds the center location for the map tile,
// and its id, size and zoom
typedef struct mapTile MapTile;
/**
* brief A map tile structure that specifies a map tile with its center location,
* identifier, size and zoom level.
*
*/
struct mapTile {
double
centerLocation[2]; //!< The center location as a latitude-longitude pair
char id[15]; //!< The tile identifier as a 14 character string
double size; //!< The size of the tile
int zoom; //!< The zoom level
MapTile* next; //!< The next tile in the linked list
};
// Map structure holds the map tile data for the map location
// as a MapTile structure array, as well as the amount of map tiles
// in the array and the name of the location for the map.
typedef struct map {
MapTile* mapTiles; //!< A linked list of tiles
char* locationName; //!< The name of the map that is containing the tiles
} Map;
// Function createMapTile creates a linked list member with the given data.
/**
* brief Create a MapTile linked list member from the arguments.
*
* param tileId The tile identifier
* param zoom The zoom level of the tile
* param size The size of the tile
* param centerLocation The center location of the tile
* return A dynamically allocated and initialized MapTile object
*/
MapTile*
createMapTile(char* tileId, int zoom, double size, double centerLocation[2]) {
// Allocate memory for map tile
MapTile* tile = malloc(sizeof(MapTile));
strcpy(tile->size, size);
tile->zoom = zoom;
// Save the name
tile->id = malloc(strlen(tileId) + 1);
strcpy(tile->id, tileId);
// Save the center coordinate
tile->centerLocation[0] = centerLocation[0];
tile->centerLocation[1] = centerLocation[1];
// Set the next pointer
tile->next = NULL;
return tile;
}
// Function createMapTiles takes five parameters:
// - tileIds, an array of tile ids (strings)
// - zoom, the zoom level of map tiles
// - size, the width and height of a map tile
// - centerLocations, and array of pair of doubles
// (latitude-longitude pairs)
// - tileCount, and integer that tells how many tiles
// there are in the arrays
// The function returns a MapTile structure linked list created
// from the data given as parameters
/**
* brief Creates a linked-list of MapTiles
*
* param tileIds An array of tile identifier strings
* param zoom The zoom level of the tile
* param size The size of the tile
* param centerLocations An array of a pair of doubles (latitude-longitude pairs)
* param tileCount The number of tiles in the map
* return A dynamically allocated linked-list of map tiles, and initialized
* using the function arguments.
*/
MapTile* createMapTiles(char** tileIds,
int zoom,
double size,
double centerLocations[][2],
int tileCount) {
MapTile* tile = createMapTile(tileIds[0], zoom, size, centerLocations[0]);
MapTile* start = *tile;
// Go through all the given data and store it in the array
for(int i = 1; i < tileCount; i++) {
tile->next = createMapTile(tileIds[i], zoom, size, centerLocations[i]);
tile = tile->next;
}
return start;
}
/**
* brief Create a Map object from the function arguments.
*
* param locationName The name of the map location
* param tileIds An array tile identifier strings
* param zoom The zoom level of tiles
* param size The size of the tiles
* param centerLocations An array of a pair of doubles (latitude-longitude pairs)
* param tileCount The number of tiles in the map
* return A dynamically allocated and initialized map object
*/
Map* createMap(char* locationName,
char** tileIds,
int zoom,
double size,
double centerLocations[][2],
int tileCount) {
// Allocate memory for the Map structure
Map* map = malloc(sizeof(int*));
// Store the location name
map->locationName = malloc(strlen(locationName) + 1);
strcpy(map->locationName, locationName);
// Store the map tiles information
map->mapTiles =
createMapTiles(tileIds, zoom, size, centerLocations, tileCount);
return map;
}
/**
* brief Prints the content of a Map object
*
* details This function prints the content of a Map object in the following
* format:
*
* has the following map tiles:
* Map tile id (size , zoom ) is at (latitude, longitude).
* ...
*
* param map The map object to be printed
*/
void printTileInfo(Map* map) {
printf("%s has the following map tiles:n", map->locationName);
// Loop through the map tiles and print their info
for(MapTile current = map->mapTiles; current; current = current->next) {
printf("Map tile id %s (size %.2f, zoom %d) is at (%f, %f).n",
current->id,
current->size,
current->zoom,
current->centerLocation[0],
current->centerLocation[1]);
}
}
/**
* brief Frees the dynamically allocated memory for a map object
*
* param map The object to be freed
*/
void freeMemory(Map* map) {
for(MapTile* current = map->mapTiles; current;) {
MapTile* del = current;
current = current->next;
del = NULL;
}
free(map->locationName);
free(map);
}
/**
* brief Main function of the program
*
* return Returns 0
*/
int main() {
// Original data for map tiles:
// Ids
char* ids[] = {"17-74574-37927",
"17-74574-37928",
"17-74574-37929",
"17-74573-37927",
"17-74573-37928",
"17-74573-37929"};
// Size is always the same at the same zoom level
double size = 152.0819;
int zoom = 17;
// Tile center location, a latitude-longitude pair
double centerLocations[][2] = {{60.1859156214031, 24.8249816894531},
{60.1845500274125, 24.8249816894531},
{60.1831843766236, 24.8249816894531},
{60.1859156214031, 24.8222351074219},
{60.1845500274125, 24.8222351074219},
{60.1831843766236, 24.8222351074219}};
// Create a map structure based on the data
Map* map = createMap("Otaniemi", ids, zoom, size, centerLocations, 6);
// Print map tiles information
printTileInfo(map);
// Free the reserved memory
freeMemory(map);
return 0;
}

More Related Content

Similar to The code below doesn�t work as it�s supposed to. Fix the functi.pdf

Enterprise workflow with Apps Script
Enterprise workflow with Apps ScriptEnterprise workflow with Apps Script
Enterprise workflow with Apps Scriptccherubino
 
CountryData.cppEDIT THIS ONE#include fstream #include str.pdf
CountryData.cppEDIT THIS ONE#include fstream #include str.pdfCountryData.cppEDIT THIS ONE#include fstream #include str.pdf
CountryData.cppEDIT THIS ONE#include fstream #include str.pdfAggarwalelectronic18
 
R Spatial Analysis using SP
R Spatial Analysis using SPR Spatial Analysis using SP
R Spatial Analysis using SPtjagger
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docxAdamq0DJonese
 
Im having trouble figuring out how to code these sections for an a.pdf
Im having trouble figuring out how to code these sections for an a.pdfIm having trouble figuring out how to code these sections for an a.pdf
Im having trouble figuring out how to code these sections for an a.pdfrishteygallery
 
Opensource gis development - part 3
Opensource gis development - part 3Opensource gis development - part 3
Opensource gis development - part 3Andrea Antonello
 
Windows Phone 7 Bing Maps Control
Windows Phone 7 Bing Maps ControlWindows Phone 7 Bing Maps Control
Windows Phone 7 Bing Maps ControlChris Pendleton
 
Assignment of SOS operating systemThe file lmemman.c has one incom.pdf
Assignment of SOS operating systemThe file lmemman.c has one incom.pdfAssignment of SOS operating systemThe file lmemman.c has one incom.pdf
Assignment of SOS operating systemThe file lmemman.c has one incom.pdfsktambifortune
 
comboboxentry - glade - ruby - guide
comboboxentry - glade - ruby - guidecomboboxentry - glade - ruby - guide
comboboxentry - glade - ruby - guideArulalan T
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfcontact41
 
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory option
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory optionStar Transformation, 12c Adaptive Bitmap Pruning and In-Memory option
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory optionFranck Pachot
 
The City Bars App with Sencha Touch 2
The City Bars App with Sencha Touch 2The City Bars App with Sencha Touch 2
The City Bars App with Sencha Touch 2James Pearce
 
student start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docx
student start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docxstudent start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docx
student start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docxhanneloremccaffery
 
Introduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdfIntroduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdffeelinggifts
 
Using an Array include ltstdiohgt include ltmpih.pdf
Using an Array include ltstdiohgt include ltmpih.pdfUsing an Array include ltstdiohgt include ltmpih.pdf
Using an Array include ltstdiohgt include ltmpih.pdfgiriraj65
 
Hive : WareHousing Over hadoop
Hive :  WareHousing Over hadoopHive :  WareHousing Over hadoop
Hive : WareHousing Over hadoopChirag Ahuja
 
The Web map stack on Django
The Web map stack on DjangoThe Web map stack on Django
The Web map stack on DjangoPaul Smith
 
Aerospike Nested CDTs - Meetup Dec 2019
Aerospike Nested CDTs - Meetup Dec 2019Aerospike Nested CDTs - Meetup Dec 2019
Aerospike Nested CDTs - Meetup Dec 2019Aerospike
 

Similar to The code below doesn�t work as it�s supposed to. Fix the functi.pdf (20)

Enterprise workflow with Apps Script
Enterprise workflow with Apps ScriptEnterprise workflow with Apps Script
Enterprise workflow with Apps Script
 
CountryData.cppEDIT THIS ONE#include fstream #include str.pdf
CountryData.cppEDIT THIS ONE#include fstream #include str.pdfCountryData.cppEDIT THIS ONE#include fstream #include str.pdf
CountryData.cppEDIT THIS ONE#include fstream #include str.pdf
 
R Spatial Analysis using SP
R Spatial Analysis using SPR Spatial Analysis using SP
R Spatial Analysis using SP
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
 
Im having trouble figuring out how to code these sections for an a.pdf
Im having trouble figuring out how to code these sections for an a.pdfIm having trouble figuring out how to code these sections for an a.pdf
Im having trouble figuring out how to code these sections for an a.pdf
 
Opensource gis development - part 3
Opensource gis development - part 3Opensource gis development - part 3
Opensource gis development - part 3
 
Windows Phone 7 Bing Maps Control
Windows Phone 7 Bing Maps ControlWindows Phone 7 Bing Maps Control
Windows Phone 7 Bing Maps Control
 
Assignment of SOS operating systemThe file lmemman.c has one incom.pdf
Assignment of SOS operating systemThe file lmemman.c has one incom.pdfAssignment of SOS operating systemThe file lmemman.c has one incom.pdf
Assignment of SOS operating systemThe file lmemman.c has one incom.pdf
 
comboboxentry - glade - ruby - guide
comboboxentry - glade - ruby - guidecomboboxentry - glade - ruby - guide
comboboxentry - glade - ruby - guide
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
 
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory option
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory optionStar Transformation, 12c Adaptive Bitmap Pruning and In-Memory option
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory option
 
The City Bars App with Sencha Touch 2
The City Bars App with Sencha Touch 2The City Bars App with Sencha Touch 2
The City Bars App with Sencha Touch 2
 
student start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docx
student start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docxstudent start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docx
student start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docx
 
Introduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdfIntroduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdf
 
Using an Array include ltstdiohgt include ltmpih.pdf
Using an Array include ltstdiohgt include ltmpih.pdfUsing an Array include ltstdiohgt include ltmpih.pdf
Using an Array include ltstdiohgt include ltmpih.pdf
 
Hive : WareHousing Over hadoop
Hive :  WareHousing Over hadoopHive :  WareHousing Over hadoop
Hive : WareHousing Over hadoop
 
The Web map stack on Django
The Web map stack on DjangoThe Web map stack on Django
The Web map stack on Django
 
Embedded C - Lecture 2
Embedded C - Lecture 2Embedded C - Lecture 2
Embedded C - Lecture 2
 
Quiz using C++
Quiz using C++Quiz using C++
Quiz using C++
 
Aerospike Nested CDTs - Meetup Dec 2019
Aerospike Nested CDTs - Meetup Dec 2019Aerospike Nested CDTs - Meetup Dec 2019
Aerospike Nested CDTs - Meetup Dec 2019
 

More from INFO952279

The chemokine receptor on the surface of B cells responsible for thei.pdf
 The chemokine receptor on the surface of B cells responsible for thei.pdf The chemokine receptor on the surface of B cells responsible for thei.pdf
The chemokine receptor on the surface of B cells responsible for thei.pdfINFO952279
 
The CEC of a soil sample is 21cmolckg, so the soil can adsorb 21cmol.pdf
 The CEC of a soil sample is 21cmolckg, so the soil can adsorb 21cmol.pdf The CEC of a soil sample is 21cmolckg, so the soil can adsorb 21cmol.pdf
The CEC of a soil sample is 21cmolckg, so the soil can adsorb 21cmol.pdfINFO952279
 
The Case of Amanda Jones wehulance by of the emergency depurtince.pdf
 The Case of Amanda Jones wehulance by of the emergency depurtince.pdf The Case of Amanda Jones wehulance by of the emergency depurtince.pdf
The Case of Amanda Jones wehulance by of the emergency depurtince.pdfINFO952279
 
The capital allocation process involves the transfer of capital among.pdf
 The capital allocation process involves the transfer of capital among.pdf The capital allocation process involves the transfer of capital among.pdf
The capital allocation process involves the transfer of capital among.pdfINFO952279
 
The Blundine Deportment of Luonco Company has the following cont sivd.pdf
 The Blundine Deportment of Luonco Company has the following cont sivd.pdf The Blundine Deportment of Luonco Company has the following cont sivd.pdf
The Blundine Deportment of Luonco Company has the following cont sivd.pdfINFO952279
 
The below describes slow block to polyspermy A sperm cell membrane f.pdf
 The below describes slow block to polyspermy A sperm cell membrane f.pdf The below describes slow block to polyspermy A sperm cell membrane f.pdf
The below describes slow block to polyspermy A sperm cell membrane f.pdfINFO952279
 
The average return for large-cap domestic stock funds over three year.pdf
 The average return for large-cap domestic stock funds over three year.pdf The average return for large-cap domestic stock funds over three year.pdf
The average return for large-cap domestic stock funds over three year.pdfINFO952279
 
The applicable tax rate is 25. There are no other temporary or perma.pdf
 The applicable tax rate is 25. There are no other temporary or perma.pdf The applicable tax rate is 25. There are no other temporary or perma.pdf
The applicable tax rate is 25. There are no other temporary or perma.pdfINFO952279
 
The AV node delay occurs on the EKG during the P wave between the P w.pdf
 The AV node delay occurs on the EKG during the P wave between the P w.pdf The AV node delay occurs on the EKG during the P wave between the P w.pdf
The AV node delay occurs on the EKG during the P wave between the P w.pdfINFO952279
 
The Aggregate Supply () in the economy is the output of all the busin.pdf
 The Aggregate Supply () in the economy is the output of all the busin.pdf The Aggregate Supply () in the economy is the output of all the busin.pdf
The Aggregate Supply () in the economy is the output of all the busin.pdfINFO952279
 
The animals in temperate grassland have adaptions including Thicker t.pdf
 The animals in temperate grassland have adaptions including Thicker t.pdf The animals in temperate grassland have adaptions including Thicker t.pdf
The animals in temperate grassland have adaptions including Thicker t.pdfINFO952279
 
The application of commercial marketing technologies to the analysis,.pdf
 The application of commercial marketing technologies to the analysis,.pdf The application of commercial marketing technologies to the analysis,.pdf
The application of commercial marketing technologies to the analysis,.pdfINFO952279
 
The annotation that is used to identify the primary key attribute of .pdf
 The annotation that is used to identify the primary key attribute of .pdf The annotation that is used to identify the primary key attribute of .pdf
The annotation that is used to identify the primary key attribute of .pdfINFO952279
 
The amount of cash paid for Selling and Administrative expenses durin.pdf
 The amount of cash paid for Selling and Administrative expenses durin.pdf The amount of cash paid for Selling and Administrative expenses durin.pdf
The amount of cash paid for Selling and Administrative expenses durin.pdfINFO952279
 
The Allwardt Trust is a simple trust that correctly uses the calendar.pdf
 The Allwardt Trust is a simple trust that correctly uses the calendar.pdf The Allwardt Trust is a simple trust that correctly uses the calendar.pdf
The Allwardt Trust is a simple trust that correctly uses the calendar.pdfINFO952279
 
The allele for color blindness (c) is on the X chromosome. C is the w.pdf
 The allele for color blindness (c) is on the X chromosome. C is the w.pdf The allele for color blindness (c) is on the X chromosome. C is the w.pdf
The allele for color blindness (c) is on the X chromosome. C is the w.pdfINFO952279
 
The allele for color blindness (c) is on the X chromosome. C is the.pdf
 The allele for color blindness (c) is on the X chromosome. C is the.pdf The allele for color blindness (c) is on the X chromosome. C is the.pdf
The allele for color blindness (c) is on the X chromosome. C is the.pdfINFO952279
 
The agent, host, and environment play key roles in the spread of infe.pdf
 The agent, host, and environment play key roles in the spread of infe.pdf The agent, host, and environment play key roles in the spread of infe.pdf
The agent, host, and environment play key roles in the spread of infe.pdfINFO952279
 
The age of children in kindergarten on the first day of school is uni.pdf
 The age of children in kindergarten on the first day of school is uni.pdf The age of children in kindergarten on the first day of school is uni.pdf
The age of children in kindergarten on the first day of school is uni.pdfINFO952279
 
The age of children in kindergarten on the first day of s.pdf
 The age of children in kindergarten on the first day of s.pdf The age of children in kindergarten on the first day of s.pdf
The age of children in kindergarten on the first day of s.pdfINFO952279
 

More from INFO952279 (20)

The chemokine receptor on the surface of B cells responsible for thei.pdf
 The chemokine receptor on the surface of B cells responsible for thei.pdf The chemokine receptor on the surface of B cells responsible for thei.pdf
The chemokine receptor on the surface of B cells responsible for thei.pdf
 
The CEC of a soil sample is 21cmolckg, so the soil can adsorb 21cmol.pdf
 The CEC of a soil sample is 21cmolckg, so the soil can adsorb 21cmol.pdf The CEC of a soil sample is 21cmolckg, so the soil can adsorb 21cmol.pdf
The CEC of a soil sample is 21cmolckg, so the soil can adsorb 21cmol.pdf
 
The Case of Amanda Jones wehulance by of the emergency depurtince.pdf
 The Case of Amanda Jones wehulance by of the emergency depurtince.pdf The Case of Amanda Jones wehulance by of the emergency depurtince.pdf
The Case of Amanda Jones wehulance by of the emergency depurtince.pdf
 
The capital allocation process involves the transfer of capital among.pdf
 The capital allocation process involves the transfer of capital among.pdf The capital allocation process involves the transfer of capital among.pdf
The capital allocation process involves the transfer of capital among.pdf
 
The Blundine Deportment of Luonco Company has the following cont sivd.pdf
 The Blundine Deportment of Luonco Company has the following cont sivd.pdf The Blundine Deportment of Luonco Company has the following cont sivd.pdf
The Blundine Deportment of Luonco Company has the following cont sivd.pdf
 
The below describes slow block to polyspermy A sperm cell membrane f.pdf
 The below describes slow block to polyspermy A sperm cell membrane f.pdf The below describes slow block to polyspermy A sperm cell membrane f.pdf
The below describes slow block to polyspermy A sperm cell membrane f.pdf
 
The average return for large-cap domestic stock funds over three year.pdf
 The average return for large-cap domestic stock funds over three year.pdf The average return for large-cap domestic stock funds over three year.pdf
The average return for large-cap domestic stock funds over three year.pdf
 
The applicable tax rate is 25. There are no other temporary or perma.pdf
 The applicable tax rate is 25. There are no other temporary or perma.pdf The applicable tax rate is 25. There are no other temporary or perma.pdf
The applicable tax rate is 25. There are no other temporary or perma.pdf
 
The AV node delay occurs on the EKG during the P wave between the P w.pdf
 The AV node delay occurs on the EKG during the P wave between the P w.pdf The AV node delay occurs on the EKG during the P wave between the P w.pdf
The AV node delay occurs on the EKG during the P wave between the P w.pdf
 
The Aggregate Supply () in the economy is the output of all the busin.pdf
 The Aggregate Supply () in the economy is the output of all the busin.pdf The Aggregate Supply () in the economy is the output of all the busin.pdf
The Aggregate Supply () in the economy is the output of all the busin.pdf
 
The animals in temperate grassland have adaptions including Thicker t.pdf
 The animals in temperate grassland have adaptions including Thicker t.pdf The animals in temperate grassland have adaptions including Thicker t.pdf
The animals in temperate grassland have adaptions including Thicker t.pdf
 
The application of commercial marketing technologies to the analysis,.pdf
 The application of commercial marketing technologies to the analysis,.pdf The application of commercial marketing technologies to the analysis,.pdf
The application of commercial marketing technologies to the analysis,.pdf
 
The annotation that is used to identify the primary key attribute of .pdf
 The annotation that is used to identify the primary key attribute of .pdf The annotation that is used to identify the primary key attribute of .pdf
The annotation that is used to identify the primary key attribute of .pdf
 
The amount of cash paid for Selling and Administrative expenses durin.pdf
 The amount of cash paid for Selling and Administrative expenses durin.pdf The amount of cash paid for Selling and Administrative expenses durin.pdf
The amount of cash paid for Selling and Administrative expenses durin.pdf
 
The Allwardt Trust is a simple trust that correctly uses the calendar.pdf
 The Allwardt Trust is a simple trust that correctly uses the calendar.pdf The Allwardt Trust is a simple trust that correctly uses the calendar.pdf
The Allwardt Trust is a simple trust that correctly uses the calendar.pdf
 
The allele for color blindness (c) is on the X chromosome. C is the w.pdf
 The allele for color blindness (c) is on the X chromosome. C is the w.pdf The allele for color blindness (c) is on the X chromosome. C is the w.pdf
The allele for color blindness (c) is on the X chromosome. C is the w.pdf
 
The allele for color blindness (c) is on the X chromosome. C is the.pdf
 The allele for color blindness (c) is on the X chromosome. C is the.pdf The allele for color blindness (c) is on the X chromosome. C is the.pdf
The allele for color blindness (c) is on the X chromosome. C is the.pdf
 
The agent, host, and environment play key roles in the spread of infe.pdf
 The agent, host, and environment play key roles in the spread of infe.pdf The agent, host, and environment play key roles in the spread of infe.pdf
The agent, host, and environment play key roles in the spread of infe.pdf
 
The age of children in kindergarten on the first day of school is uni.pdf
 The age of children in kindergarten on the first day of school is uni.pdf The age of children in kindergarten on the first day of school is uni.pdf
The age of children in kindergarten on the first day of school is uni.pdf
 
The age of children in kindergarten on the first day of s.pdf
 The age of children in kindergarten on the first day of s.pdf The age of children in kindergarten on the first day of s.pdf
The age of children in kindergarten on the first day of s.pdf
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxNikitaBankoti2
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Recently uploaded (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

The code below doesn�t work as it�s supposed to. Fix the functi.pdf

  • 1. /* The code below doesnt work as its supposed to. Fix the functions so that they work as the comments describe and dont produce compiler errors or warnings, nor valgrind errors or memory leaks. The main function has no problems, and it cannot be changed. You can also assume that there are no mistakes with the road points and their handling in any way. The structures are also defined correctly, and no includes are missing. In general, the logic of the code is correct. The program handles map data, more specifically map tiles. The program saves them in a Map structure, that holds a location name, a MapTile linked list and the number of tiles in the array. The MapTile structure holds the data for a single map tile, and stores the id of the map tile, the center coordinate (a latitude-longitude pair) of the tile and the size and the zoom level for the tile. There are six mistakes in the program, each of them clearly visible either in the compiler errors/warnings or valgrind output. Note that there might be more than one error/warning per mistake as a single mistake can create many problems at once. There are two mistakes in the createMapTile function. There is one mistake in the createMapTiles function. There is one mistakes in the createMap function. There is one mistake in the printTileInfo function. There is one mistake in the freeMemory function. */ //-------------------------------------------------------------------------- #include #include #include // MapTile structure holds the center location for the map tile, // and its id, size and zoom typedef struct mapTile MapTile; /** * brief A map tile structure that specifies a map tile with its center location, * identifier, size and zoom level. * */ struct mapTile { double centerLocation[2]; //!< The center location as a latitude-longitude pair char id[15]; //!< The tile identifier as a 14 character string
  • 2. double size; //!< The size of the tile int zoom; //!< The zoom level MapTile* next; //!< The next tile in the linked list }; // Map structure holds the map tile data for the map location // as a MapTile structure array, as well as the amount of map tiles // in the array and the name of the location for the map. typedef struct map { MapTile* mapTiles; //!< A linked list of tiles char* locationName; //!< The name of the map that is containing the tiles } Map; // Function createMapTile creates a linked list member with the given data. /** * brief Create a MapTile linked list member from the arguments. * * param tileId The tile identifier * param zoom The zoom level of the tile * param size The size of the tile * param centerLocation The center location of the tile * return A dynamically allocated and initialized MapTile object */ MapTile* createMapTile(char* tileId, int zoom, double size, double centerLocation[2]) { // Allocate memory for map tile MapTile* tile = malloc(sizeof(MapTile)); strcpy(tile->size, size); tile->zoom = zoom; // Save the name tile->id = malloc(strlen(tileId) + 1); strcpy(tile->id, tileId); // Save the center coordinate tile->centerLocation[0] = centerLocation[0]; tile->centerLocation[1] = centerLocation[1]; // Set the next pointer tile->next = NULL; return tile;
  • 3. } // Function createMapTiles takes five parameters: // - tileIds, an array of tile ids (strings) // - zoom, the zoom level of map tiles // - size, the width and height of a map tile // - centerLocations, and array of pair of doubles // (latitude-longitude pairs) // - tileCount, and integer that tells how many tiles // there are in the arrays // The function returns a MapTile structure linked list created // from the data given as parameters /** * brief Creates a linked-list of MapTiles * * param tileIds An array of tile identifier strings * param zoom The zoom level of the tile * param size The size of the tile * param centerLocations An array of a pair of doubles (latitude-longitude pairs) * param tileCount The number of tiles in the map * return A dynamically allocated linked-list of map tiles, and initialized * using the function arguments. */ MapTile* createMapTiles(char** tileIds, int zoom, double size, double centerLocations[][2], int tileCount) { MapTile* tile = createMapTile(tileIds[0], zoom, size, centerLocations[0]); MapTile* start = *tile; // Go through all the given data and store it in the array for(int i = 1; i < tileCount; i++) { tile->next = createMapTile(tileIds[i], zoom, size, centerLocations[i]); tile = tile->next; } return start; }
  • 4. /** * brief Create a Map object from the function arguments. * * param locationName The name of the map location * param tileIds An array tile identifier strings * param zoom The zoom level of tiles * param size The size of the tiles * param centerLocations An array of a pair of doubles (latitude-longitude pairs) * param tileCount The number of tiles in the map * return A dynamically allocated and initialized map object */ Map* createMap(char* locationName, char** tileIds, int zoom, double size, double centerLocations[][2], int tileCount) { // Allocate memory for the Map structure Map* map = malloc(sizeof(int*)); // Store the location name map->locationName = malloc(strlen(locationName) + 1); strcpy(map->locationName, locationName); // Store the map tiles information map->mapTiles = createMapTiles(tileIds, zoom, size, centerLocations, tileCount); return map; } /** * brief Prints the content of a Map object * * details This function prints the content of a Map object in the following * format: * * has the following map tiles: * Map tile id (size , zoom ) is at (latitude, longitude). * ...
  • 5. * * param map The map object to be printed */ void printTileInfo(Map* map) { printf("%s has the following map tiles:n", map->locationName); // Loop through the map tiles and print their info for(MapTile current = map->mapTiles; current; current = current->next) { printf("Map tile id %s (size %.2f, zoom %d) is at (%f, %f).n", current->id, current->size, current->zoom, current->centerLocation[0], current->centerLocation[1]); } } /** * brief Frees the dynamically allocated memory for a map object * * param map The object to be freed */ void freeMemory(Map* map) { for(MapTile* current = map->mapTiles; current;) { MapTile* del = current; current = current->next; del = NULL; } free(map->locationName); free(map); } /** * brief Main function of the program * * return Returns 0 */ int main() { // Original data for map tiles:
  • 6. // Ids char* ids[] = {"17-74574-37927", "17-74574-37928", "17-74574-37929", "17-74573-37927", "17-74573-37928", "17-74573-37929"}; // Size is always the same at the same zoom level double size = 152.0819; int zoom = 17; // Tile center location, a latitude-longitude pair double centerLocations[][2] = {{60.1859156214031, 24.8249816894531}, {60.1845500274125, 24.8249816894531}, {60.1831843766236, 24.8249816894531}, {60.1859156214031, 24.8222351074219}, {60.1845500274125, 24.8222351074219}, {60.1831843766236, 24.8222351074219}}; // Create a map structure based on the data Map* map = createMap("Otaniemi", ids, zoom, size, centerLocations, 6); // Print map tiles information printTileInfo(map); // Free the reserved memory freeMemory(map); return 0; }