search

Рекомендация: прочитайте задачу! Выполните ее и сравните полученный результат с картинкой CMD

Если вы полностью уверены что не можете осилить эту задачу, советую вам просмотреть код и полностью в нем разобраться! Протестировать все в отладчике!

Создать имитацию игры "однорукий бандит". Например, при нажатии кнопки «Enter» происходит «вращение» трех барабанов (естественно, количество вращений каждого из них выбирается случайно), на которых изображены разные значки; и если выпадает определенная комбинация, то игрок получает какой-то выигрыш.

//Athor Dombrovsky I.V {***}
//Academy "STEP" GROUP 32PPS21
#include <iostream>
#include <string>
#include <new>
#include <time.h>
#include <stdlib.h>
#include <Windows.h>
#define STOP_CMD system("pause"); 
#define COLOR_CMD system("color 0A"); 

/*TASK Создать имитацию игры "однорукий бандит". Например,
при нажатии кнопки «Enter» происходит «вращение»
трех барабанов (естественно, количество вращений
каждого из них выбирается случайно), на которых изображены разные значки; и если выпадает определенная
комбинация, то игрок получает какой-то выигрыш.*/

template<typename T>class Queue
{
public:
	Queue();
	Queue(int SIZE);
	~Queue();
	void addElement(T Element);
	void deleteElementQueue(); // Normal Queue
	void deleteElementQueueRing(); // Ring Queue
	void deleteElementQueuePriority(); // Priority queue
	bool checkQueue();
	void showQueue();
	T GetFirst();
	T GetLast();
	void queueRand(int min, int max);
	T sizeQueue();
	void deleteQueue();
private:
	T * arr;
	int SIZE;
	int counter;
};
template<typename T>Queue<T>::Queue() : SIZE(0), arr(NULL), counter(0)
{
	//DEFAULT
}
template<typename T> Queue<T>::Queue(int SIZE)
{
	try
	{
		this->SIZE = SIZE;
		arr = new T[this->SIZE]();
		counter = 0;
	}
	catch (std::bad_alloc &memoryAllocationException)
	{
		std::cerr << "Exception occured: [ERROR MEMORY]" << memoryAllocationException.what() << std::endl; // Fixed output
		STOP_CMD
	}
}
template<typename T> Queue<T>::~Queue()
{
	delete[] arr;
	arr = NULL;
}
template<typename T>void Queue<T>::addElement(T Element)
{
	if (this->checkQueue() != false)
	{
		this->arr[this->counter] = Element;
		this->counter++;
	}
}
template<typename T>void Queue<T>::deleteElementQueue() // Normal queue
{
	if (this->counter != 0)
	{
		T * buf = new T[this->counter]();
		for (size_t i = 0; i < this->counter; i++)
		{
			buf[i] = this->arr[i];
			this->arr[i] = 0;
		}
		for (size_t i = 0; i < this->counter - 1; i++)
		{
			this->arr[i] = buf[i + 1];
		}
		this->counter--;
		delete[] buf;
	}
	else
	{
		this->checkQueue();
	}
}
template<typename T>void Queue<T>::deleteElementQueueRing() //  Ring Queue
{
	if (this->counter != 0)
	{
		T temp = this->arr[0];
		for (size_t i = 1; i < this->counter; i++) // Copying an array without a priority item
		{
			this->arr[i - 1] = this->arr[i];
		}
		this->arr[this->counter - 1] = temp;
	}
	else
	{
		this->checkQueue();
	}
}
template<typename T>void Queue<T>::deleteElementQueuePriority() // Priority queue
{
	if (this->counter != 0)
	{
		T * buf = new T[this->counter - 1];
		T temp = this->arr[0];
		size_t count = 0, valueSameElements = 0;
		for (size_t i = 0; i < this->counter; i++) // Search Element MAX
		{
			if (temp < arr[i])
			{
				temp = arr[i];
			}
		}
		for (size_t i = 0; i < this->counter; i++) // get value same elements
		{
			if (arr[i] == temp)
				valueSameElements++;
		}
		for (size_t i = 0; i < this->counter; i++) // Copying an array without a priority item
		{
			if (this->arr[i] != temp)
			{
				buf[count] = this->arr[i];
				count++;
			}
			if (this->arr[i] == temp && valueSameElements > 1) //Protection: If the priority element is not one
			{
				buf[count] = this->arr[i];
				count++;
				valueSameElements--;
			}
		}
		for (size_t i = 0; i < this->counter - 1; i++) // Set array in main arr
		{
			this->arr[i + 1] = buf[i];
		}
		this->arr[0] = temp; // Set value in main arr index 0
		deleteElementQueue(); // DELL ELEMENT of Queue
		delete[] buf;
		count = 0;
	}
	else
	{
		this->checkQueue();
	}
}
template<typename T>bool Queue<T>::checkQueue()
{
	if (this->counter < this->SIZE)
	{
		return true;
	}
	else
	{
		//std::cerr << "Queue full:" << std::endl; 
		return false;
	}

}
template<typename T>void Queue<T>::showQueue()
{
	this->checkQueue();
	for (size_t i = 0; i < this->counter; i++)
	{
		std::cout << this->arr[i] << "\t";
	}
	std::cout << std::endl;
}
template<typename T>T Queue<T>::GetFirst()
{
	//std::cout << "First element in queue -> " << this->arr[0] << std::endl; 
	return this->arr[0];
}
template<typename T>T Queue<T>::GetLast()
{
	//std::cout << "Last element in queue -> " << this->arr[this->counter - 1] << std::endl;
}
template<typename T>void Queue<T>::queueRand(int min, int max)
{
	for (size_t i = 0; i < this->SIZE; i++)
	{
		this->arr[i] = min + rand() % (max - min + 1);
	}
	this->counter = this->SIZE;
}
template<typename T>void Queue<T>::deleteQueue()
{
	for (size_t i = 0; i < this->counter; i++)
	{
		arr[i] = 0;
	}
	this->counter = 0;
}
template<typename T>T Queue<T>::sizeQueue()
{
	std::cout << "Size queue -> " << this->SIZE << std::endl;
	std::cout << "Elements in queue -> " << this->counter << std::endl;
	return this->SIZE;
}

