C++ 11-12 커피 자판기 프로그램

혜준·2024년 6월 14일
post-thumbnail

#include <iostream>
#include <string>

using namespace std;

class Coffee{
    int coffee,sugar,cream,water,cup;
    
public: 
    Coffee(int coffee=3,int sugar=3,int cream=3,int water=3,int cup=3){
        this->coffee=coffee;
        this->sugar=sugar;
        this->cream=cream;
        this->water=water;
        this->cup=cup;
    }

    void print_out(){
        cout<<"----- 명품 커피 자판기 켭니다. ----"<<endl;
        cout<<"Coffee ***"<<endl;
        cout<<"Sugar  ***"<<endl;
        cout<<"CREAM  ***"<<endl;
        cout<<"Water  ***"<<endl;
        cout<<"Cup    ***"<<endl;
    }

    void end(){
        cout<<"종료합니다."<<endl;
    }

    void show(){
        cout<<"Coffee ";
         for(int i=0; i<coffee; i++){
            cout<<"*";
        }
        cout<<endl;

        cout<<"Sugar  ";
        for(int i=0; i<sugar; i++){
            cout<<"*";
        }
        cout<<endl;

        cout<<"Cream  ";
        for(int i=0; i<cream; i++){
            cout<<"*";
        }
        cout<<endl;

        cout<<"Water  ";
        for(int i=0; i<water; i++){
            cout<<"*";
        }

        cout<<endl;

        cout<<"Cup    ";
        for(int i=0; i<cup; i++){
            cout<<"*";
        }

        cout<<endl;
    }

    void usualCoffee(){
        coffee--;
        sugar--;
        water--;
        cup--;
    }

    void sugar_Coffee(){
        cout<<"맛있는 설탕 커피 나왔습니다~~"<<endl;
        coffee--;
        sugar--;
        water--;
        cup--;
    }

    void add(){
        coffee=3;
        sugar=3;
        cream=3;
        water=3;
        cup=3;
    }

    void black_coffee(){
        cout<<"블랙 커피 나왔습니다."<<endl;
        water--;
        coffee--;
        cup--;
    }
};

int main(){
    
    Coffee c;
    c.print_out();

    int num=0;
    while(true){
        cout<<"보통 커피:0, 설탕 커피:1, 블랙 커피:2, 채우기:3, 종료:4>>";
        cin>>num;
        
        switch(num){
        case 0:
            c.usualCoffee();
            break;
        case 1:
            c.sugar_Coffee();
            break;
        case 2:
            c.black_coffee();
            break;
        case 3:
            c.add();
            break;
        case 4:
            c.end();
            return 0;
            break;
        }

        c.show();
    }

    return 0;
}
profile
성장을 추구하는 개발자 입니다 :)

0개의 댓글