Advertisement
darkjessy94

bozza

Feb 2nd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. class Zaino01
  7. {
  8. private:
  9. string *nomi_oggetti;
  10. int n_oggetti;
  11. int *peso;
  12. int *valore;
  13. int Capacita_Zaino;
  14. public:
  15. Zaino()
  16. {
  17. lettura_dati();
  18.  
  19. };
  20.  
  21. //~Zaino(){;};
  22.  
  23. void lettura_dati()
  24. {
  25. ifstream file_dati;
  26. file_dati.open("zaino.txt",ios::in);
  27. if(!file_dati)
  28. cout<<"Errore apertura file."<<endl;
  29. file_dati>>n_oggetti;
  30. cout<<n_oggetti<<endl;
  31.  
  32. peso = new int[n_oggetti];
  33. valore = new int[n_oggetti];
  34. nomi_oggetti = new string[n_oggetti];
  35. for(int i=0;i<n_oggetti;i++)
  36. {
  37. file_dati>> *(nomi_oggetti+i);
  38. file_dati>> *(peso+i);
  39. file_dati>> *(valore+i);
  40. }
  41. for(int i=0;i<n_oggetti;i++)
  42. {
  43. cout<<" "<< *(nomi_oggetti+i);
  44. cout<<" "<< *(peso+i);
  45. cout<<" "<< *(valore+i)<<endl;
  46. }
  47. file_dati.close();
  48. }
  49.  
  50.  
  51.  
  52. };
  53.  
  54. int main()
  55. {
  56. Zaino01 *ogg = new Zaino01();
  57. ogg->lettura_dati();
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement