1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
class Product {
public:
virtual std::fstream& store(std::fstream& file, bool addNewLine)const = 0;
virtual std::fstream& load(std::fstream& file) = 0;
virtual std::ostream& write(std::ostream& os, bool linear)const = 0;
virtual std::istream& read(std::istream& is) = 0;
virtual bool operator==(const char*) const = 0;
virtual double total_cost() const = 0;
virtual const char* name() const = 0;
virtual void quantity(int) = 0;
virtual int qtyNeeded() const = 0;
virtual int quantity() const = 0;
virtual int operator+=(int) = 0;
virtual bool operator>(const Product&) const = 0;
};
std::ostream& operator<<(std::ostream&, const Product&);
std::istream& operator>>(std::istream&, Product&);
double operator+=(double&, const Product&);
Product* CreateProduct();
Product* CreatePerishable();
}
class NonPerishable : public Product {
char type; //type of product
char sku[max_sku_length + 1]; //sku of product
char* m_pName; //name of, dynamically allocated
char unit[max_unit_length + 1]; //
int inventory; //current inventory
int qtyNeed; //required
double price; //before taxes
bool taxable; //taxes
ErrorMessage* errMsg;
protected:
void name(const char*); //store\override current name with pointer
const char* name() const; //return name\nullptr
double cost() const; //returns the price of the product plus any tax that applies to the product.
void message(const char*); //store message in errMsg
bool isClear() const; //self-explanatory, but in case you forget, return true if errMsg is clear
public:
NonPerishable(char = '\0');
NonPerishable(const char*, const char*, const char*, int = 0, bool = 0, double = 0, int = 0);
~NonPerishable();
NonPerishable(const NonPerishable&);
NonPerishable& operator=(const NonPerishable&);
std::fstream& store(std::fstream&, bool newLine = true) const;
std::fstream& load(std::fstream&);
std::ostream& write(std::ostream&, bool) const;
std::istream& read(std::istream&);
bool operator==(const char*) const;
double total_cost() const; //a query that returns the total cost of all items on hand.
void quantity(int);
bool isEmpty() const;
int qtyNeeded() const;
int quantity() const;
bool operator>(const char*) const;
int operator+=(int);
bool operator>(const Product&) const;
void setEmpty(char = '\0');
};
std::ostream& operator<<(std::ostream&, const Product&);//insert Product record into ostream
std::istream& operator>>(std::istream&, Product&);//extract Product record from istream
double operator+=(double&, const Product&); //return cost
Product* CreateProduct(); //creates NonPerishable object in dynamic memory
}
|