Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <fstream>
- #include <string>
- #define file_abb "Abbonamenti.dat"
- #define file_vip "Vip.dat"
- #define NUM_ABB 3
- #define NUM_VIP 3
- using namespace std;
- struct dati_a{
- string cognome;
- string nome;
- string citta;
- string indirizzo;
- float prezzo;
- };
- class Abbonamento{
- private:
- int idAbbon;
- struct dati_a datas;
- public:
- Abbonamento(){
- this->datas.nome=this->datas.cognome=this->datas.indirizzo=this->datas.citta="##";
- this->datas.prezzo=0.0;
- this->idAbbon=-1;
- }
- Abbonamento(const struct dati_a x,const int id){
- this->datas=x;
- this->idAbbon=id;
- }
- ~Abbonamento(){
- }
- void get(struct dati_a& x,int& id) const{
- x=this->datas;
- id=this->idAbbon;
- }
- void set(struct dati_a x,int id){
- this->datas=x;
- this->idAbbon=id;
- }
- /*funzione ausiliaria per stampare */
- void stampa(){
- cout<<"ID: "<<this->idAbbon<<"\n"
- <<"Nome: "<<this->datas.nome<<"\n"
- <<"Cognome: "<<this->datas.cognome<<"\n"
- <<"Citta: "<<this->datas.citta<<"\n"
- <<"Indirizzo: "<<this->datas.indirizzo<<"\n"
- <<"Prezzo: "<<this->datas.prezzo<<"\n"
- <<endl;
- }
- };
- class Abbonamento_Vip : public Abbonamento{
- private:
- int id_poltrona_sup;
- public:
- Abbonamento_Vip() : Abbonamento(){
- this->id_poltrona_sup=-1;
- }
- Abbonamento_Vip(const struct dati_a x,const int id,const int id_sup) : Abbonamento(x,id){
- this->id_poltrona_sup = id_sup;
- }
- void get(struct dati_a& x,int& id,int& idsup) const{
- this->Abbonamento::get(x,id);
- idsup=this->id_poltrona_sup;
- }
- void set(struct dati_a x,int id,int idsup){
- this->Abbonamento::set(x,id);
- this->id_poltrona_sup=idsup;
- }
- ~Abbonamento_Vip(){}
- };
- void carica(void);
- template <class T> T request(string question);
- void visualizza();
- int main(){
- carica();
- visualizza();
- getch();
- return 0;
- }
- void visualizza(){
- Abbonamento abb;
- fstream f;
- f.open(file_abb,ios::in | ios::binary);
- while(f.read((char*)& abb,sizeof(class Abbonamento)) && f.eof()==false){
- abb.stampa();
- }
- f.close();
- return;
- }
- void carica(){
- struct dati_a vals;
- Abbonamento abb;
- fstream f;
- cout<<"INSERIMENTO ABBONATI\n"<<endl;
- for(int i=0;i<=NUM_ABB-1;i++){
- cout<<"ID: "<<i+1<<"\n";
- vals.nome=request<string>("\tNome");
- vals.cognome=request<string>("\tCognome");
- vals.citta=request<string>("\tCitta");
- vals.indirizzo=request<string>("\tIndirizzo");
- vals.prezzo=request<float>("\tPrezzo");
- abb.set(vals,i+1);
- f.open(file_abb,ios::in|ios::out|ios::binary);
- if(!f){
- cout<<"Errore nel file.\n";
- return;
- }
- f.seekp(i*sizeof(class Abbonamento),ios::beg);
- f.write((char*)& abb,sizeof(class Abbonamento));
- f.close();
- }
- }
- template <class T> T request(string question){
- T answ;
- cout<<question<<": ";
- cin>>answ;
- return answ;
- }
Advertisement
Add Comment
Please, Sign In to add comment