int checkWins(Queue<int> * one, Queue<int> * two, Queue<int> * three, int account) // CHECK WINS
{
	if (one->GetFirst() == 1 && two->GetFirst() == 1 && three->GetFirst() == 1) { account += 3; }
	if (one->GetFirst() == 2 && two->GetFirst() == 2 && three->GetFirst() == 2) { account += 5; }
	if (one->GetFirst() == 3 && two->GetFirst() == 3 && three->GetFirst() == 3) { account += 1; }
	if (one->GetFirst() == 4 && two->GetFirst() == 4 && three->GetFirst() == 4) { account += 10; }
	if (one->GetFirst() == 5 && two->GetFirst() == 5 && three->GetFirst() == 5) { account += 25; }
	if (one->GetFirst() == 6 && two->GetFirst() == 6 && three->GetFirst() == 6) { account += 15; }
	if (one->GetFirst() == 7 && two->GetFirst() == 7 && three->GetFirst() == 7) { account += 3500; }
	if (one->GetFirst() == 8 && two->GetFirst() == 8 && three->GetFirst() == 8) { account += 20; }
	if (one->GetFirst() == 9 && two->GetFirst() == 9 && three->GetFirst() == 9) { account += 53; }
	if (one->GetFirst() == 10 && two->GetFirst() == 10 && three->GetFirst() == 10) { account += 100; }
	return account;
}

