Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<cstring>
- #include<cstdlib>
- using namespace std;
- typedef char stringa[20];
- struct struttura{ stringa nome;
- stringa mese;
- int temp;
- };
- typedef int vett[30];
- const int dimfile=20;
- typedef struttura vett_temperature[50];
- int leggi_dati(int &k,stringa nome_file,int dimfile, vett_temperature v,stringa nome,stringa mese,int temp){
- fstream miofile;
- int i;
- cout<<"Inserire il nome del file di testo da importare : ";
- cin.getline(nome_file,dimfile-1,'\n');
- miofile.open(nome_file,ios::in);
- k=0;
- i=0;
- while(!miofile.eof()){
- miofile>>v[i].nome;
- miofile>>v[i].mese;
- miofile>>v[i].temp;
- i++;
- k++;}
- return k;
- }
- float calcola_media_temp( float &media_temp,int &h,vett_temperature v,stringa nome_city,float &somma_temp,int temp,stringa mese,stringa nome){
- int i;
- h=0;
- somma_temp=0;
- fstream miofile;
- int k;
- bool trovato;
- while(k>0){
- if(strcmp(nome_city,v[i].nome)==0){
- somma_temp=somma_temp+v[i].temp;
- cout<<somma_temp;
- h++;}
- k--;}
- return media_temp;
- }
- void calc_temp_maggiori( vett_temperature v,int riemp,int temp,vett temp_magg,float media_temp,int&i){
- int j;
- fstream miofile;
- i=0;
- while(!miofile.eof()){
- if(v[i].temp>media_temp){
- temp_magg[j]=v[i].temp;
- i++;
- j++;}}
- }
- int main(){
- int i,riemp,dimfile,temp,j,h,k;
- float media_temp,somma_temp,media;
- vett temp_magg;
- vett_temperature v;
- fstream miofile;
- stringa nome_file,nome,mese,nome_city;
- riemp=leggi_dati(k,nome_file,dimfile,v,nome,mese,temp);
- for(i=0;i<riemp;i++){
- cout<<v[i].nome<<" ";
- cout<<v[i].mese<<" ";
- cout<<v[i].temp<<" ";
- cout<<"\n";}
- cout<<"Inserisci il nome di una citta' :";
- cin>>nome_city;
- calcola_media_temp(media_temp,h,v,nome_city,somma_temp,temp,mese,nome);
- media_temp=(somma_temp)/h;
- cout<<"\nLa somma e' :"<<somma_temp;
- cout<<"\nLa media e' : "<<media_temp;
- calc_temp_maggiori(v,riemp,temp,temp_magg,media_temp,i);
- for(j=0;j<i;j++);
- cout<<temp_magg[j];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement