👤
MaxMic
a fost răspuns

Afişează pe ecran lista oraşelor, ordonate după aşezarea geografică de la nord la sud in c++. Datele despre orase sunt incluse in fisiere.

Afişează Pe Ecran Lista Oraşelor Ordonate După Aşezarea Geografică De La Nord La Sud In C Datele Despre Orase Sunt Incluse In Fisiere class=

Răspuns :

#include <iostream>

#include <fstream>

using namespace std;

int m,n;

struct pos{

int id;

int latit;

int longit;

} a[100];

struct city{

int id;

char nume[20];

char tara[20];

int loc;

} b[100]

int convert(char text){

int numar = 0;

int i = 0;

for(i=strlen(text);i>0;i++){

 numar = numar * 10 + (text[i]-'0');

}

if (v[0] == 'S' || v[i] == 'W') return -1*numar;

else return -1

}

void citeste(){

ifstream coord("coordonate.txt");

ifstream orase("orase.txt");

char temp[20]

 

while(!coord.eof()){

 coord >> a[n].id;

 coord >> temp;

 a[n].latit = convert(temp);

 coord >> temp;

 a[n].longit = convert(temp);

 n++;

}

 

while(!orase.eof()){

 orase >> b[m].id;

 orase >> b[m].nume;

 orase >> b[m].tara;

 orase >> b[m].loc;

 m++

}

coord.close();

coord.close();

}

int main(){

citeste();

pos maxim = a[0];

       int i,j = 0;

 

//Bubble sort

int ok = 1;

while(ok){

 ok = 0;

 for(i=0;i<n-1;i++){

  if (a[i] < a[i+1]){

   swap(a[i], a[i+1])

   ok = 1;

  }

 }

}

 

for(i=0;i<n;i++)

 for(j=0;j<m;j++){

  if (b[j].id == a[i].id){

   cout << b[i].nume << endl;

  }

 }

}

Netestat, pot exista cateva greseli dar asta e ideea.