U E D R , A S I H C RSS

보드카페 관리 프로그램/강석우

~cpp 
#include <ctime> 
#include <iostream> 
#include <stdexcept>
#include <string>
#include <VECTOR>

using namespace std; 

struct board{
	string table;
	string game;
	int person;
	int hour;
	int minute;
	int drink;
};

void input(board& bg, vector<board>& vec);
void in(board& bg, vector<board>& vec);
void play(board& bg, vector<board>& vec);
void buy(board& bg, vector<board>& vec);
void out(board& bg, vector<board>& vec);
void print_time(int& hour, int& minute);
int price(vector<board>& vec, int hour, int minute, const int& i);


const string tables[] ={"table1", "table2", "table3"};
const string games[] = {"jenga", "citadell", "pit"};

int main() 
{
	board bg;
	bg.drink = 0;
	vector<board> vec;
	vec.resize(3);
	
	input(bg, vec);
	
	return 0;
} 


void input(board& bg, vector<board>& vec)
{
	string command;
	while(cin >> command)
	{
		try
		{
			if (command == "exit")
				break;
			if (command =="in")
				in(bg, vec);
			else if(command =="play")
				play(bg, vec);
			else if(command =="out")
				out(bg, vec);
			else if(command =="buy")
				buy(bg, vec);
			
			else
				throw domain_error("잘못 입력하셨습니다.");
		}
		catch(domain_error e)
		{
			cout << e.what() << endl;
		}
	}
}

void in(board& bg, vector<board>& vec)
{
	cin >> bg.table;
	for (int i = 0 ; i < 3 ; i++)
	{
		if(tables[i] == bg.table)
		{
			if (vec[i].table == bg.table)
			{
				throw domain_error("그 테이블은 사용중 입니다.");
				return;
			}
			else
			{
				cin >> bg.person;
				if (bg.person > 0 && bg.person < 5)
				{
					vec[i].table = bg.table;
					int hour, minute;
					print_time(hour, minute);
					bg.hour = hour;
					bg.minute = minute;
					vec[i].hour = bg.hour;
					vec[i].minute = bg.minute;
					cout << bg.table << " : " << bg.person << "person : " << vec[i].hour << ":" 
						<<vec[i].minute << endl;
					vec[i].person = bg.person;
				}
				else
				{
					throw domain_error("사람은 4명까지만 할 수 있습니다.");
					vec.pop_back();
				}
				return;
			}
		}
		else if (i == 2 && tables[i] != bg.table)
			throw domain_error("테이블은 3번까지만 있습니다.");
		
	}

}	
void play(board& bg, vector<board>& vec)
{
	cin >> bg.table;
	for(int i = 0; i < 3 ;i++)
	{
		if(vec[i].table == bg.table)
		{
			cin >> bg.game;
			for (int j =0; j < 3; j++)
			{
				if (games[j] == bg.game)
				{
					vec[i].game = bg.game;

					if (vec[i-1].game == vec[i].game)
					{
						throw domain_error("그 게임은 사용중 입니다.");
						vec[i].game = ' ';
						return;	
					}
					else
					{
						cout << vec[i].table << "  " << bg.game << " " << "play" << endl;
						return;
					}

											
				}
				else if (j == 2 && games[j] != bg.game)
				{
					throw domain_error("그런 게임은 없습니다. ");
					return;
				}
			
			}
		}
		else if(i == 2 && vec[i].table != bg.table)
			throw domain_error("in을 먼저 입력하십시오.");
	}
}

void buy(board&bg, vector<board>& vec)
{
	cin >> bg.table;
	for(int i = 0; i < 3 ;i++)
	{
		if(vec[i].table == bg.table)
		{
			cin >> bg.drink;
			if(bg.drink > 0)
			{
				cout << vec[i].table << " buy " << bg.drink << "drink" << endl;
				vec[i].drink = bg.drink;
			}
			else
			{
				throw domain_error("잘못 입력하셨습니다.");
				vec[i].drink = 0;
			}
			return;
		}
		else if(i == 2 && vec[i].table != bg.table)
			throw domain_error("in을 먼저 입력하십시오.");
	}
}

void out(board& bg, vector<board>& vec)
{
	cin >> bg.table;
	for (int i =0; i < 3 ;i++)
	{
		int hour, minute;
		print_time(hour, minute);

		if(vec[i].table == bg.table)
		{
			cout << vec[i].hour << ":" << vec[i].minute << " ~ " << hour << ":" << minute << " : " 
				<< vec[i].person << "Person : " << price(vec, hour, minute, i) << "won" << endl;
			vec.erase(vec.begin() + i);
			return;
		}
		else if(i ==2 && vec[i].table != bg.table)
			throw domain_error("in을 먼저 입력하십시오.");
	}
	
}

void print_time(int& hour, int& minute)
{
    time_t current; 
    tm *today; 

    time(&current); 
    today = localtime(&current); 

    hour = today->tm_hour;
    minute = today->tm_min; 
}

int price(vector<board>& vec, int hour, int minute, const int& i)
{
	hour -= vec[i].hour;
	minute -= vec[i].minute;
	if (minute < 0)
	{
		hour--;
		minute += 60;
	}

	return (hour * 1600 + (minute / 30) * 800) * vec[i].person + (vec[i].drink * 500);
}


드카페 관리 프로그램, 강석우
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:36
Processing time 0.0167 sec