/// A quick example main maethod that shows utilizing the /// provided GroceryItem class #include #include "GroceryItem.hpp" using namespace std; int main(int argc, char* argv[]) { GroceryItem empty;...

I need this in c++


/// A quick example main maethod that shows utilizing the /// provided GroceryItem class #include #include "GroceryItem.hpp" using namespace std; int main(int argc, char* argv[]) { GroceryItem empty; cout < empty="">< endl;="" a="" gorcery="" item="" -="" we="" want="" to="" get="" 2="" oreos.="" groceryitem="" cookies("oreo",="" 2);="" cout="">< cookies="">< endl;="" a="" gorcery="" item="" -="" we="" want="" to="" get="" a="" bag="" of="" bugles.="" groceryitem="" snack("bugles");="" cout="">< snack="">< endl;="" ++cookies;="" cout="">< "after="" increment,="" cookies=" << cookies << endl; --cookies; cout << " after="" decrement,="" cookies=" << cookies << endl; cookies.bought()=true; cout << " after="" setting="" bought="" to="" true,="" cookies=" << cookies << endl; GroceryItem holder; cout << " please="" enter="" a="" grocery="" item="" -="" name="" (no="" spaces)="" followed="" by="" qty:="" ";="" cin="">> holder; cout < "you="" gave:="" "="">< holder="">< endl;="" cout="">< endl="">< "this="" is="" not="" an="" exhaustive="" example="" -="" but="" should="" give="" you="" agood="" start!"="">< endl="">< "***see="" the="" groceryitem.hpp="" file="" for="" more="" options!***"="">< endl;="" return="" 0;="" }="" ***********************************************************="" *="" file:="" groceryitem.cpp="" *="" *="" author:="" s.="" blythe="" *="" *="" date:="" 8/2021="" *="" *="" purpose:="" class="" implementation="" for="" groceryitem,="" as="" *="" *="" needed="" in="" csc24400="" project="" 2="" *="" ***********************************************************/="" #include="" "groceryitem.hpp"="" using="" namespace="" std;="" method="" to="" print="" to="" given="" stream="" ostream&="" groceryitem::print(ostream="" &os)="" const="" {="" os="">< _name="">< "="" ("="">< _quantity="">< ")="" purchased?="" "="" ;="" if="" (_bought)="" os="">< "yes";="" else="" os="">< "no";="" return="" os;="" }="" method="" to="" read="" from="" given="" stream="" istream&="" groceryitem::read(istream="" &is)="" {="" is="">> _name >> _quantity; // just read name and quantity ... _bought=false; // ... assume not bought yet return is; } //implement overloaded < by="" calling="" print.="" ostream&=""><(ostream &os,="" const="" groceryitem="" &gi)="" {="" return="" gi.print(os);="" }="" implement="" overloaded="">> by calling read. istream& operator>>(istream &is, GroceryItem &gi) { return gi.read(is); } /*********************************************************** * FILE: GroceryItem.hpp * * AUTHOR: S. Blythe * * DATE: 8/2021 * * PURPOSE: Class definition for GroceryItem, as needed in * * CSC24400 project 2 * ***********************************************************/ #ifndef _GROCERY_ITEM_HPP_ #define _GROCERY_ITEM_HPP_ #include #include class GroceryItem { private: std::string _name; // the name of the Grocery Item int _quantity; // amount of item needed bool _bought; // has the item been bought yet? public: // default constructor GroceryItem(): _name(), _quantity(0), _bought(false) {} // constructor with name and quantity (defaults to 1 if not specified) GroceryItem(const std::string &name, int quantity=1): _name(name), _quantity(quantity), _bought(false) {} // accessor/modifier for name const std::string& name() const {return _name;} std::string& name() {return _name;} // accessor/modifier for quantity int quantity() const {return _quantity;} int& quantity() {return _quantity;} // accessor/modifier for bought status bool bought() const {return _bought;} bool& bought() {return _bought;} // overloads that allow for increment or decrement of quantitty. GroceryItem operator++() {_quantity++; return *this;} GroceryItem operator--() {_quantity--; return *this;} // methods to print or rad to/from a stream std::ostream& print(std::ostream &os) const; std::istream& read(std::istream &is); // overload the < (output)="" and="">> (input) operator friend std::ostream& operator< (std::ostream="" &os,="" const="" groceryitem="" &gi);="" friend="" std::istream&="" operator="">> (std::istream &is, GroceryItem &gi); }; #endif project2 CSC24400 Programming Project #2 Due: Friday, 10/29/2021, 11:59PM Problem Description You will be writing a C++ class called GroceryList that represents a collection of grocery items on a shopping list. You are being provided with a class called GroceryItem - both definition (.hpp) and implementation (.cpp); make sure not to waste ANY time “re-inventing the wheel”! You must store the definition of your class in a file called GroceryList.hpp. You may store the implementation in any file you like, although it is strongly recommended that you store such in a file called GroceryList.cpp. You must use a partially filled array to implement the GroceryList class. Your GroceryList class must implement the following: • a default (no argument) constructor that initializes “this” GroceryList to contain no actual GrocerItems. “This” GroceryList should initially be capable of holding up to 5 elements (and no more.) • a method called getLength that takes no arguments and returns an integer. This should simply return the current number of GroceryItems in “this” GroceryList. • a method called numEmptySlots that takes no arguments and returns an integer. The method should return the number of empty slots in the underlying partially filled array. • overload the = operator when the right hand side is another GroceryList. It should change “this” GroceryList so that it contains an exact duplicate of each GroceryItem in the right hand side GroceryList. The method should then return the copied GroceryList. • overload the += operator when the right hand side is a GroceryItem.The GroceryItem on the right hand side should be added to “this” GroceryList. If the GroceryItem already exists in “this” GroceryList, then the corresponding quantity in “this” GroceryList should be updated to be the sum of the two associated quantities. The right hand side GroceryItem should not be modified by this process. A copy of the new GroceryList should be returned. • overload the += operator when the right hand side is another GroceryList. Each GroceryItem in the right hand side should be added to “this” GroceryList (see previous bullet item), and a copy of the resulting GroceryList should be returned. • overload the -= operator when the right hand side is a string. This string will represent the name of a GroceryItem. If such an item is found in the GroceryList, then that item should be removed from the GroceryList. A copy of the resulting GroceryList should be returned. • overload the [ ] operator, when the value between the [ ]’s is a string. This should return a pointer to the corresponding GroceryItem if it is found in “this” GroceryList, and NULL otherwise. • a method called checkOff, which should take a single string parameter representing the name of a GroceryItem to mark as purchased, unless such a GroceryItem is not found in “this” GroceryList (in which case nothing should happen.) The function should return nothing. • overload the < operator to output to a stream. this should output each groceryitem in the associated grocerylist, one per line. note that the order the groceryitems are listed is not important. remember, you are being provided with code to output a single groceryitem! some other important implementation details: • it is very likely that more items than can fit in the current grocerylist will be added at some points in time. whenever this happens (and not before such time), the array size should be doubled. • make sure to use const appropriately where it should be utilized. • make sure to pass parameters efficiently where it makes sense to do so. • make sure to return values efficiently where it makes sense to do so. • remember, you must use a partially filled array to solve this project. no exceptions! grading breakdown correct submission 10% code compiles 15% following directions 25% corect execution 40% comments/code fromatting/read.me 10% what to hand in you will be submitting a zip or tgz file containing your source code and a read.me file to canvas. make sure that you place the project into a single folder (which may contain sub- folders). the read.me file should include information about your project including (but not necessarily limited to): • your name • the date • the platform you developed your code on (windows, linux, ...) • any special steps needed to compile your project • any bugs your program has • a brief summary of how you approached the problem you might also want to consider adding things like a “software engineering log” or anything else you utilized while completing the project. final notes/hints • for most people, this is not the kind of project that you will be able to start the day before it is due and successfully complete. my recommendation is to start now. • if you have any questions about anything involved with this project, ask me. if you don’t ask for help, i will not know that operator="" to="" output="" to="" a="" stream.="" this="" should="" output="" each="" groceryitem="" in="" the="" associated="" grocerylist,="" one="" per="" line.="" note="" that="" the="" order="" the="" groceryitems="" are="" listed="" is="" not="" important.="" remember,="" you="" are="" being="" provided="" with="" code="" to="" output="" a="" single="" groceryitem!="" some="" other="" important="" implementation="" details:="" •="" it="" is="" very="" likely="" that="" more="" items="" than="" can="" fit="" in="" the="" current="" grocerylist="" will="" be="" added="" at="" some="" points="" in="" time.="" whenever="" this="" happens="" (and="" not="" before="" such="" time),="" the="" array="" size="" should="" be="" doubled.="" •="" make="" sure="" to="" use="" const="" appropriately="" where="" it="" should="" be="" utilized.="" •="" make="" sure="" to="" pass="" parameters="" efficiently="" where="" it="" makes="" sense="" to="" do="" so.="" •="" make="" sure="" to="" return="" values="" efficiently="" where="" it="" makes="" sense="" to="" do="" so.="" •="" remember,="" you="" must="" use="" a="" partially="" filled="" array="" to="" solve="" this="" project.="" no="" exceptions!="" grading="" breakdown="" correct="" submission="" 10%="" code="" compiles="" 15%="" following="" directions="" 25%="" corect="" execution="" 40%="" comments/code="" fromatting/read.me="" 10%="" what="" to="" hand="" in="" you="" will="" be="" submitting="" a="" zip="" or="" tgz="" file="" containing="" your="" source="" code="" and="" a="" read.me="" file="" to="" canvas.="" make="" sure="" that="" you="" place="" the="" project="" into="" a="" single="" folder="" (which="" may="" contain="" sub-="" folders).="" the="" read.me="" file="" should="" include="" information="" about="" your="" project="" including="" (but="" not="" necessarily="" limited="" to):="" •="" your="" name="" •="" the="" date="" •="" the="" platform="" you="" developed="" your="" code="" on="" (windows,="" linux,="" ...)="" •="" any="" special="" steps="" needed="" to="" compile="" your="" project="" •="" any="" bugs="" your="" program="" has="" •="" a="" brief="" summary="" of="" how="" you="" approached="" the="" problem="" you="" might="" also="" want="" to="" consider="" adding="" things="" like="" a="" “software="" engineering="" log”="" or="" anything="" else="" you="" utilized="" while="" completing="" the="" project.="" final="" notes/hints="" •="" for="" most="" people,="" this="" is="" not="" the="" kind="" of="" project="" that="" you="" will="" be="" able="" to="" start="" the="" day="" before="" it="" is="" due="" and="" successfully="" complete.="" my="" recommendation="" is="" to="" start="" now.="" •="" if="" you="" have="" any="" questions="" about="" anything="" involved="" with="" this="" project,="" ask="" me.="" if="" you="" don’t="" ask="" for="" help,="" i="" will="" not="" know="">
Oct 15, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here