コード例 #1
0
ファイル: Combined.cpp プロジェクト: scottliu77/COP3503Team17
//method that generates a questionnaire for the customer to fill out.
void recGift(vector<items> & vectorOfItems, vector<items> & recommendedItems, Customer & user) {
	string userchoice = "";
	int userpref = 0;
	int creativity = 0;
	int activity = 0;
	int complexity = 0;
	string tempchoice = "";
	recommendedItems.clear();
	cout << "Please answer the following questions with either a 1 or 2 so we can match you to your perfect item" << endl;
	cout << endl << "Would you rather 1. paint a picture or 2. ride a bike?" << endl;
	getline(cin, tempchoice);

	getline(cin, userchoice);
	userpref = atoi(userchoice.c_str());
	while (!isNumber(userchoice) || (userpref != 1 && userpref != 2))
	{
		cout << "Not a valid choice. Please enter 1 or 2." << endl;
		getline(cin, userchoice);
		if (isNumber(userchoice))
		{
			userpref = atoi(userchoice.c_str());
		}
	}
	if (userpref == 1) {
		creativity += 3;
		activity -= 1;
	}
	else if (userpref == 2) {
		activity += 3;
	}
	cout << endl << "Can you solve a Rubiks Cube? 1. yes 2. no" << endl;
	userpref = 0;
	getline(cin, userchoice);
	userpref = atoi(userchoice.c_str());
	while (!isNumber(userchoice) || (userpref != 1 && userpref != 2))
	{
		cout << endl << "Not a valid choice. Please enter 1 or 2." << endl;
		getline(cin, userchoice);
		if (isNumber(userchoice))
		{
			userpref = atoi(userchoice.c_str());
		}
	}
	if (userpref == 1) {
		complexity += 2;
	}
	else if (userpref == 2) {
		complexity -= 1;
	}
	cout << endl << "Have you ever watched a Marvel movie? 1. yes 2. no " << endl;
	userpref = 0;
	getline(cin, userchoice);
	userpref = atoi(userchoice.c_str());
	while (!isNumber(userchoice) || (userpref != 1 && userpref != 2))
	{
		cout << "Not a valid choice. Please enter 1 or 2." << endl;
		getline(cin, userchoice);
		if (isNumber(userchoice))
		{
			userpref = atoi(userchoice.c_str());
		}
	}
	if (userpref == 1) {
		creativity += 1;
	}
	cout << endl << "Can you see yourself skydiving? 1. yes 2. no" << endl;
	userpref = 0;
	getline(cin, userchoice);
	userpref = atoi(userchoice.c_str());
	while (!isNumber(userchoice) || (userpref != 1 && userpref != 2))
	{
		cout << "Not a valid choice. Please enter 1 or 2." << endl;
		getline(cin, userchoice);
		if (isNumber(userchoice))
		{
			userpref = atoi(userchoice.c_str());
		}
	}
	if (userpref == 1) {
		activity += 3;
	}
	cout << endl << "Is your spirit animal moreso 1. a cheetah or 2. a sloth" << endl;
	userpref = 0;
	getline(cin, userchoice);
	userpref = atoi(userchoice.c_str());
	while (!isNumber(userchoice) || (userpref != 1 && userpref != 2))
	{
		cout << "Not a valid choice. Please enter 1 or 2." << endl;
		getline(cin, userchoice);
		if (isNumber(userchoice))
		{
			userpref = atoi(userchoice.c_str());
		}
	}
	if (userpref == 1) {
		activity += 2;
	}
	else if (userpref == 2) {
		activity -= 2;
	}
	cout << endl << "Do you believe in aliens? 1. yes 2. no" << endl;
	userpref = 0;
	getline(cin, userchoice);
	userpref = atoi(userchoice.c_str());
	while (!isNumber(userchoice) || (userpref != 1 && userpref != 2))
	{
		cout << "Not a valid choice. Please enter 1 or 2." << endl;
		getline(cin, userchoice);
		if (isNumber(userchoice))
		{
			userpref = atoi(userchoice.c_str());
		}
	}
	if (userpref == 1) {
		creativity += 2;
		complexity += 1;
	}
	cout << endl << "Can you do a backflip? 1. yes 2. no" << endl;
	userpref = 0;
	getline(cin, userchoice);
	userpref = atoi(userchoice.c_str());
	while (!isNumber(userchoice) || (userpref != 1 && userpref != 2))
	{
		cout << "Not a valid choice. Please enter 1 or 2." << endl;
		getline(cin, userchoice);
		if (isNumber(userchoice))
		{
			userpref = atoi(userchoice.c_str());
		}
	}
	if (userpref == 1) {
		activity += 4;
	}
	cout << endl << "1. Super Smash or 2. volleyball?" << endl;
	userpref = 0;
	getline(cin, userchoice);
	userpref = atoi(userchoice.c_str());
	while (!isNumber(userchoice) || (userpref != 1 && userpref != 2))
	{
		cout << "Not a valid choice. Please enter 1 or 2." << endl;
		getline(cin, userchoice);
		if (isNumber(userchoice))
		{
			userpref = atoi(userchoice.c_str());
		}
	}
	if (userpref == 1) {
		creativity += 2;
		activity -= 1;
	}
	else if (userpref == 2) {
		activity += 2;
	}
	cout << endl << "Would you rather 1. become a sentient strawberry with the mind you have now (cannot communicate or have mobility) or 2. just become a regular strawberry with strawberry thoughts?" << endl;
	userpref = 0;
	getline(cin, userchoice);
	userpref = atoi(userchoice.c_str());
	while (!isNumber(userchoice) || (userpref != 1 && userpref != 2))
	{
		cout << "Not a valid choice. Please enter 1 or 2." << endl;
		getline(cin, userchoice);
		if (isNumber(userchoice))
		{
			userpref = atoi(userchoice.c_str());
		}
	}
	if (userpref == 1) {
		creativity += 1;
		activity += 1;
	}
	else if (userpref == 2) {
		activity -= 2;
	}

	if (complexity > 5) {
		complexity = 5;
	}
	if (creativity > 5) {
		creativity = 5;
	}
	if (activity > 5) {
		activity = 5;
	}
	if (complexity < 0) {
		complexity = 0;
	}
	if (creativity < 0) {
		creativity = 0;
	}
	if (activity < 0) {
		activity = 0;
	}

	bestFitItem(recommendedItems, vectorOfItems, creativity, activity, complexity);
	cout << endl << "The following are your survey results:" << endl;
	cout << "Activity: " << activity << endl;
	cout << "Creativity: " << creativity << endl;
	cout << "Complexity: " << complexity << endl;
	cout << "The following items are recommended for you:" << endl;
	for (size_t i = 0; i < recommendedItems.size(); i++) {
		cout << "Item: " << recommendedItems[i].getItemName() << endl;
		cout << "\tPrice: $" << recommendedItems[i].getItemPrice() << endl;
		if (user.noMoreMoney(recommendedItems[i].getItemPrice())) {
			cout << "\tWarning! This item is over your budget!" << endl;
		}
	}
	cout << endl;
}	
コード例 #2
0
ファイル: Combined.cpp プロジェクト: scottliu77/COP3503Team17
void purchaseItem(vector<items> & vectorOfItems, Customer & user) {
	int count = 0;
	int index;
	string input;
	string temp;
	cout << "Enter the name of the item: " << endl;
	getline(cin, temp);
	getline(cin, input);
	for (unsigned int i = 0; i < input.length(); i++)
	{
		input[i] = tolower(input[i]);
	}
	bool isInStock = false;
	for (size_t i = 0; i < vectorOfItems.size(); i++)
	{
		if (vectorOfItems[i].getItemName() == input) {
			isInStock = true;
			index = i;
			count++;
		}
	}
	if (!isInStock) {
		cout << "Sorry, that item is not in stock" << endl;
	}
	else {
		cout << "We have " << count << " " << input << "(s) in stock for " << vectorOfItems[index].getItemPrice() << " each. Continue with purchase?" << endl;
		cout << "1. Yes" << endl;
		cout << "2. No" << endl;
		string optionS;
		int option = 0;
		getline(cin, optionS);
		option = atoi(optionS.c_str());
		while (!isNumber(optionS) || (option != 1 && option != 2))
		{
			cout << "Not a valid choice. Please enter 1 or 2." << endl;
			getline(cin, optionS);
			if (isNumber(optionS))
			{
				option = atoi(optionS.c_str());
			}
		}
		if (option == 1)
		{
			int amt = -1;
			cout << "How many would you like to purchase?" << endl;
			getline(cin, optionS);
			amt = atoi(optionS.c_str());
			int num = 0;
			while ((!isNumber(optionS)) || (amt < 1) || (amt > count))
			{
				cout << "Not a valid choice. Please enter a number between 1 and " << count << "." << endl;
				getline(cin, optionS);
				if (isNumber(optionS))
				{
					amt = atoi(optionS.c_str());
				}
			}
			for (size_t i = 0; i < vectorOfItems.size(); i++)
			{
				if (input == vectorOfItems[i].getItemName())
				{
					if (user.noMoreMoney(vectorOfItems[i].getItemPrice()))
					{
						cout << "You have no more money left!" << endl;
						break;
					}
					else
					{
						user.subtractBudget(vectorOfItems[i].getItemPrice());
						num += 1;
						vectorOfItems.erase(vectorOfItems.begin() + i);
						i--;
						amt--;
						if (amt == 0)
							i = vectorOfItems.size();
					}
				}
			}
			cout << "Congratulations, you purchased  " << num << " " << input << "(s)!" << endl;
		}
		else if (option == 2)
		{
		}
		else
		{
			cout << "Invalid choice. Purchase?" << endl;
			cout << "1. Yes" << endl;
			cout << "2. No" << endl;
		}
	}
}