Question: 4. a) a a Fig. 4-B below describes main() program that invokes function readAndStore FurnitureRecords ( to : read in furniture data stored in a

 4. a) a a Fig. 4-B below describes main() program that

invokes function readAndStore FurnitureRecords ( to : read in furniture data storedin a file with the filename that was passed in as argument

extract the relevent pieces of information like name, material, weight, etc of

4. a) a a Fig. 4-B below describes main() program that invokes function readAndStore FurnitureRecords ( to : read in furniture data stored in a file with the filename that was passed in as argument extract the relevent pieces of information like name, material, weight, etc of each furniture stored in the file (Hint: make use of the function splitString() in Qn 2) initialize a FurnitureType struct variable with the furniture's name, height, weight, selfAssembled data (Hint function convertFrStringToPrimitiveType() in Qn 3 can also be used to help you!) store the FurnitureType variable info into a vector return a vector which contains the data of each furniture found in the file Based on the sample contents of file "furniture.txt" in Fig. 4-A, assuming both splitString() from Qn 2 and convertFrStringToPrimitiveType() in Qn 3 are available in the main() program in Fig. 4-B, and the sample output as shown in Fig. 4-C, write the implementation code for the function readAndStore FurnitureRecords () based on the function prototype signature as shown below: vector readAndStoreFurnitureRecords (string filename) (6 marks) b) Implement the toString() for struct Furniture, such that the program's output will appear as shown in Fig. 4-C, based on the sample contents of file "furniture.txt" in Fig. 4-A (4 marks) name; material;weight;selfAssembled dining chair;plastic;2.8;0 kitchen table; wood;6.8;1 bar stool;metal;5.3;0 clothes rack; wood; 3.3:1 Fig. 4-A vector splitString (string str, string delimiter) { vector result; size_t pos 0; string token; while ((pos = str.find(delimiter)) != std::string: : npos) { token = str.substr(0, pos); result.push_back (token); str.erase (0, pos+delimiter. length()); } if (!str.empty()) result.push_back (str); return (result); } template T convertFrStringToPrimitiveType (string input) { istringstream iss (input); I output; iss >> output; return (output); } #include #include #include #include #include Fig. 4-B using namespace std; struct Furniture { string name, material; float weight; bool selfAssembled; string toString(); // readAndStoreFurnitureRecords (string filename); Assuming the code for splitString() and convertFrStringToPrimitiveType() are implemented here! int main() { string filename = "furniture.txt"; vector furnitureRecs = readAndStoreFurnitureRecords (filename); for (int i=0; i

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 Databases Questions!