//Creates a simple interface that allows for the execution of multiple functions of book, patron, and library //Uses a loop to allow for consecutive operations until user quits int main(){ try{ //Only uses one library, called lib Library::Library lib; cout << "Choose Operation" << endl << "1: Create Patron" << endl << "2: Create Book" << endl << "3: Set Patron Fees" << endl << "4: Print Book Details" << endl << "5: Print Patron Details" << endl << "6: Print list of Patrons with Fees" << endl << "7: Check out a Book" << endl << "8: Print all Transactions" << endl << "Q: Quit"; //Different chars lead to different operations; loops until user inputs a char that is not 1 through 8 bool finished = false; while (!finished){ char ch; cout << endl << '>'; cin >> ch; //Clears enter from buffer so getline isn't skipped cin.ignore(numeric_limits<streamsize>::max(), '\n'); //Queries book info and adds book to library if (ch == '1') { string name, cardnumber; double fees; cout << endl << "Enter name: "; getline(cin,name); cout << "Enter card number: "; cin >> cardnumber; cout << "Enter fees: "; cin >> fees; Patron::Patron pp(name, cardnumber, fees); lib.add_patron(pp); } //Queries patron info to add to library else if (ch == '2') { string ISBN, title, author; int g; Date::Date dd; cout << endl << "Enter title: "; getline(cin,title); cout << "Enter author: "; getline(cin,author); cout << "Enter ISBN: "; cin >> ISBN; cout << "Enter genre (1 = fiction, 2 = nonfiction, 3 = periodical, " << "4 = biography, 5 = children): "; cin >> g; cout << "Enter copyright date: "; cin >> dd; Book::Book bb(ISBN, title, author, Book::Book::Genre(g), dd); lib.add_book(bb); }
int main() { try { Library::Library lib; lib.add_book("89-89-09-sq2","Three body","ci",Chrono::today(),Book::Book::fiction); lib.add_patron("qi", "123"); lib.loan_book(lib.Patrons()[0], lib.Books()[0]); } catch (...) { cout << "error" << endl; } return 0; }
void RunFileTest::TestLogic(void) { ASTNode* root; ParserAPI test; test.ParseFile(FILE_PATH); if (test.HasError()) { logger->Notice("Parsing errors for file " FILE_PATH); __list_parsing_errors(test); // Try another file logger->Notice("trying \"./sin_tun_test.sin\""); ParserAPI test0; test0.ParseFile("sin_run_test.sin"); if (test0.HasError()) { logger->Notice("Parsing errors for file ./sin_run_test.sin"); __list_parsing_errors(test0); ASSERT(!test0.HasError()); // certain failure here, to stop the test } else { logger->Notice("fallback sin_run_test.sin passed"); root = test0.GetAST(); } } else root = test.GetAST(); ASSERT(root != 0x00); FileOutputStream _foutxml("RunTreeVisualisation.xml", FileOutputStream::Mode::Truncate()); FileOutputStream _fouttxt("RunTreeVisualisation.txt", FileOutputStream::Mode::Truncate()); FileOutputStream _ctrltxt("RunTreeCtrlVisualisation.txt", FileOutputStream::Mode::Truncate()); FileOutputStream _metatxt("ShiftToMetaEvaluatorASTVisitor.txt", FileOutputStream::Mode::Truncate()); BufferedOutputStream foutxml(_foutxml); BufferedOutputStream fouttxt(_fouttxt); BufferedOutputStream ctrltxt(_ctrltxt); BufferedOutputStream metatxt(_metatxt); ASTTreeCtrlVisitor ctrlvis(ctrltxt); ASTTreeVisualisationVisitor visitor(fouttxt); //ASTTreeVisualisationVisitor metaVisualVisitor(metatxt); //ASTMITTreeVisualizerXMLProducerVisitor mitvis(foutxml); //ASTCloneVisitor cloneVisitor; //ASTUnparseTreeVisitor uparseVisitor; // root->Accept(&visitor); root->Accept(&ctrlvis); //root->Accept(&mitvis); //root->Accept(&uparseVisitor); //root->Accept(&cloneVisitor); //String unpasedString1 = uparseVisitor.UnparsedString(); //uparseVisitor.CleanUnparsedString(); //cloneVisitor.Root()->Accept(&uparseVisitor); //String unpasedString2 = uparseVisitor.UnparsedString(); // //SINASSERT(unpasedString1 == unpasedString2); // //static_cast<OutputStream&>(STDOUT) << "\n\n" << unpasedString2 << "\n\n\n"; foutxml.flush(); fouttxt.flush(); ctrltxt.flush(); //ASTNode & lastKid = static_cast<ASTNode &>(*root->rbegin()); //cloneVisitor.Resset(); //lastKid.Accept(&cloneVisitor); //uparseVisitor.CleanUnparsedString(); //ASTNode * cloneRoot = cloneVisitor.Root(); //cloneRoot->Accept(&uparseVisitor); //static_cast<OutputStream&>(STDOUT) << "\n\n" << uparseVisitor.UnparsedString() << "\n\n\n"; //cloneVisitor.DeleteListAndAST(); VM::VirtualState vs; vs.SetPrintHandler(&__print_handler); Library::Library lib; Library::Functions::print print; Library::Functions::println println; Library::Functions::arguments arguments; Library::Functions::totalarguments totalarguments; Library::Functions::tostring tostring; Library::Functions::strtonum strtonum; Library::Functions::typeof typeof; Library::Functions::fileopen fileopen; Library::Functions::fileread fileread; lib.InstallFunction(&print ); lib.InstallFunction(&println ); lib.InstallFunction(&arguments ); lib.InstallFunction(&totalarguments ); lib.InstallFunction(&tostring ); lib.InstallFunction(&strtonum ); lib.InstallFunction(&typeof ); lib.InstallFunction(&fileopen ); lib.InstallFunction(&fileread ); // TODO remove the reference here and watch it burn SymbolTable *globalSymTable = &vs.CurrentStable(); globalSymTable->Insert("print", SINEWCLASS(MemoryCellLibFunction, (&print))); globalSymTable->Insert("println", SINEWCLASS(MemoryCellLibFunction, (&println))); globalSymTable->Insert("arguments", SINEWCLASS(MemoryCellLibFunction, (&arguments))); globalSymTable->Insert("totalarguments", SINEWCLASS(MemoryCellLibFunction, (&totalarguments))); globalSymTable->Insert("tostring", SINEWCLASS(MemoryCellLibFunction, (&tostring))); globalSymTable->Insert("strtonum", SINEWCLASS(MemoryCellLibFunction, (&strtonum))); globalSymTable->Insert("typeof", SINEWCLASS(MemoryCellLibFunction, (&typeof))); globalSymTable->Insert("fileopen", SINEWCLASS(MemoryCellLibFunction, (&fileopen))); globalSymTable->Insert("fileread", SINEWCLASS(MemoryCellLibFunction, (&fileread))); TreeEvaluationVisitor eval(&lib, &vs); try { root->Accept(&eval); } catch(SIN::RunTimeError rte) { static_cast<OutputStream&>(STDOUT) << rte.CompleteMessage() << "\n"; exit(-1); } catch(...) { static_cast<OutputStream&>(STDOUT) << "Unexpected exception" << "\n"; exit(-1); } //ShiftToMetaEvaluatorASTVisitor shifter(eval); //root->Accept(&shifter); //shifter.Root()->Accept(&metaVisualVisitor); metatxt.flush(); test.DeleteListAndAST(); // shifter.DeleteListAndAST(); }