previous | index | next

Separating the Other Classes

Similar separation is done for the subclasses, shown below. Note that the header files need to include item.H because they reference the superclass ItemInfo.

Here is a zipped folder containing all the code discussed here: Duds.zip.

OxfordShirtInfo

shirt.H

#ifndef _SHIRT_H
#define _SHIRT_H

#include "item.H"
#include <string>
using namespace std;

class OxfordShirtInfo: public ItemInfo {
public:
  OxfordShirtInfo(double p, string c, int n, int s);
  int getNeck();
  int getSleeve();    
  void display();
private:
  int neck;
  int sleeve;
};

#endif /* _SHIRT_H */
shirt.cpp

#include "shirt.H"

OxfordShirtInfo::OxfordShirtInfo(double p, string c, int n, int s) :
  ItemInfo(p, c) {
  neck = n;
  sleeve = s;
}

int OxfordShirtInfo::getNeck() {
  return neck;
}

int OxfordShirtInfo::getSleeve() {
  return sleeve;
}

void OxfordShirtInfo::display() {
  cout << "The shirt's price is " << getPrice() << endl;
  cout << "The shirt's color is " << getColor() << endl;
  cout << "The shirt's neck size is " << neck << endl;
  cout << "The shirt's sleeve length is " << sleeve << endl;
}

ChinoInfo

chino.H

#ifndef _CHINO_H
#define _CHINO_H

#include "item.H"
#include <string>
using namespace std;

class ChinoInfo: public ItemInfo {
public:
  ChinoInfo(double p, string c, int s, int i, bool cf);
  int getSize();
  int getInseam();
  bool getCuffed();    
  void display();
private:
  int size;
  int inseam;
  bool cuffed;
};

#endif /* _CHINO_H */
chino.cpp

#include "chino.H"

ChinoInfo::ChinoInfo(double p, string c, int s, int i, bool cf) :
  ItemInfo(p, c) {
  size = s;
  inseam = i;
  cuffed = cf;
}

int ChinoInfo::getSize() {
  return size;
}

int ChinoInfo::getInseam() {
  return inseam;
}

bool ChinoInfo::getCuffed() {
  return cuffed;
}

void ChinoInfo::display() {
  cout << "The pants' price is " << getPrice() << endl;
  cout << "The pants' color is " << getColor() << endl;
  cout << "The pants' waist size is " << size << endl;
  cout << "The pants' inseam length is " << inseam << endl;
  cout << "The pants are " <<
    (cuffed ? "" : "not ") << "cuffed." << endl;
}


previous | index | next