previous | index | next

Virtual Methods

Here are the new OxfordShirtInfo and ChinoInfo classes:

class OxfordShirtInfo: public ItemInfo {
public:
    OxfordShirtInfo(double p, string c, int n, int s):
      ItemInfo(p, c) {
        neck = n;
        sleeve = s;
    }
    int getNeck() { return neck; }
    int getSleeve() { return sleeve; }
    
    void 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;
    }
private:
    int neck;
    int sleeve;
};
class ChinoInfo: public ItemInfo {
public:
    ChinoInfo(double p, string c, int s, int i, bool cf):
      ItemInfo(p, c) {
        size = s;
        inseam = i;
        cuffed = cf;
    }
    int getSize() { return size; }
    int getInseam() { return inseam; }
    bool getCuffed() { return cuffed; }
    
    void 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;
    }
private:
    int size;
    int inseam;
    bool cuffed;
};


previous | index | next