Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. void ZainoF::Stampa_Soluzione_ZainoF()
  2. {
  3.     ofstream file_dati;
  4.     file_dati.open("file.txt",ios::out| ios::app);
  5.     if(!file_dati)
  6.         {cout<<"Errore apertura file."<<endl;exit(1);}
  7.     file_dati.seekp(0,ios::end);
  8.     file_dati<<endl<<"Soluzione Zaino Frazionario (tecnica greedy):"<<endl;
  9.  
  10.     cout<<"Oggetti presi: "<<endl;
  11.     int k=0;
  12.     while(*(frazione+k)!=0 && k<ogg->size())
  13.         {
  14.             if(*(frazione+k)==1)
  15.             {
  16.                 cout<<"- "<<(ogg->at(k)).get_nome()<<"\tPeso: "<<(ogg->at(k)).get_peso()<<"\tValore: "<<(ogg->at(k)).get_valore()<<endl;
  17.                 file_dati<<(ogg->at(k)).get_nome()<<" "<<(ogg->at(k)).get_peso()<<" "<<(ogg->at(k)).get_valore()<<endl;
  18.                 k=k+1;
  19.             }
  20.             else//oggetto frazionato
  21.             {
  22.                 cout<<"- "<<(ogg->at(k)).get_nome()<<"\tPeso: "<<(ogg->at(k)).get_peso()*(*(frazione+k))<<"\tValore: "<<(ogg->at(k)).get_valore()*(*(frazione+k))<<endl;
  23.                 file_dati<<(ogg->at(k)).get_nome()<<" "<<(ogg->at(k)).get_peso()*(*(frazione+k))<<" "<<(ogg->at(k)).get_valore()*(*(frazione+k))<<endl;
  24.                 k=k+1;
  25.             }
  26.         }
  27.     cout<<"Valore totale: "<<valore_tot<<endl;
  28.     file_dati<<"Valore totale: "<<valore_tot<<endl;
  29.     file_dati<<"Capienza rimanente: "<<capienza<<endl;
  30.     file_dati.close();
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement