[객체지향] 자판기 시뮬레이션
본 자료는 5페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
해당 자료는 5페이지 까지만 미리보기를 제공합니다.
5페이지 이후부터 다운로드 후 확인할 수 있습니다.

소개글

[객체지향] 자판기 시뮬레이션에 대한 보고서 자료입니다.

목차

1. class 구성도(Inheritance(상속)과 composition 이용)

2. 각 class 분석

3. 세부 구현방법

4. source code

본문내용

1/13, 음료확률은 3/13
int choice[13] ={0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4};
int select;
char *name[10] = {"반환", "Hot coffee", "Hot choco", "Ice tea", "Lemon tea"};
// 버튼 표시
cout << " **********************************************************************" << endl;
cout << " * 0. 반환 1. Hot coffee 2. Hot choco 3. Ice tea 4. Lemon tea *" << endl;
cout << " **********************************************************************" << endl;
if(coin < 500) // 500원 미만으로 넣었으경우 선택할수 있는 경우는 0번, 1번
select = choice[random(3)];
else if(coin < 600) // 600원 미만으로 놓었을 경우 0, 1, 2번
select = choice[random(6)];
else if(coin < 700) // 700원 미만으로 넣었을 경우 0, 1, 2, 3번
select = choice[random(9)];
else // 700원 이상으로 넣었을 경우 다 선택가능
select = choice[random(12)];
cout << " " << name[select] << "버튼을 눌렀습니다. " << endl;
switch(select){ // 선택에 따른 입금
case 1: coin -= 450;
coffee.decAmount(); // 커피 갯수 -1
break;
case 2: coin -= 500;
chocolate.decAmount(); // 초코 갯수 -1
break;
case 3: coin -= 600;
icetea.decAmount(); // 아이스 티 갯수 -1
break;
case 4: coin -= 700;
lemontea.decAmount(); // 레몬 티 갯수 -1
break;
}
if(coin > 0){
money.decCoin(coin); // coin이 남았을 경우 잔돈을 거슬러 준다.
}
}
void VendingMachine::Administer(){ // 관리자모드
time.incTime(5); // 관리자는 상품이나 돈이 떨어지면 5분위에 온다.
cout << time << endl; // 도착시간
double total = money.getDeposit(); // 현재까지 자판기에서 벌어들인 돈
cout << " 관리인이 왔습니다. " << endl;
cout << " 돈과 물건을 채워 놓는군요. " << endl;
cout << " 현재 까지 벌어들인 " << total << "원을 가져갑니다. " << endl;
coffee.setAmount(10); // 초기 설정
chocolate.setAmount(10);
icetea.setAmount(10);
lemontea.setAmount(10);
money.setCoin50(20);
money.setCoin100(20);
money.setCoin500(10);
totalIncome += total; // 하루 총 매상을 알아보기 위해 누적시킨다.
}
void VendingMachine::printStatus(){ // 자판기 상태 출력
cout << " ************************************ " << endl;
cout << setw(15) << "Hot coffee : " << setw(3) << coffee.getAmount()
<< setw(15) << "500 won : " << money.getCoin500() << endl;
cout << setw(15) << "Hot choco : " << setw(3) << chocolate.getAmount()
<< setw(15) << "100 won : " << money.getCoin100() << endl;
cout << setw(15) << "Ice tea : " << setw(3) << icetea.getAmount()
<< setw(15) << "50 won : " << money.getCoin50() << endl;
cout << setw(15) << "Lemon tea : " << setw(3) << lemontea.getAmount()
<< setw(15) << "Income : " << money.getDeposit() << endl;
cout << " ************************************ " << endl << endl << endl;
// 상품수 5개 미만, 동전수 50, 100원 10개 미만, 500 5개 미만일 경우
if(coffee.getAmount()<5 || chocolate.getAmount()<5 || icetea.getAmount()<5
|| lemontea.getAmount()<5 || money.getCoin500()<5 || money.getCoin100()<10
|| money.getCoin50()<10){
Administer(); // 관리자가 온다.
printStatus();
}
}
/**********************************************
M A I N . C P P
***********************************************/
#include
#include // time함수
#include
#include // Sleep 함수
#include "vendingmachine.h"
#define randomize() srand((unsigned)time(NULL)) // 난수 발생
void main(){
VendingMachine v; // 객체 생성
randomize();
v.Run(); // 실행
}

키워드

  • 가격2,000
  • 페이지수15페이지
  • 등록일2003.09.28
  • 저작시기2003.5
  • 파일형식한글(hwp)
  • 자료번호#225287
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니