Code

[Absolute C++] Ch7-4

BIGFROG 2019. 9. 19. 11:18
#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;
}

'Code' 카테고리의 다른 글

[Absolute C++] Ch1-8  (0) 2019.09.19
[Absolute C++] Ch2-3  (0) 2019.09.19
[Absolute C++] Ch6-3  (0) 2019.09.19
[Absolute C++] Ch10-2  (0) 2019.09.19
[Absolute C++] Ch14-9  (0) 2019.09.19