<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>12장 on Sobamemil</title>
    <link>https://blog.sobamemil.com/tags/12%EC%9E%A5/</link>
    <description>Recent content in 12장 on Sobamemil</description>
    <generator>Hugo</generator>
    <language>ko</language>
    <lastBuildDate>Thu, 02 Apr 2020 16:58:54 +0900</lastBuildDate>
    <atom:link href="https://blog.sobamemil.com/tags/12%EC%9E%A5/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>명품 C&#43;&#43; programming 실습 문제 11장 12번</title>
      <link>https://blog.sobamemil.com/posts/143-%EB%AA%85%ED%92%88-c-programming-%EC%8B%A4%EC%8A%B5-%EB%AC%B8%EC%A0%9C-11%EC%9E%A5-12%EB%B2%88/</link>
      <pubDate>Thu, 02 Apr 2020 16:58:54 +0900</pubDate>
      <guid>https://blog.sobamemil.com/posts/143-%EB%AA%85%ED%92%88-c-programming-%EC%8B%A4%EC%8A%B5-%EB%AC%B8%EC%A0%9C-11%EC%9E%A5-12%EB%B2%88/</guid>
      <description>&lt;p&gt;&lt;strong&gt;문제 :&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;커피 자판기 시뮬레이터를 C++로 작성해보자. 실행 사례는 다음과 같다.&lt;/p&gt;
&lt;p&gt;자판기는 보통 커피, 설탕  커피, 블랙 커피의 3종류만 판매한다.&lt;/p&gt;
&lt;p&gt;단순화를 위해 실행 살에는 총 3인분의 재료만 가지도록 하였다. 커피 메뉴에 따라 필요한 재료들이 하나씩 없어진다.&lt;/p&gt;
&lt;p&gt;객체 지향 구조에 따라 필요한 클래스를 작성하여 프로그램을 완성하라.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;실행 결과 :&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img loading=&#34;lazy&#34; src=&#34;https://img.sobamemil.com/posts/143/img_1.png&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;목적 및 힌트 :&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;객체 지향 구조로 종합 응용 연습&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;코드 :&lt;/strong&gt;&lt;/p&gt;
&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;&lt;/th&gt;
          &lt;th&gt;&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;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  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99  100  101  102  103  104  105  106  107  108  109  110  111  112  113  114  115  116  117  118  119  120  121  122  123  124  125  126  127  128  129  130  131  132  133  134  135  136  137  138  139  140  141  142  143  144  145  146  147  148  149  150  151  152  153  154  155  156  157  158  159  160  161  162  163  164  165  166  167  168  169&lt;/td&gt;
          &lt;td&gt;#include &lt;iostream&gt;  #include &lt;iomanip&gt;  using namespace std;    class Material {  protected:  string name;  int amount;  public:  string getName() {  return name;  }  int getAmount() {  return amount;  }  void setAmount(int amount) {  this-&amp;gt;amount = amount;  }  bool subAmount(int amount) {  if(this-&amp;gt;amount &amp;lt;= 0)  return false;  else  this-&amp;gt;amount -= amount;  return true;  }  };    class Coffee : public Material {  public:  Coffee() {  name = &amp;ldquo;Coffee&amp;rdquo;;  amount = 3;  }  };    class Sugar : public Material {  public:  Sugar() {  name = &amp;ldquo;Sugar&amp;rdquo;;  amount = 3;  }  };    class Cream : public Material {  public:  Cream() {  name = &amp;ldquo;Cream&amp;rdquo;;  amount = 3;  }  };    class Water : public Material {  public:  Water() {  name = &amp;ldquo;Water&amp;rdquo;;  amount = 3;  }  };    class Cup : public Material {  public:  Cup() {  name = &amp;ldquo;Cup&amp;rdquo;;  amount = 3;  }  };    class CoffeeMachine {  Material *mat[]; // Material의 객체 배열 포인터 생성  public:  CoffeeMachine() { // 생성자에서 안내 멘트와 재료 상태 출력  cout &amp;laquo; &amp;ldquo;&amp;mdash;&amp;ndash;명품 커피 자판기 켭니다.&amp;mdash;&amp;ndash;&amp;rdquo; &amp;laquo; endl;  mat[0] = new Coffee();  mat[1] = new Sugar();  mat[2] = new Cream();  mat[3] = new Water();  mat[4] = new Cup();  showCoffeeMachineState();  cout &amp;laquo; endl;  }  void showCoffeeMachineState() { // 재료 상태 출력  for(int i=0; i&amp;lt;5; i++) {  cout &amp;laquo; setw(10) &amp;laquo; mat[i]-&amp;gt;getName();  for(int j=0; j&amp;lt;mat[i]-&amp;gt;getAmount(); j++)  cout &amp;laquo; &amp;ldquo;*&amp;rdquo;;  cout &amp;laquo; endl;  }  }  void start() { // 메뉴 출력 시작  int num;  while(true) {  showMenu();  num = selectMenu();  if(num == 3) { // 채우기  for(int i=0; i&amp;lt;5; i++) {  mat[i]-&amp;gt;setAmount(3);  }  cout &amp;laquo; &amp;ldquo;모든 통을 채웁니다~~&amp;rdquo; &amp;laquo; endl;  showCoffeeMachineState();  cout &amp;laquo; endl;  continue;  }  else if(num == 4) { // 종료  cout &amp;laquo; &amp;ldquo;프로그램을 종료합니다&amp;hellip;&amp;rdquo; &amp;laquo; endl;  exit(0);  }    if(mat[0]-&amp;gt;subAmount(1) == false) { // coffee-1  cout &amp;laquo; &amp;ldquo;재료가 부족합니다.&amp;rdquo; &amp;laquo; endl;  showCoffeeMachineState();  continue;  }  if(mat[3]-&amp;gt;subAmount(1) == false) { // water-1  cout &amp;laquo; &amp;ldquo;재료가 부족합니다.&amp;rdquo; &amp;laquo; endl;  showCoffeeMachineState();  continue;  }  if(mat[4]-&amp;gt;subAmount(1) == false) { // cup-1  cout &amp;laquo; &amp;ldquo;재료가 부족합니다.&amp;rdquo; &amp;laquo; endl;  showCoffeeMachineState();  continue;  }  // 기본 재료가 부족하지 않으면 실행  switch(num) {  case 0: // 보통 커피는 cream 추가 소모  if(mat[2]-&amp;gt;subAmount(1) == false) { // cream-1  cout &amp;laquo; &amp;ldquo;재료가 부족합니다.&amp;rdquo; &amp;laquo; endl;  showCoffeeMachineState();  continue;  }  cout &amp;laquo; &amp;ldquo;맛있는 보통 커피 나왔습니다~~&amp;rdquo; &amp;laquo; endl;  showCoffeeMachineState();  cout &amp;laquo; endl;  break;  case 1: // 설탕 커피는 sugar 추가 소모  if(mat[1]-&amp;gt;subAmount(1) == false) { // sugar-1  cout &amp;laquo; &amp;ldquo;재료가 부족합니다.&amp;rdquo; &amp;laquo; endl;  showCoffeeMachineState();  continue;  }  cout &amp;laquo; &amp;ldquo;맛있는 설탕 커피 나왔습니다~~&amp;rdquo; &amp;laquo; endl;  showCoffeeMachineState();  cout &amp;laquo; endl;  break;  case 2: // 블랙 커피는 추가 소모 없음  cout &amp;laquo; &amp;ldquo;맛있는 블랙 커피 나왔습니다~~&amp;rdquo; &amp;laquo; endl;  showCoffeeMachineState();  break;  default : // 잘못 입력  cout &amp;laquo; &amp;ldquo;잘못 입력 하셨습니다.&amp;rdquo; &amp;laquo; endl &amp;laquo; endl;  break;  }  }  }  void showMenu() {  cout &amp;laquo; &amp;ldquo;보통 커피:0, 설탕 커피:1, 블랙 커피:2, 채우기:3, 종료:4&amp;raquo; &amp;ldquo;;  }  int selectMenu() {  int num;  cin &amp;raquo; num;  return num;  }  };    int main() {  cout.setf(ios::left);  CoffeeMachine c;  c.start();  }&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;설명 :&lt;/strong&gt;&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