int main() {
	COLOR_CMD
		SetConsoleTitle("One-armed bandit");
	system("MODE CON: COLS=80 LINES=25");
	srand(time(NULL));
	//---------------------------------------------------------------------------------------------------------------
	//		START PROGRAM CREATE QUEUE
	//---------------------------------------------------------------------------------------------------------------
	Queue<int> drum1(10), drum2(10), drum3(10);
	char start = 'y';
	int tablo[3];
	int difficulty = 7; // Difficulty of the game
	int startDifficulty = 0;
	int account = 100; // MONEY

	for (size_t i = 1; i <= 10; i++)
	{
		drum1.addElement(i);
		drum2.addElement(i);
		drum3.addElement(i);
	}
	//---------------------------------------------------------------------------------------------------------------
	//				DISPLAY
	//---------------------------------------------------------------------------------------------------------------
	while (start == 'y') {

		std::cout << "You can win only if all the first elements match! Your account = " << account << "$" << std::endl;
		std::cout << "Your budget is reduced with each click on the button for 5 dollars! " << std::endl << std::endl;
		std::cout << "1->Cherry 3$" << "   " << "2->Apple 5$" << "   " << "3->Orange 1$" << "   " << "4->Apricot 10$" << "   " << "5->Master 25$" << std::endl;
		std::cout << "6->Melon 15$" << "   " << "7->Jack pot 3500$" << "   " << "8->Banana 20$" << "   " << "9->Garnet 53$" << "   " << "10->Nuts 100$" << std::endl << std::endl;

		std::cout << "--------------------------------------------------------------------------" << std::endl;
		drum1.showQueue();
		drum2.showQueue();
		drum3.showQueue();
		std::cout << "--------------------------------------------------------------------------" << std::endl;
		//---------------------------------------------------------------------------------------------------------------
		//					DISPLAY [TABLO]
		//---------------------------------------------------------------------------------------------------------------

		tablo[0] = drum1.GetFirst();
		tablo[1] = drum2.GetFirst();
		tablo[2] = drum3.GetFirst();
		for (size_t i = 0; i < 3; i++)
		{
			std::cout << "===>>> [" << tablo[i] << "] <<<===" << "\t";
		}
		std::cout << std::endl;
		//---------------------------------------------------------------------------------------------------------------
		//					Scroll drums
		//---------------------------------------------------------------------------------------------------------------
		startDifficulty = rand() % difficulty;
		for (size_t i = 0; i < startDifficulty; i++)
		{
			drum1.deleteElementQueueRing();
		}
		startDifficulty = rand() % difficulty;
		for (size_t i = 0; i < startDifficulty; i++)
		{
			drum2.deleteElementQueueRing();
		}
		startDifficulty = rand() % difficulty;
		for (size_t i = 0; i < startDifficulty; i++)
		{
			drum3.deleteElementQueueRing();
		}

		account = checkWins(&drum1, &drum2, &drum3, account);
		//---------------------------------------------------------------------------------------------------------------
		//					START GAME
		//---------------------------------------------------------------------------------------------------------------
		std::cout << "Take money, enter [n] Continue game, enter [y]:" << std::endl;
		std::cin >> start;

		if (start == 'n')
		{
			std::cout << "Thanks for game! Bay-Bay" << std::endl;
			break;
		}
		if (start != 'n' && start != 'y')
		{
			std::cout << "Do not hit the machine!" << std::endl;
			break;
		}

		account -= 5;
		if (account == 0 || account < 0)
		{
			std::cout << "Your money is over, goodbye!" << std::endl;
			break;
		}
		system("CLS");
	}
	//---------------------------------------------------------------------------------------------------------------
	//				END
	//---------------------------------------------------------------------------------------------------------------
	STOP_CMD
		return 0;
}

dinamic_struct	
Разработать приложение, имитирующее очередь печати принтера. Должны быть клиенты, посылающие запросы на принтер, у каждого из которых есть свой приоритет. Каждый новый клиент попадает в очередь в зависимости от своего приоритета. Необходимо сохранять статистику печати (пользователь, время) в отдельной очереди. Предусмотреть вывод статистики на экран.

