hw1 - / hw1.cpp : Defines the entry point for the console...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
// hw1.cpp : Defines the entry point for the console application. // / #include "stdafx.h" # # include <iostream> # include <string> # include <climits> using namespace std; class Product { public: Product() { price = 0.0; quantity = 0; location = ""; } Product(double p, int q, string l) { price = p; quantity = q; location = l; } virtual ~Product(){ cout << "Deleting object. .."; } virtual string get_value (string s) { if(location == s) return location; else return ""; } virtual void print(void) { cout << "\nFor the selected product:"; cout << "\n Price is: " << price; cout << "\n Quantity is: " << quantity; cout << "\n Location is: " << location; } private: double price; int quantity; string location; }; class Eatable : public Product { public: Eatable() : Product() { name = ""; best_before = ""; } Eatable(string n, string bb, double p, int q, string l) : Product(p, q, l) { name = n; best_before = bb; } virtual ~Eatable(){ cout << "Deleting object. .."; } string get_value (string s) { if(name == s) return name;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
else return ""; } void print(void) { Product::print(); cout << "\n Name is: " << name; cout << "\n Best-before date is: " << best_before; } private: string name; string best_before; }; class Food : public Eatable { public: Food() : Eatable() { category_of_pack = ""; quantity_per_unit = 0.0; measure = ""; } Food(string c, double qu, string m, string n, string bb, double p, int q, string l) : Eatable (n, bb, p, q, l) { category_of_pack = c; quantity_per_unit = qu; measure = m; } virtual ~Food(){ cout << "Deleting object. .."; } string get_value (string s) { if(Eatable::get_value(s) == s) return s; else return ""; } void print(void) { Eatable::print(); cout << "\n Category_of_pack is: " << category_of_pack; cout << "\n Quantity_per_unit: " << quantity_per_unit; cout << "\n Measure: " << measure; M } private: string category_of_pack; double quantity_per_unit; string measure; }; class Beverages : public Eatable { public: Beverages() : Eatable() { type = ""; volume = 0.0; } Beverages(string t, double v, string n, string bb, double p, int q, string l) : Eatable (n, bb, p, q, l) { type = t;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

hw1 - / hw1.cpp : Defines the entry point for the console...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online