Link to details of C++ programming assignment:https://bytes.usc.edu/cs104-sp21/homework/hw2/programming/ The link above also contains an "example run" to make sure the program works. You can refer to...

1 answer below »
Link to details of C++ programming assignment:https://bytes.usc.edu/cs104-sp21/homework/hw2/programming/


The link above also contains an "example run" to make sure the program works. You can refer to this to test out the code.


I have uploaded the starter code that we have to code in (fill in the blanks in the code) below in the "hw2.zip" file. Please use the starter code and follow the instructions in the link above for where to fill in the blanks in each file. Deadline: July 30, 2021. Language: C++. Thank you.




hw2/database.txt book Data Abstraction & Problem Solving with C++ 79.99 20 978-013292372-9 Carrano and Henry book Great Men and Women of Troy 19.50 5 978-000000000-1 Tommy Trojan clothing Men's Fitted Shirt 39.99 25 Medium J. Crew movie Hidden Figures DVD 17.99 1 Drama PG aturing 100.00 0 johnvn 50.00 1 adal 120.00 1 hw2/db_parser.h #ifndef DBPARSER_H #define DBPARSER_H #include #include #include

#include "datastore.h" #include "product.h" #include "user.h" #include "product_parser.h" /** * Interface for all section parsers_ * A section parser parses everything between *

...

in the database file */ class SectionParser { public: virtual ~SectionParser() { } /** * Parses the section stored in the given istream * Increments lineno after successfully parsing each lineno * Sets errorMsg with a descriptive message upon an error * Returns true if an error occurred. */ virtual bool parse(std::istream& is, DataStore& ds, int& lineno, std::string& errorMsg) = 0; /** * Reports how many items were parsed */ virtual void reportItemsRead(std::ostream& os) = 0; }; /** * Main parser utilizing section parsers to do most * of the actual parsing. Breaks the database into * sections and handle error output */ class DBParser { public: DBParser(); ~DBParser(); /** * Registers a section parser that will be invoked * when a section with sectionName is found in the * database */ void addSectionParser(const std::string& sectionName, SectionParser* parser); /** * Registers a section parser that will be invoked * when a section with sectionName is found in the * database. Returns true if an error occurs. */ bool parse(std::string db_filename, DataStore& ds); private: enum PState { FIND_SECTION, IN_SECTION }; int lineno_; std::string errorMsg_; bool error_; std::map parsers_; }; /** * Product section parser. Uses separate ProductParsers * to parse each type of product */ class ProductSectionParser : public SectionParser { public: ProductSectionParser(); ~ProductSectionParser(); virtual bool parse(std::istream& is, DataStore& ds, int& lineno, std::string& errorMsg); virtual void reportItemsRead(std::ostream& os); void addProductParser(ProductParser* p); protected: Product* parseProduct(const std::string& category, std::istream& is, int& lineno, std::string& errorMsg); private: std::map prodParsers_; unsigned int numRead_ ; }; /** * User section parser that parses and creates Users */ class UserSectionParser : public SectionParser { public: UserSectionParser(); ~UserSectionParser() {} virtual bool parse(std::istream& is, DataStore& ds, int& lineno, std::string& errorMsg); virtual void reportItemsRead(std::ostream& os); protected: User* parseUser( std::istream& is, DataStore& ds, std::string& errorMsg); private: unsigned int numRead_ ; }; #endif hw2/db_parser.cpp #include #include #include #include #include #include #include #include #include "db_parser.h" #include "util.h" using namespace std; DBParser::DBParser() { lineno_ = 1; error_ = false; } DBParser::~DBParser() { for(map::iterator it = parsers_.begin(); it != parsers_.end(); ++it) { delete it->second; } } void DBParser::addSectionParser(const std::string& sectionName, SectionParser* parser) { parsers_.insert(make_pair(sectionName, parser)); } bool DBParser::parse(string db_filename, DataStore& ds) { #ifdef DEBUG cout < "starting="" parsing"="">< endl;="" #endif="" ifstream="" ifile(db_filename.c_str());="" if(ifile.fail())="" {="" return="" true;="" }="" lineno_="1;" int="" startlineno;="" string="" line;="" string="" sectionname;="" pstate="" state="FIND_SECTION;" stringstream="" sectiontext;="" while(!ifile.fail()="" &&="" !error_)="" {="" getline(ifile,="" line);="" #ifdef="" debug="" cout="">< "line:="" "="">< line="">< endl;="" #endif="" trim(line);="" remove="" whitespace="" on="" either="" end="" if(state="=" find_section)="" {="" if((line.size()=""> 2) && line[0] == '<' &&="" line[line.size()-1]="=" '="">') { state = IN_SECTION; sectionName = line.substr(1,line.size()-2); startLineNo = lineno_ + 1; #ifdef DEBUG cout < "found="" section:="" "="">< sectionname="">< endl;="" #endif="" sectiontext.clear();="" sectiontext.str("");="" }="" }="" else="" if(state="=" in_section)="" {="" if((line.size()=""> 3) && line[0] == '<' &&="" line[1]="=" '/'="" &&="" line[line.size()-1]="=" '="">') { map::iterator it = parsers_.find(sectionName); if(it != parsers_.end()) { error_ = it->second->parse(sectionText, ds, startLineNo, errorMsg_); if(error_) { lineno_ = startLineNo; } } else { cerr < "no="" section="" parser="" available="" for="" "="">< sectionname="">< "..skipping!"="">< endl;="" }="" state="FIND_SECTION;" #ifdef="" debug="" cout="">< "end="" section:="" "="">< sectionname="">< endl;="" #endif="" }="" else="" {="" sectiontext="">< line="">< '\n';="" }="" }="" if(error_)="" {="" cerr="">< "parse="" error="" on="" line="" "="">< lineno_="">< ":="" "="">< errormsg_="">< endl;="" }="" lineno_++;="" }="" if(!error_)="" {="">::iterator it = parsers_.begin(); it != parsers_.end(); ++it) { it->second->reportItemsRead(cout); } } return error_; } ProductSectionParser::ProductSectionParser() { numRead_ = 0; } ProductSectionParser::~ProductSectionParser() { for(map::iterator it = prodParsers_.begin(); it != prodParsers_.end(); ++it) { delete it->second; } } void ProductSectionParser::addProductParser(ProductParser* p) { prodParsers_.insert(make_pair(p->categoryID(), p)); } bool ProductSectionParser::parse( std::istream& is, DataStore& ds,
Answered 4 days AfterJul 25, 2021

Answer To: Link to details of C++ programming...

Karthi answered on Jul 30 2021
161 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here