//Athor Dombrovsky I.V {***}
//Academy "STEP" GROUP 32PPS21
#include <iostream>
#include <new>
#include <Windows.h>
#include <string>
#include <stdio.h>      /* puts, printf */
#include <ctime>       /* time_t, struct tm, time, localtime */
#include <iomanip>
#include <stdlib.h>
#include <sstream>
#define STOP_CMD system("pause"); 
#define COLOR_CMD system("color 0A");
/*TASK
Разработать приложение, имитирующее очередь печати принтера. Должны быть клиенты, посылающие
запросы на принтер, у каждого из которых есть свой
приоритет. Каждый новый клиент попадает в очередь
в зависимости от своего приоритета. Необходимо
сохранять статистику печати (пользователь, время) в
отдельной очереди. Предусмотреть вывод статистики
на экран.
*/
//----------------------------------------------------------------------
template<typename T>class Queue
{
public:
	Queue();
	Queue(int SIZE);
	~Queue();
	void addElement(T Element);
	void deleteElementQueue(); // Normal Queue
	void deleteElementQueueRing(); // Ring Queue
	void deleteElementQueuePriority(); // Priority queue
	bool checkQueue();
	void showQueue();
	T GetFirst();
	T GetLast();
	void queueRand(int min, int max);
	int sizeQueue();
	void showStatistic();
	void deleteQueue();
private:
	T * arr;
	int SIZE;
	int counter;
};
template<typename T>Queue<T>::Queue() : SIZE(0), arr(NULL), counter(0)
{
	//DEFAULT
}
template<typename T> Queue<T>::Queue(int SIZE)
{
	try
	{
		this->SIZE = SIZE;
		arr = new T[this->SIZE]();
		counter = 0;
	}
	catch (std::bad_alloc &memoryAllocationException)
	{
		std::cerr << "Exception occured: [ERROR MEMORY]" << memoryAllocationException.what() << std::endl; // Fixed output
		STOP_CMD
	}
}
template<typename T> Queue<T>::~Queue()
{
	delete[] arr;
	arr = NULL;
}
template<typename T>void Queue<T>::addElement(T Element)
{
	if (this->checkQueue() != false)
	{
		this->arr[this->counter] = Element;
		this->counter++;
	}
}
template<typename T>void Queue<T>::deleteElementQueue() // Normal queue
{
	if (this->counter != 0)
	{
		T * buf = new T[this->counter]();
		for (size_t i = 0; i < this->counter; i++)
		{
			buf[i] = this->arr[i];
			this->arr[i] = 0;
		}
		for (size_t i = 0; i < this->counter - 1; i++)
		{
			this->arr[i] = buf[i + 1];
		}
		this->counter--;
		delete[] buf;
	}
	else
	{
		this->checkQueue();
	}
}
template<typename T>void Queue<T>::deleteElementQueueRing() //  Ring Queue
{
	if (this->counter != 0)
	{
		T temp = this->arr[0];
		for (size_t i = 1; i < this->counter; i++) // Copying an array without a priority item
		{
			this->arr[i - 1] = this->arr[i];
		}
		this->arr[this->counter - 1] = temp;
	}
	else
	{
		this->checkQueue();
	}
}
template<typename T>void Queue<T>::deleteElementQueuePriority() // Priority queue
{
	if (this->counter != 0)
	{
		T * buf = new T[this->counter - 1];
		T temp = this->arr[0];
		size_t count = 0, valueSameElements = 0;
		for (size_t i = 0; i < this->counter; i++) // Search Element MAX
		{
			if (temp < arr[i])
			{
				temp = arr[i];
			}
		}
		for (size_t i = 0; i < this->counter; i++) // get value same elements
		{
			if (arr[i] == temp)
				valueSameElements++;
		}
		for (size_t i = 0; i < this->counter; i++) // Copying an array without a priority item
		{
			if (this->arr[i] != temp)
			{
				buf[count] = this->arr[i];
				count++;
			}
			if (this->arr[i] == temp && valueSameElements > 1) //Protection: If the priority element is not one
			{
				buf[count] = this->arr[i];
				count++;
				valueSameElements--;
			}
		}
		for (size_t i = 0; i < this->counter - 1; i++) // Set array in main arr
		{
			this->arr[i + 1] = buf[i];
		}
		this->arr[0] = temp; // Set value in main arr index 0
		deleteElementQueue(); // DELL ELEMENT of Queue
		delete[] buf;
		count = 0;
	}
	else
	{
		this->checkQueue();
	}
}
template<typename T>bool Queue<T>::checkQueue()
{
	if (this->counter < this->SIZE)
	{
		return true;
	}
	else
	{
		//std::cerr << "Queue full:" << std::endl; 
		return false;
	}

}
template<typename T>void Queue<T>::showQueue()
{
	this->checkQueue();
	for (size_t i = 0; i < this->counter; i++)
	{
		std::cout << this->arr[i] << "\t";
	}
	std::cout << std::endl;
}
template<typename T>T Queue<T>::GetFirst()
{
	//std::cout << "First element in queue -> " << this->arr[0] << std::endl; 
	return this->arr[0];
}
template<typename T>T Queue<T>::GetLast()
{
	//std::cout << "Last element in queue -> " << this->arr[this->counter - 1] << std::endl;
}
template<typename T>void Queue<T>::queueRand(int min, int max)
{
	for (size_t i = 0; i < this->SIZE; i++)
	{
		this->arr[i] = min + rand() % (max - min + 1);
	}
	this->counter = this->SIZE;
}
template<typename T>void Queue<T>::deleteQueue()
{
	for (size_t i = 0; i < this->counter; i++)
	{
		arr[i] = 0;
	}
	this->counter = 0;
}
template<typename T>int Queue<T>::sizeQueue()
{
	std::cout << "Size queue -> " << this->SIZE << std::endl;
	std::cout << "Elements in queue -> " << this->counter << std::endl;
	return this->SIZE;
}
//----------------------------------------------------------------------
class Time
{
public:
	Time() :minutes(0), hours(0), seconds(0) {}
	Time(int h, int m, int s) {
		this->hours = h;
		this->minutes = m;
		this->seconds = s;
	}
	void show() { std::cout << "Time -> " << hours << ":" << minutes << ":" << seconds << std::endl; }
	void setHours(int h) { if (h <= 12 && h >= 0 || h <= 24 && h >= 0) this->hours = h; }
	void setMinutes(int m) { if (m <= 60 && m >= 0) this->minutes = m; }
	void setSeconds(int s) { if (s <= 60 && s >= 0) this->seconds = s; }
	int getHours() { return this->hours; }
	int getMinutes() { return this->minutes; }
	int getSeconds() { return this->seconds; }
private:
	int minutes;
	int hours;
	int seconds;
};
//----------------------------------------------------------------------
class Users
{
public:
	Users();
	Users(std::string name, std::string surname, int age, int numberSheets, Time * time, int priority);
	void show();
	void setName(std::string name);
	std::string getName();
	void setSurname(std::string surname);
	std::string getSurname();
	void setAge(int age);
	int getAge();
	void setNumberSheets(int numberSheets);
	int getNumberSheets();
	void setTime(int h, int m, int s);
	Time & getTime();
	void setPriority(int priority);
	int getPriority();
private:
	std::string name;
	std::string surname;
	int age;
	int numberSheets;
	Time * time;
	int priority;
};

