9/23/2020 PROJECT 1 https://maryash.github.io/235/projects/project_1_/project_1_.html 1/9 Project 1 The Art of the Cart Your objective for this project is to implement a high level shopping simulator....

submitting files on gradescope


9/23/2020 PROJECT 1 https://maryash.github.io/235/projects/project_1_/project_1_.html 1/9 Project 1   The Art of the Cart Your objective for this project is to implement a high level shopping simulator. To do so you will use inheritance to model a class, ShoppingCart , after another class, DynamicArray , that you will modify to make functional. You will proceed to create an abstract Grocery class and to create its concrete children Vegetable , Drink , and JunkFood , which will collectively represent every type of item with which you can populate a ShoppingCart object. For this project you will use separate compilation with g++ to link multiple classes into one executable, and, in order to successfully complete this project, you must understand the prerequisite material from Project 0, the concept of an abstract data type, template classes, dynamic memory allocation, and polymorphism. Some additional resources Concept of an Abstract Data Type: Geeks for Geeks MIT https://www.geeksforgeeks.org/abstract-data-types http://web.mit.edu/6.005/www/fa14/classes/08-abstract-data-types/ 9/23/2020 PROJECT 1 https://maryash.github.io/235/projects/project_1_/project_1_.html 2/9 Dynamic Memory Allocation: C++ Documentation Tutorialspoint Template Classes: tutorialspoint Geeks for Geeks Polymorphism: javaTpoint Medium Implementation: Work incrementally! Work through the tasks sequentially (implement and test). Only move on to a task when you are positive that the previous one has been completed correctly. Remember that the names of function prototypes and member variables must exactly match those declared in the respective header file when implementing a class. Definition: Let a dynamically resizable array be an array whose maximum capacity increases by a factor of 2 in the event that an insertion is attempted when it is already at maximum capacity and whose maximum capacity decreases by a factor of 2 when the number of elements within it drops below a quarter of its maximum capacity. Examples: arr1 <- {1,="" 2,="" 3,="" 4}="" (capacity="=" 4)="" arr1.add(5)="" arr1="=" {1,="" 2,="" 3,="" 4,="" 5,="" _,="" _,="" _}="" (capacity="=" 8)="" arr2=""><- {1,="" 2,="" 3,="" 4,="" 5,="" _,="" _,="" _}="" (capacity="=" 8)="" arr2.remove(5)="" arr2.remove(4)="" arr2.remove(3)="" arr2.remove(2)="" arr2="=" {1,="" _,="" _,="" _}="" (capacity="=" 4)="" http://www.cplusplus.com/doc/tutorial/dynamic/="" https://www.tutorialspoint.com/cplusplus/cpp_dynamic_memory.htm="" https://www.tutorialspoint.com/cplusplus/cpp_templates.htm="" https://www.geeksforgeeks.org/templates-cpp/="" https://www.javatpoint.com/cpp-polymorphism="" https://medium.com/@deryacortuk17/polymorphism-in-c-5a7b188fa94f/="" 9/23/2020="" project="" 1="" https://maryash.github.io/235/projects/project_1_/project_1_.html="" 3/9="" addendum:="" removal="" in="" this="" fashion="" ensures="" the="" efficient="" execution="" of="" future="" anticipated="" insertions="" by="" minimizing="" the="" amount="" of="" resize()="" operations="" that="" need="" to="" be="" called="" later.="" required="" files="" starter_code.zip="" task="" 1:="" the="" grocery="" list="" now="" that="" you="" have="" your="" bicycle()="" ,="" your="" parents="" want="" you="" to="" run="" some="" errands.="" today="" you="" must="" go="" grocery="" shopping.="" what="" your="" parents="" don’t="" realize="" is="" that="" now="" you’re="" in="" charge.="" you="" have="" the="" money="" and="" the="" list!="" the="" list…="" how="" do="" you="" make="" a="" list="" again?="" modify="" the="" dynamicarray.cpp="" file="" to="" implement="" the="" following="" methods="" (i="" highly="" suggest="" that="" you="" complete="" them="" in="" the="" presented="" order).="" the="" prototypes="" have="" already="" been="" written="" for="" you.="" i)=""> void DynamicArray::resize() //carries out the dynamic sizing mentioned in the definition Hint: You must dynamically allocate a new array of the appropriate altered size, and then you must copy all elements from the initial array into this new one. Finally, you must update and reassign the private members of the caller. ii) template bool DynamicArray::add(const ItemType &new_entry) // inserts an item into the last position of the caller // it must call resize(), and it must allow for the // the pointer to the caller array to be == nullptr iii) template bool DynamicArray::remove(const ItemType &an_item) https://maryash.github.io/235/projects/project_1_/starter_code.zip 9/23/2020 PROJECT 1 https://maryash.github.io/235/projects/project_1_/project_1_.html 4/9 // removes the first instance of an item from the caller // it must check whether the element to be removed is within // the array and it must call resize() Hint: Before you call resize you could copy all of the items except the one to be removed into a new dynamically allocated array. Task 2: FOOD! That’s right; you heard me! FOOD! Everything you could ever want! Grab whatever your heart desires! Define and implement the Vegetable , Drink , and JunkFood classes as polymorphic children of the Grocery class. Class Vegetable must contain the following methods: /** unit of price: dollars unit of weight: pounds (lb) */ Vegetable(std::string name, double price, double weight) /** total_price_ <- product="" of:="" quantity,="" weight="" per="" item,="" and="" price="" per="" pound="" */="" void="" updatecost()="" updates="" total_price_="" class="" drink="" must="" contain="" the="" following="" methods:="" **="" unit="" of="" price:="" dollars="" unit="" of="" weight:="" pounds="" (lb)="" */="" drink(std::string="" name,="" double="" price,="" double="" weight)="" 9/23/2020="" project="" 1="" https://maryash.github.io/235/projects/project_1_/project_1_.html="" 5/9="" **="" total_price_=""><- product="" of:="" quantity,="" weight="" per="" liter,="" and="" price="" per="" liter="" */="" void="" updatecost()="" updates="" total_price_="" note:="" weight="" liter="=" unit_weight_="" *="" 16="" floz_per_liter="" note:="" 1="" liter="=" 33.814="" fluid="" ounces="" class="" junkfood="" must="" contain="" the="" following="" methods:="" **="" unit="" of="" price:="" dollars="" unit="" of="" weight:="" pounds="" (lb)="" */="" junkfood(std::string="" name,="" double="" price,="" double="" weight)="" **="" total_price_=""><- product="" of:="" quantity="" and="" price="" per="" unit="" */="" void="" updatecost()="" which="" updates="" total_price_="" task="" 3:="" bringing="" it="" home="" did="" you="" get="" everything="" you="" wanted?="" great!="" time="" to="" check="" out="" and="" head="" back="" home.="" hope="" you="" remembered="" to="" get="" the="" bread…="" define="" the="" shoppingcart="" class="" as="" a="" child="" of="" the="" dynamicarray="" class="" in="" a="" file="" entitled="" shoppingcart.hpp="" .="" all="" shopping="" carts="" have="" a="" maximum="" carrying="" capacity="" of="" 350="" pounds.="" implement="" the="" class="" in="" a="" file="" entitled="" shoppingcart.cpp="" .="" you="" must="" include="" but="" are="" not="" limited="" to="" the="" following="" methods="" and="" members:="" public:="" *="" default="" constructor="" */="" 9/23/2020="" project="" 1="" https://maryash.github.io/235/projects/project_1_/project_1_.html="" 6/9="" shoppingcart();="" **="" must="" call="" the="" destructor="" of="" dynamicarray="" */="" ~shoppingcart();="" **="" adds="" new_entry="" to="" the="" caller;="" if="" the="" entry="" already="" exists="" in="" the="" caller,="" increment="" quantity_="" in="" the="" object,="" and="" increment="" the="" curr_contents_weight_="" of="" the="" caller="" by="" the="" unit_weight_="" of="" the="" added="" item.="" @pre="" :="" the="" addition="" of="" the="" weight="" of="" new_entry="" does="" not="" bring="" the="" curr_contents_weight_="" over="" the="" carrying="" capacity="" @return="" :="" true="" if="" the="" addition="" is="" successful="" */="" bool="" add(grocery="" *="" new_entry);="" **="" removes="" the="" first="" instance="" of="" an_item="" from="" the="" caller;="" if="" the="" entry="" already="" exists="" in="" the="" caller,="" decrement="" quantity_="" in="" the="" object,="" and="" decrement="" the="" curr_contents_weight_="" of="" the="" caller="" by="" the="" unit_weight_="" of="" the="" added="" item.="" --=""> !!!THIS FUNCTION MUST CALL garbageClear()!!! <-- @return="" :="" true="" if="" the="" addition="" is="" successful="" */="" bool="" remove(grocery="" *="" an_item);="" **="" displays="" shopping="" cart="" contents="" in="" required="" format="" */="" 9/23/2020="" project="" 1="" https://maryash.github.io/235/projects/project_1_/project_1_.html="" 7/9="" double="" checkout();="" **="" iterates="" through="" caller="" and="" removes="" items="" whose="" quantity_="=" 0="" --=""> !!!THIS FUNCTION MUST CALL DynamicArray::remove()!!! <-- @post="" :="" every="" item="" in="" the="" caller="" has="" quantity_="">= 1 */ void garbageClear(); /* Getter: curr_contents_weight_ */ double getCurrentWeight(); private: double curr_contents_weight_; Here is a freebie implementation of method checkout() to put in ShoppingCart.cpp : double ShoppingCart::checkout() { if (item_count_ == 0) { std::cout < "your="" cart="" is="" empty!"="">< std::endl;="" return="" 0;="" }="" double="" total="0;" for="" (size_t="" i="0;" i="">< item_count_;="" i++)="" {="" std::cout="">< "\n"="">< std::setw(10)="">< std::left="">< items_[i]-="">getName() < "\t"="">< items_[i]-="">getQuantity() < "\t"="">< std::fixed="">< std::setprecision(2)="">< items_[i]-="">getTotalPrice(); total += items_[i]->getTotalPrice(); } 9/23/2020 PROJECT 1 https://maryash.github.io/235/projects/project_1_/project_1_.html 8/9 std::cout < std::setfill('-')="">< std::setw(40)="">< "\n"="">< std::endl="">< "total:>
Sep 23, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here