#include "Factory.h" #include #include #include "Book.h" #include "Volume.h" #include "Series.h" Text * Factory::create() { cout << "0) exit" << endl << "1) Book" << endl << "2) Volume" << endl << "3) Series" << endl; int c; cin >> c; cin.ignore( 256, '\n' ); switch ( c ) { case 1 : return createBook(); case 2 : return createVolume(); case 3 : return createSeries(); default : return 0; } } Text * Factory::createBook() { char str[ 100 ]; cout << "author: "; cin.getline( str, 100, '\n'); string author( str ); cout << "title: "; cin.getline( str, 100, '\n'); string title( str ); return new Book( author, title ); } Text * Factory::createVolume() { char str[ 100 ]; cout << "author: "; cin.getline( str, 100, '\n'); string author( str ); cout << "title: "; cin.getline( str, 100, '\n'); string title( str ); cout << "number: "; int n; cin >> n; cin.ignore( 256, '\n' ); return new Volume( author, title, n ); } Text * Factory::createSeries() { Series * s = new Series; cout << "inserisci elementi collana" << endl; Text * t; do { t = create(); if ( t != 0 ) s->add( t ); } while ( t != 0 ); cout << "inserimento collana completato" << endl; return s; } void Factory::fill( vector & v ) { Text * t; do { t = create(); if ( t != 0 ) v.push_back( t ); } while ( t != 0 ); }