Guest User

Untitled

a guest
Aug 21st, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <fstream>
  4. #include <string>
  5. #define file_abb "Abbonamenti.dat"
  6. #define file_vip "Vip.dat"
  7. #define NUM_ABB 3
  8. #define NUM_VIP 3
  9. using namespace std;
  10.  
  11.  
  12. struct dati_a{
  13. string cognome;
  14. string nome;
  15. string citta;
  16. string indirizzo;
  17. float prezzo;
  18. };
  19.  
  20. class Abbonamento{
  21. private:
  22. int idAbbon;
  23. struct dati_a datas;
  24. public:
  25. Abbonamento(){
  26. this->datas.nome=this->datas.cognome=this->datas.indirizzo=this->datas.citta="##";
  27. this->datas.prezzo=0.0;
  28. this->idAbbon=-1;
  29. }
  30. Abbonamento(const struct dati_a x,const int id){
  31. this->datas=x;
  32. this->idAbbon=id;
  33. }
  34. ~Abbonamento(){
  35. }
  36. void get(struct dati_a& x,int& id) const{
  37. x=this->datas;
  38. id=this->idAbbon;
  39. }
  40. void set(struct dati_a x,int id){
  41. this->datas=x;
  42. this->idAbbon=id;
  43. }
  44.  
  45. /*funzione ausiliaria per stampare */
  46. void stampa(){
  47. cout<<"ID: "<<this->idAbbon<<"\n"
  48. <<"Nome: "<<this->datas.nome<<"\n"
  49. <<"Cognome: "<<this->datas.cognome<<"\n"
  50. <<"Citta: "<<this->datas.citta<<"\n"
  51. <<"Indirizzo: "<<this->datas.indirizzo<<"\n"
  52. <<"Prezzo: "<<this->datas.prezzo<<"\n"
  53. <<endl;
  54. }
  55. };
  56.  
  57. class Abbonamento_Vip : public Abbonamento{
  58. private:
  59. int id_poltrona_sup;
  60. public:
  61. Abbonamento_Vip() : Abbonamento(){
  62. this->id_poltrona_sup=-1;
  63. }
  64. Abbonamento_Vip(const struct dati_a x,const int id,const int id_sup) : Abbonamento(x,id){
  65. this->id_poltrona_sup = id_sup;
  66. }
  67. void get(struct dati_a& x,int& id,int& idsup) const{
  68. this->Abbonamento::get(x,id);
  69. idsup=this->id_poltrona_sup;
  70. }
  71. void set(struct dati_a x,int id,int idsup){
  72. this->Abbonamento::set(x,id);
  73. this->id_poltrona_sup=idsup;
  74. }
  75. ~Abbonamento_Vip(){}
  76. };
  77.  
  78. void carica(void);
  79. template <class T> T request(string question);
  80. void visualizza();
  81.  
  82. int main(){
  83.  
  84.  
  85. carica();
  86. visualizza();
  87. getch();
  88. return 0;
  89. }
  90.  
  91. void visualizza(){
  92. Abbonamento abb;
  93. fstream f;
  94. f.open(file_abb,ios::in | ios::binary);
  95. while(f.read((char*)& abb,sizeof(class Abbonamento)) && f.eof()==false){
  96. abb.stampa();
  97. }
  98. f.close();
  99.  
  100. return;
  101. }
  102.  
  103. void carica(){
  104.  
  105. struct dati_a vals;
  106. Abbonamento abb;
  107. fstream f;
  108. cout<<"INSERIMENTO ABBONATI\n"<<endl;
  109. for(int i=0;i<=NUM_ABB-1;i++){
  110. cout<<"ID: "<<i+1<<"\n";
  111. vals.nome=request<string>("\tNome");
  112. vals.cognome=request<string>("\tCognome");
  113. vals.citta=request<string>("\tCitta");
  114. vals.indirizzo=request<string>("\tIndirizzo");
  115. vals.prezzo=request<float>("\tPrezzo");
  116.  
  117. abb.set(vals,i+1);
  118.  
  119. f.open(file_abb,ios::in|ios::out|ios::binary);
  120. if(!f){
  121. cout<<"Errore nel file.\n";
  122. return;
  123. }
  124. f.seekp(i*sizeof(class Abbonamento),ios::beg);
  125. f.write((char*)& abb,sizeof(class Abbonamento));
  126. f.close();
  127. }
  128.  
  129. }
  130.  
  131.  
  132.  
  133. template <class T> T request(string question){
  134. T answ;
  135. cout<<question<<": ";
  136. cin>>answ;
  137. return answ;
  138. }
Advertisement
Add Comment
Please, Sign In to add comment