#include "Factory.h" #include #include #include "Book.h" #include "Volume.h" Text * Factory::create() { cout << "0) exit" << endl << "1) Book" << endl << "2) Volume" << endl; int c; cin >> c; cin.ignore( 256, '\n' ); switch ( c ) { case 1 : return createBook(); case 2 : return createVolume(); 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 ); } void Factory::fill( vector & v ) { Text * t; do { t = create(); if ( t != 0 ) v.push_back( t ); } while ( t != 0 ); }