Question
C Program Code: #include // 1) constant size of 10 #define SIZE 10 // 2) MetroStation struct typedef struct MetroStation { char name[20]; double x;
C Program
Code:
#include
// 1) constant size of 10 #define SIZE 10
// 2) MetroStation struct typedef struct MetroStation { char name[20]; double x; double y; } MetroStation;
// 3) MetroLine struct typedef struct MetroLine { char color[20]; MetroStation MetroStations[SIZE]; } MetroLine;
// 4) MetroSystem struct typedef struct MetroSystem { char name[20]; MetroLine MetroLines[SIZE]; } MetroSystem;
int main() { return 0; }
Please add these functions to the code.
Please implement the following functions:
1) Write a function equals (MetroStation sl, MetroStation s2) which returns a non-zero value if the name property of the MetroStation sl is equal to the name property of MetroStation s2; zero otherwise.
2) Write a function addstation which takes two inputs, a MetroLine* and a MetroStation; and adds the given metro station to the end of the MetroStations[] array pointed by the MetroLine* pointer. It should return void. 3) Write a function hasStation which takes two inputs, a MetroLine and a MetroStation and returns a non-zero value if the given metro line has a metro station with the same name as the given metro station; zero otherwise.
4) Write a function getFirststop which takes input as a MetroLine and returns the MetroStation representing the first stop of the given metro line. If there is no such station, your function should return an empty MetroStation.
5) Write a function getPreviousStop which takes two inputs, a MetroLine and a MetroStation and returns the previous MetroStation to the MetroStation passed as input. If the given station is the first stop on the MetroLine, then this function should return an empty MetroStation. You may assume that there are no "loops" in the MetroLine that is, no station is present on the same line twice.
6) Write a function getNextStop which takes two inputs, a MetroLine and a MetroStation and returns the MetroStation after the MetroStation passed as input. If the given station is the last stop on the MetroLine, then this function should return an empty MetroStation.
7) Write a function addLine which takes two inputs, a MetroSystem* and a MetroLine and adds the given metro line to the end of the MetroLines [] array pointed by MetroSystem pointer. The function should return void.
8) Write a function printLine which takes input as a MetroLine and prints the metro stations of the given metro line. The function should return void.
9) Write a function printPath which takes input as a MetroStations[] array and prints the metro stations in the given array. The function should return void. 10) Write a function getDistanceTravelled which takes input as a MetroStation[] array as path, and returns a double value representing the total distance travelled along a path that goes from the first MetroStation in the array, to the second MetroStation and so on, until the end of the array. For each MetroStation along the journey, it should calculate the distance between the MetroStation and the previous one. If the array path contains less than 2 values, your function should return 0.0. You may assume that the variable path is not null. For example, if the array path contains five MetroStation your code should calculate the sum of the distance between the first and second stations, the second and third stations, the third and fourth, and lastly the fourth and final stations. (Hint: The distance between two metro stations should be calculated using x and y coordinates of the metro stations. You should know how to calculate the distance between two points in 2D space.)
11) Write a function findNearestStation which takes three inputs as a MetroSystem, double x and a double y, and returns the MetroStation which is nearest to the x and y. To do this, it should look through all the MetroStations of all the MetroLines inside of the given MetroSystem and find the MetroStation that has the smallest distance away. You may assume that there is at least one MetroLine defined in the MetroSystem and every MetroLine has at least one MetroStation in it. (Hint: You can use the getFirstStop() and getNextStop() functions to access every entry of a MetroLine.)
12) Write a function getNeighboringstations which takes three inputs as MetroSystem, a MetroStation and a MetroStation[] array named as neigboringStations, and fills the given neigboringStations array containing all neighboring stations to the given station (possibly many if the station is on many lines). For example, if a station is the 3rd stop on the blue line, the 6th stop on the red line, and the 15 stop on the green line, then the function should update the neigboringStations containing the MetroStation that is the 2nd stop on the blue line, the 4th stop on the blue line, the 5th stop on the red line, the 7th stop on the red line, and the 2nd stop on the green line. Remember that a MetroStation will not necessarily be on every MetroLine. However, you may assume that the MetroStation is on at least one MetroLine.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started