Sie sind auf Seite 1von 4

#include <iostream> #include <conio.

h> #include <cstdlib> #include <string> #include <fstream> using namespace std; void swap_Place(int& v1, int& v2); void swap_name (string& n1, string& n2); void TOTAL_Place(string Name[], int b[]); // output of total Place void DIRECTION_Place(string x[], int y[], int z[][4]); // output of Places and directions to the different Distancess from ECC void DIRECTION_SIDE(string x[], int y[], int z[][4]); // output of Places and side like north, south, east, west from ECC

int main() { int Distances[11][4], Place[11]; string Name[11]; //defining array size for given data ifstream ECCFile; ECCFile.open("ECC.txt"); //open file for(int n=0; n<11; n++) { ECCFile >> Name[n] >> Distances[n][0]>> Distances[n][1] >>Distances[n][2] >>Distances[n][3]; //get distance from each line from ECC.txt Place[n]= Distances[n][0]+ Distances[n][1] +Distances[n][2] +Distances[n][3]; //calculate total distance for each place

for(int x=0; x<n; x++) { for(int y=x+1; y<=n; y++) { if (Place[y] < Place[x]) { //swaping values for table view swap_Place(Place[y], Place[x]);// this will sort out name of total of destination swap_name(Name[y], Name[x]); // this will sort out name of destination // next for method will sort out distance from ecc swap_Place(Distances[y][0],Distances[x][0]); swap_Place(Distances[y][1],Distances[x][1]); swap_Place(Distances[y][2],Distances[x][2]); swap_Place(Distances[y][3],Distances[x][3]); } } } } // to get out in file TOTAL_Place ( Name, Place); DIRECTION_Place ( Name, Place , Distances); DIRECTION_SIDE ( Name, Place , Distances); ECCFile.close();//file closed

return 0; } // this will swap total of destination by ascending order void swap_Place(int& v1, int& v2 ) { int temp; temp = v1; v1 = v2; v2 = temp; } // this will swap name of destinace by total od destination void swap_name (string& n1, string& n2) { string temp; temp = n1; n1 = n2; n2 = temp; }

// using a scale of 5:1 character-line representing the total distances to the different locations from ECC void TOTAL_Place(string Name[], int b[]) { ofstream TOTAL_Place; TOTAL_Place.open("619279_TOTAL_PlaceDistance.xls"); //open file TOTAL_Place << "Distances TOTAL Dist. CHARACTER LINE REPRESENTATION" << endl; //displaying table for character line representation into file for (int n=0; n<11; n++) { TOTAL_Place << Name[n] <<"\t \t" << b[n] << "\t \t"; // dived total by 5 to get 5:1 character-line for (int y=0; y <b[n]/5;y++) { TOTAL_Place<<"*"; } TOTAL_Place<<"\n"; } TOTAL_Place.close(); //close file }

// Here using a scale of 5:1 character-line representing the distances and directions //to the different locations from ECC is ascending order or total distance void DIRECTION_Place(string x[], int y[], int z[][4]) { ofstream DIRECTION_Place; DIRECTION_Place.open("619279_DIRECTION_Place.xls"); //open file //displaying direction in table in file DIRECTION_Place << "Distances"<<"\t"<<"TOTAL"<<"\t"<<"NORTH"<<"\t"<<"EAST"<<"\t"<<"SOUTH"<<"\t"<<"WEST"<<"\t "<< endl;

for(int n=1; n<11; n++) { DIRECTION_Place <<"\n"<< x[n] <<"\t " << y[n] <<"\t"; // displaying name of location and distance of each side ... if (z[n][0] == 0) // for north side distance { DIRECTION_Place<<"0"; } else { for (int y=0; y < (z[n][0]/5); y++) { DIRECTION_Place<<"*"; } } DIRECTION_Place<<"\t";// for new column if (z[n][1] == 0) // for East side distance { DIRECTION_Place<<"0"; // output 0 if north == 0 } else { for (int y=0; y < (z[n][1]/5); y++) { DIRECTION_Place<<"*"; } }DIRECTION_Place<<"\t";// for new column if (z[n][2] == 0) // for South side distance { DIRECTION_Place<<"0"; } else { for (int y=0;y <z[n][2]/5;y++) { DIRECTION_Place<<"*"; } }DIRECTION_Place<<"\t"; // for new column if (z[n][3] == 0) // for West side distance { DIRECTION_Place<<"0"; } else { for (int y=0; y < z[n][3]/5; y++) { DIRECTION_Place<<"*"; } }DIRECTION_Place<<"\t";// for new column DIRECTION_Place<<endl; } DIRECTION_Place.close(); //close file }

// file the total distance and direction of the locations from ECC void DIRECTION_SIDE(string x[], int y[], int z[][4]) { ofstream DIRECTION_SIDE; DIRECTION_SIDE.open("619279_DIRECTION_SIDE.xls"); //displaying direction side table DIRECTION_SIDE << "OCATIONS \tTOTAL dist. \tDirection from ECC" << endl; //calculate direction path/side for(int n=1; n<11; n++) { DIRECTION_SIDE << x[n] <<"\t\t" << y[n] <<"\t"; if(z[n][0]!=0 && z[n][1]== 0 &&z[n][2]==0 &&z[n][3]==0) DIRECTION_SIDE << "\tNORTH OR N"<< endl; if(z[n][0] == 0 && z[n][1]!=0 &&z[n][2]==0 &&z[n][3]==0) DIRECTION_SIDE << "\tEAST OR E"<< endl; if(z[n][0] == 0 && z[n][1]==0 &&z[n][2]!=0 &&z[n][3]==0) DIRECTION_SIDE << "\tSOUTH OR S"<< endl; if(z[n][0] == 0 && z[n][1]==0 &&z[n][2]==0 &&z[n][3]!=0) DIRECTION_SIDE << "\tWEST OR W"<< endl; if(z[n][0]!= 0 && z[n][1]==0 &&z[n][2]==0 &&z[n][3]!=0) DIRECTION_SIDE << "\tNORTHWEST OR NW"<< endl; if(z[n][0]!= 0 && z[n][1]!=0 && z[n][2]==0 && z[n][3]==0) DIRECTION_SIDE << "\tNORTHEAST OR NE"<< endl; if(z[n][0]!= 0 && z[n][1]==0 && z[n][2]!=0 && z[n][3]==0) DIRECTION_SIDE << "\tNORTHSOUTH OR NS"<< endl; if(z[n][0] == 0 && z[n][1]!=0 &&z[n][2]!=0 &&z[n][3]==0) DIRECTION_SIDE << "\tSOUTHEAST OR SE"<< endl; if(z[n][0] == 0 && z[n][1]==0 &&z[n][2]!=0 &&z[n][3]!=0) DIRECTION_SIDE << "\tSOUTHWEST OR SW"<< endl; } DIRECTION_SIDE.close(); }

Das könnte Ihnen auch gefallen