Question: / / Complete me #include customparser.h #include #include using namespace std; const char * error _ msg _ 1 = Cannot read integer n

// Complete me #include "customparser.h" #include #include using namespace std; const char* error_msg_1= "Cannot read integer n"; const char* error_msg_2= "Error in content parsing"; const char* error_msg_3= "Error in user parsing"; // To Do - Complete this function void CustomFormatParser::parse(std::istream& is, std::vector& content, std::vector& users){//separatte into 3 parts, the first bullet point the second the third int n; if(!(is >> n)){ throw ParserError(error_msg_1); } string line; getline(is,line); //to move on to next for(int i =0; i < n; i++){ int id, type,numReviews,totalStars,rating,numEpisodes; std::string name, viewersline; std::vectorviewers; if(!(is>>id>>type)){ throw ParserError(error_msg_2); } std::getline(is,line); std::getline(is>>std::ws,name); if(!(is>>numReviews>>totalStars>>rating)){ throw ParserError(error_msg_2); } if(type ==1){ if(!(is >> numEpisodes)){ throw ParserError(error_msg_2); }} std::getline(is>>std::ws,viewersline); if(!viewersline.empty()){ std::stringstream viewerStream (viewersline); std::string viewer; while(viewerStream >> viewer){ viewers.push_back(viewer); }} Content* newContent = nullptr; if(type ==0){ newContent = new Movie(id,name,numReviews,totalStars,rating); } else if(type ==1){ newContent = new Series(id,name,numReviews,totalStars,rating,numEpisodes); } content.push_back(newContent); } while(getline(is>>std::ws,line)){ std::string username; if(!(is >> username)){ break; } int ratingLimit; if(!(is>>ratingLimit)){ throw ParserError(error_msg_3); } User* newUser = new User(username,ratingLimit); users.push_back(newUser); }}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!