Question & Answer: In this program, you create a map and find the route from a source location to a destination location. You will use structure(s), po…..

In this program, you create a map and find the route from a source location to a destination location. You will use structure(s), pointer(s) and class(es) to accomplish this task Lets begin by looking at the following map The letters of the alphabet represent the locations. Each line represents a highway and each location has one exit highway and one entry highway. You may only leave a location through its exit highway and enter it through its entry highway. (For example The route from location A to D using this map is A>E>C B D Your code will implement this. First, you will begin by creating the map above in your code using class(cs), structure(s), pointer(s) and anything else you may want to use. Once you have the map, you will prompt the user to enter new names for the locations represented by A,B.C.D,E, above. Once you have accomplished that, you have created your map Next, you will prompt the user for the starting location and destination location. You will use the map to figure out and then display the route from the starting location to the destination location. You must keep track of how many times a location is chosen as a destination. You must, then, display the following menu and continue to do so until the user decides to exit the program: C- to enter another source & destination pair P- to see the most popular destination locations E to exit If the user enters P, you must display the locations from most popular (chosen the most number of times as destination) to least popular. If two or more locations have been chosen as the destination the same number of times, list them in alphabetical order. Please remember to place appropriate error checks (PLEASE INCLUDE THE FILES AND THE OUTPUT C++

In this program, you create a map and find the route from a source location to a destination location. You will use structure(s), pointer(s) and class(es) to accomplish this task. Let’s begin by looking at the following map: The letters of the alphabet represent the locations. Each line represents a highway and each location has one exit highway and one entry highway. You may only leave a location through its exit highway and enter it through its entry highway. (For example The route from location A to D using this map is A rightarrow E rightarrow C rightarrow B rightarrow D) Your code will implement this. First, you will begin by creating the map above in your code using class(es), structure(s), pointer(s) and anything else you may want to use. Once you have the map, you will prompt the user to enter new names for the locations represented by A, B, C, D, E, above. Once you have accomplished that, you have created your map. Next, you will prompt the user for the starting location and destination location. You will use the map to figure out and then display the route from the starting location to the destination location. You must keep track of how many times a location is chosen as a destination. You must, then, display the following menu and continue to do so until the user decides to exit the program: C- to enter another source & destination pair P- to see the most popular destination locations E to exit If the user enters P, you must display the locations from most popular (chosen the most number of times as destination) to least popular. If two or more locations have been chosen as the destination the same number of times, list them in alphabetical order. Please remember to place appropriate error checks.

Expert Answer

 

The given path is A->E->C->B->D->A.
User enters the start and end point.
I am implementing the code in Java but only the syntax for input will change else everything will be same. You must be capable of doing that much change I guess.

import java.io.*;
import java.util.*;
class solution
{
public static void main(String args[])throws IOException
{
int i,si,di;
int ar[]={0,4,2,1,3};
int ds[]={0,0,0,0,0};
Scanner sc=new Scanner(System.in);
System.out.println(“Path isnA->E->C->B->D->A”);
System.out.println(“Enter new names of locations”);
String names[]=new String[5];
for(i=0;i<5;i++)
names[i]=sc.nextLine();
System.out.println(“Path with new names :”);
System.out.println(names[0]+”->”+names[4]+”->”+names[2]+”->”+names[1]+”->”+names[3]+”->”+names[0]);
while(true)
{
System.out.println(“C-To enter new source and destination”);
System.out.println(“P-To view most popular destination”);
char ch=(sc.nextLine()).charAt(0);
if(ch==’C’)
{
System.out.println(“Enter source and destination”);
String s=sc.nextLine();
String d=sc.nextLine();
for(i=0;i<4;i++)
{
if(s.equals(names[i]))si=i;
if(d.equals(names[i]))di=i;
}
if(si<di)
for(i=si;i<=di;i++)
{
System.out.println(names[i]);
ds[i]++;
}
else
{
for(i=si;i<=4;i++)
{
System.out.println(names[i]);
ds[i]++;
}
i=0;
for(i=0;i<=di;i++)
{
System.out.println(names[i]);
ds[i]++;
}
}
}
else if(ch==’P’)
{
int mv=0;
for(i=0;i<=4;i++)
if(ds[i]>=mv)mv=i;
for(int k=i;k<=4;k++)
System.out.println(names[i]);
}
}
}
}

Still stressed from student homework?
Get quality assistance from academic writers!