previous | index | next

Expanding the ItemInfo Class

Displaying the price and color of an item should be performed by a class method.

So expand the ItemInfo class:

class ItemInfo {
public:
  ItemInfo(double p, string c) {
    price = p;
    color = c;
  };

  double getPrice() { return price; }
  string getColor() { return color; }

  void display() {
    cout << "The item's price is " << price << endl;
    cout << "The item's color is " << color << endl;
  }
private:
  double price;
  string color;
};

Note that display can access the private instance variables of the class.


previous | index | next