#include <iostream>
#include<conio.h>
using namespace std;
class Equipment {
protected:
float price;
public:
Equipment(float p)
{ price = p;}
virtual void display() const { }
virtual void read() { }
} ;
class Printer : public Equipment {
private:
char* type;
int speed;
public:
Printer(const char s[] = "", const float p = 0, const int ppm = 0) :
Equipment(p)
{ type = new char[strlen(s)+1];
if (type == NULL) { cout << "Out of memory\n"; exit(0); }
strcpy(type,s);
speed = ppm;}
friend ostream& operator << (ostream& out, const Equipment* e);
friend istream& operator >> (istream& in, Equipment& e);
/*Printer& operator = (const Printer& p)
{ if (this == &p) return *this;
delete [] type;
strcpy(type, p.type);
return *this; } */
void read()
{ cout << " Enter printer type : "; cin >> type;
cout << " Enter printer speed: "; cin >> speed;
cout << " Enter printer price: "; cin >> price;
cout << endl;}
void display() const
{ cout << " Printer type: " << type << endl;
cout << " Printer speed: " << speed << endl;
cout << " Printer price: " << price << endl << endl; }
~Printer()
{ delete [] type; }
} ;
ostream& operator << (ostream& out, const Equipment* e) //for cout
{ e->display(); return out;}
istream& operator >> (istream& in, Equipment& e) // for cin
{ e.read(); return cin;}
int main()
{ cout << endl << endl;
Equipment* dataBase[10]; int cnt = 0;
Printer p;
cout << " --- Reading Objects --- " << endl;
cin >> p;
dataBase[cnt++] = &p;
cout << " --- Displaying Objects --- " << endl;
for (int i=0; i < cnt; i++)
cout << dataBase
;
getch();
return 0;
}