Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include using namespace std; class Purchase { public: bool ReadFoodAndQuantity(); void Print() const; private: string food; int quantity; }; bool Purchase::ReadFoodAndQuantity() { string newFood;

image text in transcribed

#include #include using namespace std;

class Purchase { public: bool ReadFoodAndQuantity(); void Print() const; private: string food; int quantity; };

bool Purchase::ReadFoodAndQuantity() { string newFood; cin >> newFood; if (newFood == "end") { return false; } else { food = newFood; cin >> quantity; return true; } }

void Purchase::Print() const { cout

class Ledger { public: void InputPurchases(); void PrintPurchases(); private: vector purchaseList; };

/* Your code goes here */ Please edit at here and do not change other code, use default template,thank you.

void Ledger::PrintPurchases() { unsigned int i; Purchase currPurchase;

for (i = 0; i

int main() { Ledger ledger;

ledger.InputPurchases(); ledger.PrintPurchases(); return 0; }

Write the InputPurchases() function in the Ledger class. Within InputPurchases(), use currPurchase's ReadFoodAndQuantity() to read each pair of inputs, string food and integer quantity, until "end" is read from input and currPurchase's ReadFoodAndQuantity() returns false. If currPurchase's ReadFoodAndQuantity() returns true, append currPurchase to vector purchaseList. Ex: If the input is truffle 3 cabbage 20 pumpkin 7 end, then the output is: Purchase: truffle, Quantity: 3 Purchase: cabbage, Quantity: 20 Purchase: pumpkin, Quantity: 7

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions

Question

Explain the main elements of a sustainable work system

Answered: 1 week ago

Question

Explain the nature of paid work

Answered: 1 week ago