Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C program. You are the owner of a very busy convenient store. The store sells weekly magazines as well as other oods. One problem you

C program.

image text in transcribed

You are the owner of a very busy convenient store. The store sells weekly magazines as well as other oods. One problem you have is to decide how many magazines to order per week. Despite the buy back from the publishers, ordering too many copies will be wasteful and costly. Order too few will not meet customers' demand. You want to of course make as much profit as possible. You need to find out the optimal amount of magazine to order per week. Note that each magazine is sold at $20.0 each. The store buys a copy from the publisher at $12.0 and the publisher will buy back unsold copies at $5.0 each One way to solve the problem is to look at the history. There is fluctuation from one week to the next, but in the long run the fluctuation will be averaged out. We can make use of the history to make prediction. The following table shows the probability of selling certain copies of magazine Number of Copies Probabilities 20 40 0.06 0.21 0.32 0.18 60 80 100 140 08 02 160 e are going to solve the problem with simulation. The first step is to generate the number of magazine sold in a week. This should be a random number according to the above probability table Complete the following function that randomly returns one of the 8 integers (i.e. number of copies of magazine) according to probabilities. int randMagazineDemand() According to the above table, the function should have the probability of 0.06 (6 in 100 chance) of returning 40 (demand of 40 copies), and the probability of 0.21 (21 in 100 chance) returning 60, etc. The function testMagazineDemand is provided for you in the skeleton to test randMagazineDemand. If your implementation is correct, the results printed should be close to that in the above table Complete the following function that calculates (and returns) the profit (or loss) made by your store by simulating the number of copies of magazine sold in one week. float simulateOneWeek(int copiesToOrder); Remember the profit should be calculated from the number of magazines ordered from the publishers and the number of magazines actually sold. The former is a decision by you (i.e. the store owner), and the latter is represented by the following table Number of Copies Probabilities 20 40 60 0.01 06 0.21 120 0.12 0.08 0.02 140 160 Yes, this is exactly the same table for the previous function randMagazineDemand. Therefore, if the revious function can generate the demand for magazine for simulating one week's business. his function simulateneWeek should simulate the profit of magazine business of a particular week by performing the following Call the function randMagazineDemand to obtain the number of copies as the demand Use the parameter copiesToOrder as the number of copies to order this week. Use the cost of ordering the magazine, and the price of selling a copy of the magazine and the buy back return for unsold magazines, calculate and return the profit (or loss) in one week. - - The function testSimulateOneWeek is given for you to test your implementation. The profit (or loss) will change if you run the test function multiple times. This is due to the number returned from randMagazineDemand can be different. The following two examples illustrate sample return values of function simulateOneWeek Magazine Magazine Actual Magazine Demand Ordered 100 Return simulateOneWeek eaning O return value Profit 80 cause orn is 80 $20-80 $12- ordered 220 Complete the following function that searches for the optimal copies of magazine to order in a week so that the profit is maximized void findMaxProfit() The function finds out the answer by trying out different order size from 10, 20, 30, until 160. For each quantity (say 10), the function should call simulateOneWeek 100000 times to find out the average profit. Calling 100000 times (or more) means simulating the business for 100000 weeks. You are expected to write two nested for loops. The outer for loop controls the order size for one week, and the inner for loop controls the simulation of 100000 times. The function should print the average profit for each possible order quantity. Finally the function should print the optimal order size that maximizes the average profit. You are the owner of a very busy convenient store. The store sells weekly magazines as well as other oods. One problem you have is to decide how many magazines to order per week. Despite the buy back from the publishers, ordering too many copies will be wasteful and costly. Order too few will not meet customers' demand. You want to of course make as much profit as possible. You need to find out the optimal amount of magazine to order per week. Note that each magazine is sold at $20.0 each. The store buys a copy from the publisher at $12.0 and the publisher will buy back unsold copies at $5.0 each One way to solve the problem is to look at the history. There is fluctuation from one week to the next, but in the long run the fluctuation will be averaged out. We can make use of the history to make prediction. The following table shows the probability of selling certain copies of magazine Number of Copies Probabilities 20 40 0.06 0.21 0.32 0.18 60 80 100 140 08 02 160 e are going to solve the problem with simulation. The first step is to generate the number of magazine sold in a week. This should be a random number according to the above probability table Complete the following function that randomly returns one of the 8 integers (i.e. number of copies of magazine) according to probabilities. int randMagazineDemand() According to the above table, the function should have the probability of 0.06 (6 in 100 chance) of returning 40 (demand of 40 copies), and the probability of 0.21 (21 in 100 chance) returning 60, etc. The function testMagazineDemand is provided for you in the skeleton to test randMagazineDemand. If your implementation is correct, the results printed should be close to that in the above table Complete the following function that calculates (and returns) the profit (or loss) made by your store by simulating the number of copies of magazine sold in one week. float simulateOneWeek(int copiesToOrder); Remember the profit should be calculated from the number of magazines ordered from the publishers and the number of magazines actually sold. The former is a decision by you (i.e. the store owner), and the latter is represented by the following table Number of Copies Probabilities 20 40 60 0.01 06 0.21 120 0.12 0.08 0.02 140 160 Yes, this is exactly the same table for the previous function randMagazineDemand. Therefore, if the revious function can generate the demand for magazine for simulating one week's business. his function simulateneWeek should simulate the profit of magazine business of a particular week by performing the following Call the function randMagazineDemand to obtain the number of copies as the demand Use the parameter copiesToOrder as the number of copies to order this week. Use the cost of ordering the magazine, and the price of selling a copy of the magazine and the buy back return for unsold magazines, calculate and return the profit (or loss) in one week. - - The function testSimulateOneWeek is given for you to test your implementation. The profit (or loss) will change if you run the test function multiple times. This is due to the number returned from randMagazineDemand can be different. The following two examples illustrate sample return values of function simulateOneWeek Magazine Magazine Actual Magazine Demand Ordered 100 Return simulateOneWeek eaning O return value Profit 80 cause orn is 80 $20-80 $12- ordered 220 Complete the following function that searches for the optimal copies of magazine to order in a week so that the profit is maximized void findMaxProfit() The function finds out the answer by trying out different order size from 10, 20, 30, until 160. For each quantity (say 10), the function should call simulateOneWeek 100000 times to find out the average profit. Calling 100000 times (or more) means simulating the business for 100000 weeks. You are expected to write two nested for loops. The outer for loop controls the order size for one week, and the inner for loop controls the simulation of 100000 times. The function should print the average profit for each possible order quantity. Finally the function should print the optimal order size that maximizes the average profit

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions