-
Notifications
You must be signed in to change notification settings - Fork 0
/
Printer.cpp
71 lines (65 loc) · 1.73 KB
/
Printer.cpp
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
65
66
67
68
69
70
71
#include<string>
#include<iostream>
using namespace std;
class Device {
private:
string name;
string model;
string version;
protected:
Device(string nameArg, string modelArg, string versionArg) :name{ nameArg }, model{ modelArg }, version{versionArg} {
cout << "Device instantiated" << endl;
}
~Device() {
cout << "Device Destructed" << endl;
}
};
class Printer :virtual public Device{
public:
Printer():Device("", "", "") {
cout << "Printer instantiated" << endl;
}
~Printer() {
cout << "Printer Destructed" << endl;
}
virtual void print(string content) {
cout << "print" << content << endl;
}
};
class Scanner: virtual public Device {
public:
Scanner() :Device("", "", "") {
cout << "Scanner instantiated" << endl;
}
~Scanner() {
cout << "Scanner Destructed" << endl;
}
virtual void scan(string content) {
cout << "Scan" << content << endl;
}
};
class PrintScanner :public Printer, public Scanner{
public:
PrintScanner(string n, string m, string v) : Device{ n, m, v } {
cout << "PrinterScanner Initiated" << endl;
}
~PrintScanner(){
cout << "Printer destructed" << endl;
}
};
class TaskManager {
public:
void invokePrintTask(Printer* printPtr, string content) {
printPtr->print(content);
}
void invokeScanTask(Scanner* scanPtr, string content) {
scanPtr->scan(content);
}
};
int main() {
PrintScanner hpPrintScanner("","","");
TaskManager taskMgr;
taskMgr.invokePrintTask(&hpPrintScanner, "doc.pdf");
taskMgr.invokeScanTask(&hpPrintScanner, "doc.pdf");
return 0;
}