Please fix any mistakes in my GildedRose.hpp file. I keep getting this compiler error of expected primary expression. Also I don't know what to put for my constructor/destructor, instructions say
//Gilded Rose hpp file
#include #include using std::string; using namespace std;
// This is already done for you... class Item { public: string name; int sellIn; int quality; Item(string, int, int); };
Item::Item(string new_name, int new_sellIn, int new_quality) : name(new_name), sellIn(new_sellIn), quality(new_quality) { }
// This class is incomplete... class GildedRose { private: vector- storage; // vector that holds all of our items public: //constructor GildedRose(){ //storage.resize(0); }; //destructor ~GildedRose(){ storage.clear(); };
//returns the size of vector size_t size() const{ return storage.size(); }; // returns item via matching index in vector Item& get(size_t index){ return storage.at(index); }; //adds Item class stuff into vector void add(Item){ storage.push_back(Item); }; // returns item via matching index in vector Item& operator[](size_t index){ return storage.at(index); }; };
//Main file to test(must pass all cases)
// This file tests your class and makes sure you created the GildedRose correctly #include #include #include #include "GildedRose.hpp" using std::fabs; using std::cout; using std::endl; using std::string; const size_t NUM_TESTS = 9; size_t NUM_PASSED = 0; // Helper Functions template void assertEquals(string, T, T); // Main Testing int main(int argc, char const *argv[]) { GildedRose store; store.add(Item("+5 Dexterity Vest", 10, 20)); store.add(Item("Aged Brie", 2, 0)); store.add(Item("Elixir of the Mongoose", 5, 7)); store.add(Item("Sulfuras, Hand of Ragnaros", 0, 80)); assertEquals("GildedRose.size()", static_cast(4), store.size()); assertEquals("GildedRose[0].sellIn", 10, store[0].sellIn); assertEquals("GildedRose.get(3).quality", 80, store.get(3).quality); store.add(Item("Backstage passes to a TAFKAL80ETC concert", 15, 20)); store.add(Item("Backstage passes to a TAFKAL80ETC concert", 10, 49)); store.add(Item("Backstage passes to a TAFKAL80ETC concert", 5, 49)); assertEquals("GildedRose.size()", static_cast(7), store.size()); assertEquals("GildedRose[6].quality", 49, store[6].quality); assertEquals("GildedRose.get(4).sellIn", 15, store.get(4).sellIn); store.add(Item("Conjured Mana Cake", 3, 6)); assertEquals("GildedRose.size()", static_cast(8), store.size()); assertEquals("GildedRose[8].name", static_cast("Conjured Mana Cake"), store[7].name); assertEquals("GildedRose.get(8).name", static_cast("Conjured Mana Cake"), store.get(7).name); // Calculate Total Points cout void assertEquals(string test_name, T expected, T actual) { if (actual == expected) { cout You are given a partial implementation of one header file, GildedRose. App. Item is a class that holds the information for each item in the store. Gilded Rose is a class that holds a listing of Item objects. This inventory should hold at least 10 items For this you should use C++ containers. You should use a container from the ones you have studied so far such as the vector or the array- Complete the implementation of GildedRose class, adding public/private member variables and functions as needed. The implementation of Item class is already done for you. You should choose an appropriate data structure to maintain this inventory with an unknown size, known only at runtime. Your code is tested in the provided main.cpp. You will need to implement the following functions: Constructors/Destructors - Initialize your data. Allocate memory where necessary. The destructor should deallocate memory where necessary size() - This should return the number of items currently for sale (this is the capacity). get(size t) - This should return the item with the matching index. For example if given an index of 3, you should return the item at index 3 in the list. add (Item) - This should add another item for sale in the Gilded Rose by adding it to your inventory operator[](size_t) - This should perform identical to the get(size_t) function. Initially the given code will not compile. As you complete the code, the tests should start to pass in main.cpp Source Code Files You are given "skeleton" code files with declarations that may be incomplete and without any implementation. Implement the code and ensure that all the tests in main.cpp pass successfully GildedRose. hpp: This is to be completed main.cpp: The main function tests the output of your functions. You may wish to add additional tests. During grading your main.cpp file will be replaced with the one you were provided with Hints This is an introductory assignment meant to test your knowledge of constructing a class with storing the inventory and some member functions that change the state of that inventory. Decide which data structure you wish to use for your underlying inventory, std: array or std::vector student@tuffix-vm:-$ g++ main.cpp In file included from main.cpp:5: GildedRose. hpp: In member function 'void GildedRose::add (Item)': GildedRose. hpp:44:29: error: expected primary-expression before storage.push_back(Item); ) token student@tuffix-vm:-$