Advertisement
Guest User

Untitled

a guest
Dec 7th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<cstring>
  4. #include<cstdlib>
  5. using namespace std;
  6. typedef char stringa[20];
  7. struct struttura{ stringa nome;
  8. stringa mese;
  9. int temp;
  10. };
  11. typedef int vett[30];
  12. const int dimfile=20;
  13. typedef struttura vett_temperature[50];
  14. int leggi_dati(int &k,stringa nome_file,int dimfile, vett_temperature v,stringa nome,stringa mese,int temp){
  15. fstream miofile;
  16. int i;
  17. cout<<"Inserire il nome del file di testo da importare : ";
  18. cin.getline(nome_file,dimfile-1,'\n');
  19. miofile.open(nome_file,ios::in);
  20. k=0;
  21. i=0;
  22. while(!miofile.eof()){
  23. miofile>>v[i].nome;
  24. miofile>>v[i].mese;
  25. miofile>>v[i].temp;
  26. i++;
  27. k++;}
  28. return k;
  29.  
  30.  
  31. }
  32. float calcola_media_temp( float &media_temp,int &h,vett_temperature v,stringa nome_city,float &somma_temp,int temp,stringa mese,stringa nome){
  33. int i;
  34.  
  35. h=0;
  36. somma_temp=0;
  37. fstream miofile;
  38. int k;
  39. bool trovato;
  40. while(k>0){
  41.  
  42. if(strcmp(nome_city,v[i].nome)==0){
  43. somma_temp=somma_temp+v[i].temp;
  44. cout<<somma_temp;
  45. h++;}
  46. k--;}
  47.  
  48. return media_temp;
  49. }
  50.  
  51.  
  52.  
  53. void calc_temp_maggiori( vett_temperature v,int riemp,int temp,vett temp_magg,float media_temp,int&i){
  54.  
  55. int j;
  56. fstream miofile;
  57. i=0;
  58. while(!miofile.eof()){
  59.  
  60. if(v[i].temp>media_temp){
  61.  
  62. temp_magg[j]=v[i].temp;
  63. i++;
  64. j++;}}
  65.  
  66. }
  67.  
  68.  
  69.  
  70.  
  71.  
  72. int main(){
  73. int i,riemp,dimfile,temp,j,h,k;
  74. float media_temp,somma_temp,media;
  75. vett temp_magg;
  76. vett_temperature v;
  77. fstream miofile;
  78. stringa nome_file,nome,mese,nome_city;
  79. riemp=leggi_dati(k,nome_file,dimfile,v,nome,mese,temp);
  80. for(i=0;i<riemp;i++){
  81. cout<<v[i].nome<<" ";
  82. cout<<v[i].mese<<" ";
  83. cout<<v[i].temp<<" ";
  84. cout<<"\n";}
  85. cout<<"Inserisci il nome di una citta' :";
  86. cin>>nome_city;
  87. calcola_media_temp(media_temp,h,v,nome_city,somma_temp,temp,mese,nome);
  88. media_temp=(somma_temp)/h;
  89.  
  90. cout<<"\nLa somma e' :"<<somma_temp;
  91. cout<<"\nLa media e' : "<<media_temp;
  92. calc_temp_maggiori(v,riemp,temp,temp_magg,media_temp,i);
  93. for(j=0;j<i;j++);
  94. cout<<temp_magg[j];
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement