[Absolute C++]Ch7-4


 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
#include <iostream>

using namespace std;

class HotDogStand {
public:
 HotDogStand(int ID_value);
 int JustSold();
 static int GetTotal();

private:
 int ID;
 int soldcount;
 static int total;
};

int HotDogStand::total = 0;

HotDogStand::HotDogStand(int ID_value)
 :ID(ID_value), soldcount(0)
{

}
int HotDogStand::GetTotal() {
 total++;
 //cout << "total is " << total << endl;
 return total;
}

int HotDogStand::JustSold() {
 soldcount++;
 cout <<"영업점 "<< ID << "에서 판매한 핫도그의 수 : "<<soldcount << endl;
 GetTotal();
 return soldcount;
}

int main() {
 HotDogStand h1(1);
 HotDogStand h2(2);
 HotDogStand h3(3);
 

 int id;

 while (1) {
  cout << "영업지점(1~3)을 선택하세요.\n"<<"프로그램을 종료하려면 '0'를 입력하세요.\n";
  cin >> id;
  if (id == 0)
   break;
  else if (id == 1)
   h1.JustSold();
  else if (id == 2)
   h2.JustSold();
  else if (id == 3)
   h3.JustSold();
  else
   cout << "없는 지점입니다." << endl;

 }
 cout << "총 판매한 핫도그의 수 : " << HotDogStand::GetTotal() << endl;
 cout << "프로그램을 종료합니다." << endl;
 return 0;
}

댓글