Users::Users() :age(0), numberSheets(0)
{
	//DEFAULT
}

Users::Users(std::string name, std::string surname, int age, int numberSheets, Time * time, int priority)
{
	this->name = name;
	this->surname = surname;
	this->age = age;
	this->numberSheets = numberSheets;
	this->time = time;
	this->priority = priority;
}
void Users::show()
{
	std::cout << "User" << std::endl;
	std::cout << "Name -> " << this->getName() << std::endl;
	std::cout << "Surname -> " << this->getSurname() << std::endl;
	std::cout << "Age -> " << this->getAge() << std::endl;
	std::cout << "Sent to printer -> " << this->getNumberSheets() << std::endl;
	this->time->show();
	std::cout << "Priority -> " << this->getPriority() << std::endl;
}
void Users::setName(std::string name)
{
	this->name = name;
}
std::string Users::getName()
{
	return this->name;
}
void Users::setSurname(std::string surname)
{
	this->surname = surname;
}
std::string Users::getSurname()
{
	return this->surname;
}
void Users::setAge(int age)
{
	this->age = age;
}
int Users::getAge()
{
	return this->age;
}
void Users::setNumberSheets(int numberSheets)
{
	this->numberSheets = numberSheets;
}
int Users::getNumberSheets()
{
	return this->numberSheets;
}
void Users::setTime(int h, int m, int s)
{
	this->time->setHours(h);
	this->time->setMinutes(m);
	this->time->setSeconds(s);
}
Time & Users::getTime() {
	return *time;
}
void Users::setPriority(int priority)
{
	this->priority = priority;
}
int Users::getPriority()
{
	return this->priority;
}
//----------------------------------------------------------------------
int main() {
	COLOR_CMD

		char symbol = 0;

	std::cout << "--------------------------------------" << std::endl;
	Time time(12, 52, 35);
	Users u = { "Igor", "Dombrovsky", 29, 35,  &time, 15 };
	u.show();
	std::cout << "--------------------------------------" << std::endl;
	Time time1(10, 24, 27);
	Users u1 = { "Elena", "Petrova", 28, 78,  &time1, 25 };
	u1.show();
	std::cout << "--------------------------------------" << std::endl;
	Time time2(12, 52, 35);
	Users u2 = { "Petro", "Trefaldo", 35, 15,  &time2, 8 };
	u2.show();
	std::cout << "--------------------------------------" << std::endl;

	std::cout << "Send document to printer enter [y]:" << std::endl;
	std::cin >> symbol;
	if (symbol == 'y')
	{
		Queue<int> printer(3);
		printer.addElement(u.getPriority());
		printer.addElement(u1.getPriority());
		printer.addElement(u2.getPriority());
		std::cout << "--------------------------------------" << std::endl;
		printer.showQueue();
		std::cout << "--------------------------------------" << std::endl;
		printer.deleteElementQueuePriority();
		std::cout << "--------------------------------------" << std::endl;
		printer.showQueue();
		std::cout << "--------------------------------------" << std::endl;
		printer.deleteElementQueuePriority();
		std::cout << "--------------------------------------" << std::endl;
		printer.showQueue();
		std::cout << "--------------------------------------" << std::endl;
		printer.deleteElementQueuePriority();
		std::cout << "--------------------------------------" << std::endl;
		printer.showQueue();
		std::cout << "--------------------------------------" << std::endl;
	}
	else
	{
		std::cerr << "Error input!" << std::endl;
	}
	STOP_CMD
		return 0;
}

dinamic_struct