1. Engineering
  2. Computer Science
  3. 1 create an item class 10 points in the problems...

Question: 1 create an item class 10 points in the problems...

Question details

1. Create an Item class

[10 points] In the problems below, we will be implementing a list of "items." In this problem, we will create an Item class for this purpose. The idea is that you can modify Item to hold whatever kind of data you want, and your list implementation will work. Later in the class, we will learn how to make this even more general.

To make things a little interesting, we will have two components to our Item: (1) an integer key and (2) a literal string value. We don't need to allocate space for the string characters; our assumption is that only literal strings (e.g., "abc") will be used to initialize the Item.

Your class must include:

  • [2.5 pts] Private member variables for the key (int) and value (const char *). Don't allocate space for the string -- just keep a pointer.

  • [2.5 pts] A public constructor that initializes the key and value. Again, don't copy the string that is passed in -- just save the pointer.

  • [2.5 pts] Public methods to read the key and value -- e.g., getKey(), getValue().

  • [2.5 pts] A public copy constructor.

Item.h:


Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution