Exemplo n.º 1
0
int main()
{
	IoHandler ioh;
	MatrixGraph mg;
	ListGraph lg;
	TaskManager tm;

	while (1)
	{
		char menu = ioh.getMenu();

		switch (menu)
		{
		case 's': // 탐색
		case 'S':
			tm.searchGraph(mg, lg);
			break;
		case 'm':	// 최소비용 신장트리
		case 'M':
			break;
		case 't':	// 위상정렬
		case 'T':
			break;
		case 'q':	// 종료
		case 'Q':
			exit(1);
		}

	}

	system("pause");
	return 0;
}
Exemplo n.º 2
0
unsigned long IoThread::userFunc(const double dt)
{
   IoHandler* ioHandler = static_cast<IoHandler*>(getParent());
   ioHandler->inputDevicesImp( static_cast<double>(dt) );
   ioHandler->outputDevicesImp( static_cast<double>(dt) );
   return 0;
}
void Taskmanager::printMenu(Day &day, Day &dDay)
{
	IoHandler ioh;
	while (true)
	{
		try
		{
			printDay(day, dDay);

			string inputData = ioh.inputMenu("날짜 이동(년월일, (다음날)+, (전날)-), D-day 계산(+/- 날짜), 종료(Q) : ");

			if (inputData == "q" || inputData == "Q")
			{
				break;
			}

			int menu = checkInputData(inputData);

			switch (menu)
			{

				//하루이동
			case ONE_DAY_MOVE:
			{
				oneDayMove(day, dDay, inputData);
				break;
			}

			//DDay지정
			case SET_D_DAY:
			{
				setDDay(day, dDay);
				break;
			}

			//지정날짜이동
			case SET_DAY:
			{
				setDay(day, dDay, inputData);
				break;
			}

			default:
			{
				ioh.putMsg("잘못된 기능 입력");
				ioh.putNewLine();
				break;
			}
			}
		}
		catch (string error)
		{
			ioh.putMsg(error);
			ioh.putNewLine();
		}

		ioh.putNewLine();
	}
	ioh.putNewLine();
}
Exemplo n.º 4
0
void SetsGraph::setGraph(int numberOfElements)
{
	if (numberOfElements < 2)
	{
		IoHandler ioh;
		ioh.putString("Must have at least 2 elements.");
		ioh.putNewLine();
	}

	size = numberOfElements;
	parent = new int[size];
	for (int i = 0; i < numberOfElements; ++i)
	{
		parent[i] = -1;	// 모든 원소가 집합
	}
}
Exemplo n.º 5
0
void MatrixGraph::displayMatrix(MatrixGraph& mg)
{
	IoHandler ioh;

	string fileName = ioh.getString("무방향 그래프가 저장된 파일명을 입력하시오.(종료는 quit) : ");
	if (fileName == "quit")
	{
		exit(1);
	}
	FileHandler fh;

	fh.loadMatrixGraph(fileName, mg);

	ioh.putString("입력된 그래프의 인접 행렬 표현");
	ioh.putNewLine();

	mg.printMatrix();
	ioh.putNewLine();

	mg.dfs();
	ioh.putNewLine();

	mg.bfs();
	ioh.putNewLine();
}
void Taskmanager::printDay(Day &day, Day &dDay)
{
	IoHandler ioh;

	ioh.putMsg("[현재날짜] ");
	ioh.printDay(day);

	if (isExistDDay)
	{
		ioh.putMsg("[D");
		ioh.putChar(oper);
		ioh.putNum(difference);
		ioh.putMsg("] ");
		ioh.printDay(dDay);
	}
	else
	{
		ioh.putMsg("[D-day 없음]");
	}

	ioh.putNewLine();
}
Exemplo n.º 7
0
void MatrixGraph::printMatrix()
{
	IoHandler ioh;
	for (int i = 0; i < size; i++)
	{
		for (int j = 0; j < size; j++)
		{
			if (adjMatrix[i][j] == true)
			{
				ioh.putInteger(1);
				ioh.putString(" ");
			}
			else
			{
				ioh.putInteger(0);
				ioh.putString(" ");
			}
		}
		ioh.putNewLine();
	}
}
Exemplo n.º 8
0
int main()
{
	StudentList stdList;
	BookList bookList;
	LendList lendList;

	IoHandler ioh;

	ioh.loadStd("std.txt", stdList);
	ioh.loadBook("book.txt", bookList);
	ioh.loadLend("lend.txt", lendList);

	Taskmanager tm(stdList, bookList, lendList);

	int menu;
	while (true)
	{
		menu = ioh.putMenu();

		switch (menu)
		{
		case 1:	//대출
		{
			ioh.putMsg("학번과 도서명 입력 --- ");
			int stdNum =  ioh.inputNum();
			string bookName = ioh.inputMsg();

			tm.lendBook(stdNum, bookName);
			ioh.putNewLine();

			break;
		}
		case 2:	//반납
		{
			ioh.putMsg("학번과 도서명 입력 --- ");
			int stdNum = ioh.inputNum();
			string bookName = ioh.inputMsg();

			tm.returnBook(stdNum, bookName);
			ioh.putNewLine();

			break;
		}
		case 3:	//현황
		{
			tm.printLendList();
			break;
		}
		case 4:	//종료
		{
			tm.saveLendList("lend.txt");
			ioh.putMsg("대출 - 반납 상황을 저장하고 종료합니다.");

			return 0;
		}
		default:
		{
			ioh.putMsg("1 ~ 4중에 선택하세요.");
			ioh.putNewLine();
			break;
		}
		}
	}
}
void Taskmanager::startHangmanGame(HangmanGame &hg, WordList &wordList)
{
	IoHandler ioh;
	char a;

	hg.makeQuestion(wordList);

	string lowerQuestion = upperToLower(hg.getQuestionWord());
	
	string lowerInputData;

	hg.setUsableLetter();
	hg.setFindLetter();
	
	hg.endGame();		//hangmancount = 0

	while (true)
	{
		hg.putGameHeader(currentUser);
		hg.putHangman();
		hg.putQuestion();

		hg.putUsableLetter();

		ioh.putNewLine();
		ioh.putNewLine();


		lowerInputData = upperToLower(ioh.inputLetter("알파벳이나 전체 단어를 입력하세요. [A - z 또는 단어] : "));
		hg.setInputWord(lowerInputData);

		if (isOverlap(hg))
		{
			cin >> a;
			continue;
		}

		
		if (hg.isCorrect() == true)
		{
			if (hg.isWin() == true)
			{
				hg.putGameHeader(currentUser);
				hg.putHangman();
				hg.putQuestion();

				hg.putUsableLetter();

				ioh.putNewLine();
				ioh.putNewLine();

				ioh.putMsg("단어찾기에 성공하셨습니다!! 계속하시려면 아무 키나 입력하세요.");
				cin >> a;

				currentUserScore(true);
				break;
			}
		}
		else
		{
			if (hg.isWin() != true && hg.isLose() == true)
Exemplo n.º 10
0
void MatrixGraph::dfs()
{
	bool* visit = new bool[size];
	memset(visit, false, size);
	Stack<int> tstack;
	Stack<int> stack;

	int visited = 0;	//	0번 vertex부터 출발
	visit[visited] = true;
	stack.Push(visited);
	tstack.Push(visited);

	int connecctComponent = 1;	//	연결요소 개수

	IoHandler ioh;
	ioh.putString("인접행렬 + DFS");
	ioh.putNewLine();

	for (int i = 0; i < size; i++)
	{
		for (int j = 0; j < size; j++)
		{
			if (adjMatrix[i][j] == true)	//	간선이 있으면
			{
				if (visit[j] == false)	//	방문하지 않은 곳이면
				{
					visit[j] = true;
					stack.Push(j);	//	방문한 곳 Push
					tstack.Push(j);
					int temp = i;
					i = j;
					j = temp;
					j = j - 1;
				}
			}
		}

		if (stack.IsEmpty() == false)
		{
			i = stack.Top();
			i = i - 1;
			stack.Pop();
			continue;
		}

		while (1)
		{	//	출력하기 위해 임시 스텍에 연결요소를 옮겨담음
			stack.Push(tstack.Top());
			tstack.Pop();

			if (tstack.IsEmpty() == true)
			{
				break;
			}
		}

		ioh.putString("연결요소");
		ioh.putInteger(connecctComponent++);
		ioh.putString(" - ");

		while (1)
		{	//	출력
			ioh.printConnectedComponent(stack.Top());
			stack.Pop();

			if (stack.IsEmpty() == true)
			{
				break;
			}
		}
		ioh.putNewLine();

		//	종료 조건
		int flag = 0;
		for (int j = 0; j < size; j++)
		{
			if (visit[j] == true)
			{
				flag++;
			}
		}
		if (flag == size)
		{
			break;
		}

		//	방문하지 않은 vertex로 이동
		for (int j = 0; j < size; j++)
		{
			if (visit[j] == false)
			{
				visit[j] = true;
				tstack.Push(j);
				i = j;
				i = i - 1;
				break;
			}
		}
	}	//	for end

	delete[] visit;
	return;
}
Exemplo n.º 11
0
void MatrixGraph::bfs()
{
	bool* visit = new bool[size];
	memset(visit, false, size);
	Queue<int> queue;

	int visited = 0;	//	0번 vertex부터 출발
	visit[visited] = true;

	queue.Push(visited);

	int connecctComponent = 1;	//	연결요소 개수

	IoHandler ioh;
	ioh.putString("인접행렬 + BFS");
	ioh.putNewLine();

	for (int i = 0; i < size; i++)
	{

		//	다음 vertex로 넘어왔는데 false면 연결요소가 끊어진 것
		if (visit[i] == false)
		{
			ioh.putString("연결요소");
			ioh.putInteger(connecctComponent++);
			ioh.putString(" - ");

			while (1)
			{	//	출력
				ioh.printConnectedComponent(queue.Front());
				queue.Pop();

				if (queue.isEmpty() == true)
				{
					break;
				}
			}
			ioh.putNewLine();
		}

		if (visit[i] == false)
		{
			visit[i] = true;
			queue.Push(i);
		}


		for (int j = 0; j < size; j++)
		{
			if (adjMatrix[i][j] == true)
			{
				if (visit[j] == false)
				{
					visit[j] = true;
					queue.Push(j);
				}
			}
		}
	}	//	for end

	if (queue.isEmpty() == false)
	{
		ioh.putString("연결요소");
		ioh.putInteger(connecctComponent++);
		ioh.putString(" - ");

		while (1)
		{	//	출력
			ioh.printConnectedComponent(queue.Front());
			queue.Pop();

			if (queue.isEmpty() == true)
			{
				break;
			}
		}
		ioh.putNewLine();
	}

	return;
}
Exemplo n.º 12
0
int main()
{
	IoHandler ioh;

	Taskmanager tm;
	HangmanGame hg;

	char menu;

	//-------소켓 라이브러리 불러오기--------
	WSADATA wsaData;
	int retval = WSAStartup(MAKEWORD(2, 2), &wsaData);
	if (retval != 0)
	{
		ioh.putMsg("WSAStartup() Error\n");
		return 0;
	}

	//---------소켓생성-------- 
	SOCKET servSock = socket(PF_INET, SOCK_STREAM, 0);	//TCP를 이용한 소켓

	//---------서버 정보 입력--------------------
	string ip = ioh.inputStr("서버의 IP주소를 입력하세요 : ");
	int port = ioh.inputNum("서버의 포트번호를 입력하세요 : ");

	SOCKADDR_IN servAddr;
	servAddr.sin_family = AF_INET;						// IP주소를 이용
	servAddr.sin_addr.s_addr = inet_addr(ip.c_str());	// 서버의 ip주소
	servAddr.sin_port = htons(port);					// 소켓

	//---------서버 연결------------
	retval = connect(servSock, (SOCKADDR*)&servAddr, sizeof(servAddr));
	if (retval == SOCKET_ERROR)
	{
		ioh.putMsg("connect() Error\n");
		return 0;
	}

	ioh.putMsg("행맨 서버에 접속중...");

	User currentUser = ioh.printUserMenu(servSock);

	tm.setCurrentUser(currentUser);

	while (true)
	{
		ioh.printMenuHeader(tm.getCurrentUser(), tm.getCurrentWin(), tm.getCurrentLose());

		menu = tm.selectMenu(ioh.inputMenu(tm.getCurrentUser()), hg, servSock);

		if (menu == 'Q' || menu == 'Z')
		{
			recv(servSock, &menu, 1, 0);
			break;
		}
	}

	///////////////////////////////////////////////////
	//----------소켓 닫음------------------
	closesocket(servSock);

	//---------라이브러리 해제---------
	WSACleanup();

	system("pause");
}