Description
You are a manager of a printery (印刷廠). There are 3 departments in the printery, Cyan department, Magenta department, Yellow department, which is charged in cyan dye, magenta dye, and yellow dye respectively.
Complete four existed classes CyanDepartment, MagentaDepartment, YellowDepartment, PrinteryManager.
Printery:
Protected Variables:
- cyan_storage(int) as the storage of cyan dye.
- magenta _storage(int) as the storage of magenta dye.
- yellow_storage(int) as the storage of yellow dye.
Public Methods:
- void info() – Should print out the storage of all kinds of dye.
CyanDepartment: virtual derived from Printery
Constructors:
- CyanDepartment(int c) – Should initialize the cyan_storage to c.
Public Methods:
- void buy(int l) – Should increase the cyan_storage by l.
- void use(int l) – Should decrese the cyan_storage by l.
- bool check(int l) – Return true if cyan_storage is more or equal than l; otherwise, return false.
So as to classes MagentaDepartment (handle magenta_storage), YellowDepartment (handle yellow_storage).
PrinteryManager: derived from CyanDepartment, MagentaDepartment, YellowDepartment
Constructors:
- PrinteryManager(int c, int m, int y) – Should initialize the cyan_storage to c, magenta_storage to m, yellow_storage to y.
Public Methods:
- void info() – Should call info() in Printery to print out the storage information.
- void buy(int c, int m, int y) – Should call buy() in CyanDepartment, MagentaDepartment, YellowDepartment to increase cyan_storage by c, magenta_storage by m, yellow_storage by y. And print out as below format.
Buy cyan:cL, magenta:mL, yellow:yL, total:tL
For example: Buy cyan:10L, magenta:20L, yellow:30L, total:60L
- void use(int c, int m, int y) – First, call check() to see whether all the dye have enough storage. If so call use() in CyanDepartment, MagentaDepartment, YellowDepartment to decrease cyan_storage by c, magenta_storage by m, yellow_storage by y. And print out as below format.
Use cyan:cL, magenta:mL, yellow:yL, total:tL
For example: Use cyan:10L, magenta:20L, yellow:30L, total:60L
Otherwise, than do nothing.
- bool check(int c, int m, int y) – Call check() in CyanDepartment, MagentaDepartment, YellowDepartment. Return true if all of them have enough storage. Otherwise, return false, and print as below format:
[ERROR] No enough color dye
For example:
[ERROR] No enough cyan dye
[ERROR] No enough yellow dye
note that print by followed order cyan -> magenta -> yellow.
main.cpp: download
#include <iostream>
#include <iomanip>
using namespace std;
class Printery
{
public:
void info()
{
cout << "[C_STORAGE]:" << cyan_storage << "L" << endl
<< "[M_STORAGE]:" << magenta_storage << "L" << endl
<< "[Y_STORAGE]:" << yellow_storage << "L" << endl;
}
protected:
int cyan_storage, magenta_storage, yellow_storage;
};
class CyanDepartment: // Todo
{
public:
CyanDepartment(int c)
{
cyan_storage = c;
}
void buy(int l)
{
cyan_storage += l;
}
void use(int l)
{
cyan_storage -= l;
}
bool check(int l)
{
if (l <= cyan_storage)
return true;
else
return false;
}
};
class MagentaDepartment: // Todo
{
public:
MagentaDepartment(int m)
{
magenta_storage = m;
}
void buy(int l)
{
magenta_storage += l;
}
void use(int l)
{
magenta_storage -= l;
}
bool check(int l)
{
if (l <= magenta_storage)
return true;
else
return false;
}
};
class YellowDepartment: // Todo
{
public:
YellowDepartment(int y)
{
yellow_storage = y;
}
void buy(int l)
{
yellow_storage += l;
}
void use(int l)
{
yellow_storage -= l;
}
bool check(int l)
{
if (l <= yellow_storage)
return true;
else
return false;
}
};
class PrinteryManager : protected CyanDepartment, MagentaDepartment, YellowDepartment
{
public:
PrinteryManager(int c, int m, int y) : CyanDepartment(c), MagentaDepartment(m), YellowDepartment(y) {}
void info()
{
// Todo
}
void buy(int c, int m, int y)
{
// Todo
}
void use(int c, int m, int y)
{
// Todo
}
private:
bool check(int c, int m, int y)
{
// Todo
}
};
void check()
{
int testcase;
cin >> testcase;
if (testcase == 1)
{
PrinteryManager pm = PrinteryManager(50, 20, 70);
pm.info();
pm.buy(50, 80, 30);
pm.info();
}
else if (testcase == 2)
{
PrinteryManager pm = PrinteryManager(100, 40, 60);
pm.info();
pm.use(90, 30, 50);
pm.info();
}
else if (testcase == 3)
{
PrinteryManager pm = PrinteryManager(20, 30, 80);
pm.info();
pm.use(120, 60, 50);
pm.info();
}
else if (testcase == 4)
{
PrinteryManager pm = PrinteryManager(15, 10, 10);
pm.info();
pm.use(30, 20, 20);
pm.info();
pm.buy(15, 10, 10);
pm.use(30, 20, 20);
pm.info();
}
else if (testcase == 5)
{
PrinteryManager pm = PrinteryManager(700, 200, 600);
pm.info();
pm.use(900, 100, 500);
pm.info();
pm.buy(300, 0, 200);
pm.use(900, 900, 900);
pm.info();
}
}
int main()
{
check();
return 0;
}
Input
No need to handle input. (Input would be number 1~5 to represent the index of test-case)
Output
Depend on test case show in main.cpp.
Tags