示例#1
0
void AddProductToAShop(StringType productName, int shopIndex)
{
	Product ourProduct;
	ourProduct.setProductName(productName);
	ourProduct.setProductPrice((double)rand() / 100);
	ourProduct.setProductAmount(rand() % kMaxixumAmountOfProducts + 1);
	if (!retailNetwork[shopIndex].addProduct(ourProduct))
		printf("\nToo many products in shop %d!\n\n", shopCounter + 1);
}
示例#2
0
Product* Store::getRandomProduct() const
{
	Product* result = new Product();

	char* randomProductName = getRandomProductName();
	result->setProductName(randomProductName);
	delete[] randomProductName;

	ProductPriceType productPrice = rand() % (kMaxRandomValueForProductPrice - kMinRandomValueForProductPrice + 1);
	productPrice += kMinRandomValueForProductPrice;
	result->setProductPrice(productPrice);

	ProductAmountType productAmount = rand() % (kMaxRandomValueForProductAmount - kMinRandomValueForProductAmount + 1);
	productAmount += kMinRandomValueForProductAmount;
	result->setProductAmount(productAmount);

	return result;
}
示例#3
0
Shop SelfInputShop()
{
	Shop ourShop;
	bool continueCycle;
	do 
	{
		continueCycle = false;
		gets_s(shopName);
		for (int shopCounter = 0; shopCounter < shopsAmount; shopCounter++)
		{
			StringType currentShopName;
			retailNetwork[shopCounter].getShopName(currentShopName); 
			if(strcmpi(currentShopName, shopName) == 0)
			{
				printf("There is shop with the same name in the Retail Network! Input other name! << ");
				continueCycle = true;
				break;
			}
		}
	} while (continueCycle);	

	ourShop.setShopName(shopName);
	ourShop.setProductsAmount(0);

	bool exitCycle = false;

	while (!exitCycle)
	{
		printf("\n-------How many products should be in Shop%d (maximum 20):", shopCounter);
		printf("\n-------<< ");
		cin >> productsAmount;

		if (!MakeCheckForNumberInputFromCin())
			continue;

		if (productsAmount <= NULL || productsAmount > kMaxixumAmountOfProducts)
		{
			printf(kThereIsNoCorrespondingOptionErrorMessage);
			continue;
		}

		printf("\n-------Input data about products:\n");

		for (productCounter = 0; productCounter < productsAmount; productCounter++)
		{
			Product currentProduct;
			bool countinueCycle;
			do
			{
				countinueCycle = false;
				printf("-------Product%d Name: << ", productCounter + 1);
				gets_s(productName);

				Product currentShopCase[kMaxixumAmountOfProducts]; 
				ourShop.getShopCase(currentShopCase);
			
				for (int productNameCounter = 0; productNameCounter < productCounter; productNameCounter++)
				{
					StringType currentProductName;
					currentShopCase[productNameCounter].getProductName(currentProductName);
					if (strcmpi(currentProductName, productName) == 0)
					{
						printf("\nThere is a product with same name in retail network! Put the name again << \n");
						countinueCycle = true;;
					}
				}				
			} while (countinueCycle);

			currentProduct.setProductName(productName);

			bool exitPriceCycle = false;
			while (!exitPriceCycle)
			{
				printf("-------Product%d Price: << ", productCounter + 1);
				cin >> userProductPrice;

				if (!MakeCheckForNumberInputFromCin())
					continue;

				if (userProductPrice <= NULL)
				{
					printf(kThereIsNoCorrespondingOptionErrorMessage);
					continue;
				}
				exitPriceCycle = true;
			}
			currentProduct.setProductPrice(userProductPrice);

			bool exitAmountCycle = false;
			while (!exitAmountCycle)
			{
				printf("-------Product%d Amount: << ", productCounter + 1);
				cin >> oneProductAmount;

				if (!MakeCheckForNumberInputFromCin())
					continue;

				if (oneProductAmount <= NULL)
				{
					printf(kThereIsNoCorrespondingOptionErrorMessage);
					continue;
				}
				exitAmountCycle = true;
			}
			currentProduct.setProductPrice(userProductPrice);
			currentProduct.setProductAmount(oneProductAmount);
			printf("\n");

			ourShop.addProduct(currentProduct);
		}

		exitCycle = true;
	}
	return ourShop;
}