#include "Produce.h" //Produce methods Produce::Produce() { weight = 0.0; } Produce::Produce( ifstream& fin ) throw(TokenError) { Extract( fin ); } Produce::Produce( string Name, double Markup, int Cost, double Wt ) :Grocery(Name,Markup,Cost), weight(Wt) { } double Produce::getWeight() const { return weight; } int Produce::getPrice() const { return (int)( weight * Grocery::getCost() * Grocery::getMarkup() + 0.5); } void Produce::Extract(ifstream& fin ) throw(TokenError) { string opentkn, closetkn; fin >> opentkn; if( opentkn != "Produce{" ) throw TokenError("Invalid Open Token!", "Produce::Extract(1)"); Get( fin ); fin >> closetkn; if( closetkn != "}Produce" ) throw TokenError("Invalid Close Token!", "Produce::Extract(2)"); } void Produce::Insert( ostream& fout ) { fout << endl << " Produce{ "; Put( fout ); fout << " }Produce "; } void Produce::Get( ifstream& fin) throw(TokenError) { Grocery::Get( fin ); //parse weight string label; fin >> label; if( label != "weight:" ) throw TokenError("Invalid field token, weight: expected!", "Produce::Get(1)"); fin >> weight; } void Produce::Put ( ostream& fout) { Grocery::Put( fout ); fout << " weight: " << weight; }