#include <iostream>
using namespace std;
/*
//419p NO.03
class Point{
int x,y;
public:
Point(int x, int y){this->x =x; this->y=y;}
int getX() {return x;}
int getY() {return y;}
protected:
void move(int x, int y) {this->x=x; this->y=y;}
};
class ColorPoint: public Point{
string color;
public:
ColorPoint();
ColorPoint(int x, int y, string s= " "): Point(x,y){
color=s;
}
void setPoint(int x, int y){
move(x,y);
}
void setColor(string s){
color=s;
}
void show() {
cout << color << "색으로 ( " << getX() << "," << getY() << " )에 위치한 점입니다." << endl;
}
};
int main() {
ColorPoint cp(5, 5, "RED");
cp.setPoint(10, 20);
cp.setColor("BLUE");
cp.show();
}
*/
/*
//419p NO.04
class Point{
int x,y;
public:
Point(int x, int y){this->x =x; this->y=y;}
int getX() {return x;}
int getY() {return y;}
protected:
void move(int x, int y) {this->x=x; this->y=y;}
};
class ColorPoint : public Point {
string color;
public:
ColorPoint() : Point(0, 0) { color = "BLACK"; }
ColorPoint(int x, int y, string s = " ") : Point(x, y) {
color = s;
}
void setPoint(int x, int y) {
move(x, y);
}
void setColor(string s) {
color = s;
}
void show() {
cout << color << "색으로 ( " << getX() << "," << getY() << " )에 위치한 점입니다." << endl;
}
};
int main() {
ColorPoint zeroPoint;
zeroPoint.show();
ColorPoint cp(5, 5);
cp.setPoint(10, 20);
cp.setColor("BLUE");
cp.show();
}
*/
/*
//421p NO.06
class BaseArray{
private:
int capacity;
int *mem;
protected:
BaseArray(int capacity=100){
this-> capacity = capacity; mem = new int [capacity];
}
~BaseArray() {delete [] mem; }
void put (int index, int val) { mem[index] = val; }
int get(int index) {return mem[index]; }
int getCapacity() {return capacity; }
};
class MyStack: public BaseArray {
int top;
public:
MyStack(int n):BaseArray(n){
top=0;
}
void push(int val){
put(top,val);
top++;
}
int pop(){
top--;
return get(top);
}
int capacity(){
return getCapacity();
}
int length(){
return top;
}
};
int main() {
MyStack mStack(100);
int n;
cout<< "스택에 삽입할 5개의 정수를 입력하라>> ";
for(int i=0; i<5; i++){
cin>> n;
mStack.push(n);
}
cout << "스택용량: "<< mStack.capacity() << ", 스택크기: " <<mStack.length() << endl;
cout << "스택의 모든 원소를 팝하여 출력한다>> ";
while(mStack.length() !=0){
cout<<mStack.pop() << ' ';
}
cout << endl << "스택의 현재 크기 : "<< mStack.length() << endl;
}
*/
/*
//422p NO.08
class Printer
{
string model;
string manu;
int printed;
int available;
public:
Printer() {}
Printer(string model, string manu, int available)
{
this->model=model;
this->manu=manu;
this->available=available;
}
string getmodel()
{
return model;
}
string getmanu()
{
return manu;
}
void setprinted(int page)
{
printed=page;
}
int paper()
{
return available;
}
void print(int page)
{
available-=page;
}
};
class Inkjet: public Printer
{
public:
int leftInk;
Inkjet(string model, string manu, int printed, int leftInk) : Printer(model, manu, printed)
{
this->leftInk=leftInk;
}
printInk(int page)
{
setprinted(page);
print(page);
leftInk-=page;
}
void show()
{
cout<< "잉크젯 : " << getmodel() << ", " << getmanu() << ", 남은 종이 " << paper() << "장 , 남은 잉크 " << leftInk<< endl;
}
};
class Laser: public Printer
{
public:
int toner;
Laser(string model, string manu, int printed, int toner): Printer(model, manu, printed)
{
this->toner=toner;
}
void printlaser(int page)
{
setprinted(page);
print(page);
toner-=page/2;
}
void show()
{
cout << "레이저 : " << getmodel()<< ", " << getmanu() << ", 남은 종이" << paper()<< "장, 남은 토너" << toner<< endl;
}
};
int main()
{
Inkjet n("Officejet V40", "HP", 5, 10);
Laser m("SCX-6x45", "삼성전자", 3, 20);
cout<< "현재 작동중인 2대 프린터는 아래와 같다."<<endl;
n.show();
m.show();
char a='y';
int b, c;
while(a=='y')
{
cout << "프린터(1: 잉크젯, 2: 레이저)와 매수 입력>>"<< endl;
cin >> b >> c ;
switch(b)
{
case 1:
if(n.paper()<c)
{
cout<< "용지가 부족하여 프린트할 수 없습니다."<< endl;
break;
}
else if(n.leftInk<c)
{
cout<< "잉크가 부족하여 프린트할 수 없습니다."<< endl;
break;
}
else
{
cout<< "프린트하였습니다."<<endl;
n.printInk(c);
break;
}
case 2:
if(m.paper()<c)
{
cout<< "용지가 부족하여 프린트할 수 없습니다."<< endl;
break;
}
else if(m.toner<c/2)
{
cout<< "토너가 부족하여 프린트할 수 없습니다."<< endl;
break;
}
else
{
cout<< "프린트하였습니다."<<endl;
m.printlaser(c);
break;
}
}
n.show();
m.show();
cout<< "계속 프린트 하시겠습니까(y/n)>> ";
cin >> a;
}
}
*/