Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Assignment, please help me figure it out ? It is ok to just give me some sam

ID: 3823797 • Letter: C

Question

C++ Assignment, please help me figure it out ? It is ok to just give me some sample code, not complete assignment code.

Thank you!

zombieCities.txt

cities,Atlanta,Boston,Boulder,Cheyenne,Chicago,Cleveland,Disneyland,Key West,Miami,New Orleans,New York,Portland,San Francisco,Seattle,Yakima
Atlanta,0,-1,-1,-1,-1,-1,-1,-1,663,487,-1,-1,-1,-1,-1
Boston,-1,0,-1,-1,982,640,-1,-1,-1,-1,215,-1,-1,-1,-1
Boulder,-1,-1,0,-1,1130,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
Cheyenne,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,1162,-1,-1,1095
Chicago,-1,982,1130,-1,0,344,-1,-1,-1,-1,-1,-1,-1,-1,-1
Cleveland,-1,640,-1,-1,344,0,-1,-1,-1,-1,-1,-1,-1,-1,-1
Disneyland,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,989,408,-1,-1
Key West,-1,-1,-1,-1,-1,-1,-1,0,159,-1,-1,-1,-1,-1,-1
Miami,663,-1,-1,-1,-1,-1,-1,159,0,864,-1,-1,-1,-1,-1
New Orleans,487,-1,-1,-1,-1,-1,-1,-1,864,0,-1,-1,-1,-1,-1
New York,-1,215,-1,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,-1
Portland,-1,-1,-1,1162,-1,-1,989,-1,-1,-1,-1,0,635,173,185
San Francisco,-1,-1,-1,-1,-1,-1,408,-1,-1,-1,-1,635,0,-1,-1
Seattle,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,173,-1,0,142
Yakima,-1,-1,-1,1095,-1,-1,-1,-1,-1,-1,-1,185,-1,142,0

Graph.h

Chicago Boulder Boston 2000 982 Boston 2000 Boulder -1 Chicago 982 would generate this graph: Boulder Boston Chicago

Explanation / Answer

C+ Program that read cities from file and build 2d array for graph :-

#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
using namespace std;
int check_path(int,int,int);
int path[20][20]={{0}};
int main()
{
int nodes=0,i,j,sourse,dest,s,d;
string city[20];
ifstream inFile("city_names.txt"); //file contains city names.
if (inFile.is_open())
{
string word;
while (getline(inFile,word))
{
  
city[nodes++]=word; //build array with city names

}
}
else
{
cout << "Can't open file." << endl;
}
ifstream gFile("city_graph.txt"); /a file contain connection between cities.
if (gFile.is_open())
{
string word,word1,word2,str,split[3];
while (getline(gFile,word))
{

int k=0;
istringstream iss(word);
while(iss >> str)
{
split[k]=str; //divide two cities in a line into an array.

k++;
}
word1=split[0];
word2=split[1];
for(i=0;i<nodes;i++)
{
if(word1==city[i])
{
for(j=0;j<nodes;j++)
{
if(word2==city[j])
{
path[i][j]=1; //path become 1 if want distance you can update code here.
break;
}

}
break;
}
}
split[0]=" ";split[1]=" ";

}
for(i=0;i<nodes;i++)
{
for(j=0;j<nodes;j++)
{
cout<<path[i][j]<<" "; //prints 2d array for the cities graph.
}
cout<<endl;
}
}
else
{
cout << "Can't open file." << endl;
}

}

citynames.txt

Bangkok
London
Paris
Dubai
NewYork
Singapore
KualaLumpur
Istanbul
Tokyo

city_graph.txt

Bangkok   Istanbul
London       NewYork  
Paris       NewYork
Dubai       Tokyo
NewYork   Singapore  
Singapore Dubai  
KualaLumpur  
Istanbul  
Tokyo Paris

OUTPUT:-

0 0 0 0 0 0 0 1 0
0 0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 1
0 0 0 0 0 1 0 0 0
0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0

One idicates there is a path exist, 0 idicates no path