Objective You are given a partial implementation of one header file, GildedRose.h. Item is a class that...

70.2K

Verified Solution

Question

Programming

Objective

You are given a partial implementation of one headerfile, GildedRose.h. Item is a class that holds the information foreach item for the inn. GildedRose is a class that holds an internallisting of many Item objects. This inventory should hold at least10 items. For this you can use arrays, the std::array class, oreven the vector class.

Complete the implementation of these classes, addingpublic/private member variables and functions as needed. You shouldchoose an appropriate data structure to maintain this inventorywith an unknown size known only at runtime. Your code is tested inthe provided main.cpp.

You will need to implement the followingfunctions:

  • Constructors/Destructors - Initialize your data.Allocate memory if using a native array. The destructor shoulddeallocate memory if using a native array.

  • size() - This should return the number of itemscurrently for sale (this is different from the max).

  • get(size_t) - This should return the item with thematching index. For example if given an index of 3, you shouldreturn the item at index 3 in the list.

  • add(Item) - This should add another item for sale in theGilded Rose by adding it to your inventory.

  • operator[](size_t) - This should perform identical tothe get(size_t) function.

SKELETAL CODE FOR HEADER FILE:

#pragma once

#include
using std::string;

// 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, intnew_quality)
   : name(new_name), sellIn(new_sellIn),quality(new_quality) {
}


// This class is incomplete...
class GildedRose {
private:
   // Add something to hold at least 10items

public:
   GildedRose();
   ~GildedRose();

   size_t size() const;
   Item& get(size_t);
   void add(const Item&);

   Item& operator[](size_t);
};

Code should be in C++

Answer & Explanation Solved by verified expert
3.6 Ratings (270 Votes)
ScreenshotProgramMaincppinclude    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students