+/EE312
software design
git clone https://git.julia.blue/+/EE312
6241299
master
1#include <stdio.h> 2#include <string> 3#include <stdio.h> // declarations of FILE and printf 4#include <stdlib.h> // includes declaration of exit() 5#include "String.h" 6// #include "MemHeap.h" 7 8#include "CustomerDB.h" 9/* 10struct CheckMemoryLeaks { 11~CheckMemoryLeaks(void) { 12if (! isSaneHeap()) { 13printf("oh goodness! you've corrupted the heap, naughty naughty\n"); 14return; 15} 16if (! isEmptyHeap()) { 17printf("Uh Oh! you have a memory leak somewhere, better find it\n"); 18return; 19} 20printf("The heap is all clean, good work!\n"); 21} 22} MemoryChecker; 23*/ 24FILE * input_stream ; 25String inventory_cmd_name = String ("Inventory" ); 26String purchase_cmd_name = String ("Purchase" ); 27String summarize_cmd_name = String ("Summarize" ); 28String quit_cmd_name = String ("Quit" ); 29 30void readNum (int & x ) { 31int val ; 32fscanf (input_stream ,"%d" ,& val ); 33x = val ; 34} 35 36void readString (String & x ) { 37char buff [BUFSIZ ]; 38fscanf (input_stream ,"%s" ,buff ); 39x = String (buff ); 40} 41 42void displayTailAndClose () { 43char * rval ; 44char buff [BUFSIZ ]; 45 46rval = fgets (buff ,BUFSIZ ,input_stream ); 47while (rval != 0 ) { 48printf (buff ); 49rval = fgets (buff ,BUFSIZ ,input_stream ); 50 } 51fclose (input_stream ); 52} 53 54void readInput (const char * file_name ) { 55String next_command ; 56bool all_done = false; 57 58/* open the file */ 59input_stream = fopen (file_name ,"r" ); 60if (input_stream == 0 ) { 61printf ("sorry, I could not open %s for reading\n" ,file_name ); 62exit (-1 ); 63 } 64 65/* main loop, read commands from input file */ 66do { 67readString (next_command ); 68if (next_command == inventory_cmd_name ) { 69processInventory (); 70 }else if (next_command == purchase_cmd_name ) { 71processPurchase (); 72 }else if (next_command == summarize_cmd_name ) { 73processSummarize (); 74 }else if (next_command == quit_cmd_name ) { 75all_done = true; 76 }else { 77printf ("Encountered an error in input file\n" ); 78printf ("The offending line has been ignored\n" ); 79 } 80 }while (!all_done ); 81 82displayTailAndClose (); 83} 84 85int main (void ) { 86readInput ("TheMotherOfAllTestCases.txt" ); 87reset (); 88readInput ("test1.txt" ); 89reset (); 90readInput ("test2.txt" ); 91reset (); 92readInput ("test3.txt" ); 93reset (); 94return 0 ; 95}