/*************************************************************************** * Copyright (C) 2006 by Gabriele Di Stefano * * gabriele@localhost.localdomain * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifdef HAVE_CONFIG_H #include #endif #include #include using namespace std; // Semplice rubrica #include #include #include #include using namespace std; class Coppia { public: Coppia(string n, int m){ nome = n; numero = m; } string getNome() {return nome;} int getNumero() {return numero;} private: string nome; int numero; //il tipo int non e' sufficiente per un numero telefonico!! }; list rubrica; //la rubrica e' una lista int main () { ifstream input("rubrica.txt", ios::in); string nom; int num; while (!input.eof() && !input.fail()) { //carica la rubrica dal file input >> nom >> num; Coppia dati(nom,num); rubrica.push_back(dati); } input.close(); int ris; do { cout << "-------------------------------\n" << "1) stampa rubrica\n" << "2) inserisci nuovo elemento\n" << "3) salva ed esci\n" << "-------------------------------\n" << "scelta:"; cin>> ris; switch (ris){ case 1: for (list::iterator i= rubrica.begin(); i!= rubrica.end(); ++i) cout <<"nome: "<< i->getNome() <<" numero: "<< i->getNumero()<<"\n"; break; case 2: cout<<"nome : "; cin >> nom; cout<<"numero :"; cin >> num; rubrica.push_back(Coppia(nom,num)); } } while (ris != 3); ofstream output("rubrica.txt", ios::out); for (list::iterator i= rubrica.begin(); i!= rubrica.end(); ++i) output << i->getNome()<<" " << i->getNumero(); output.close(); return 0; }