Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   Need help making a game plan for final programming project! (http://www.programmingforums.org/showthread.php?t=11998)

codylee270 Nov 25th, 2006 3:14 PM

Need help making a game plan for final programming project!
 
Ok guys, I'm near the end of my Info. Structures class (very frustrating but definitely worth every penny of tuition). My professor has given us a final project to do and it's an event simulation. Since this thing is incredibly long, I was hoping you guys could help me formulate a game plan to attack the individual segments of this sucker. I'm going to post the prompt for this thing, and at the bottom I'll tell you my ideas of what I'm thinking of doing. If you can think of a better/quicke/ more efficient way of completing some of these tasks, please let me know. I've gotten through almost 3 whole classes with everyone on this forum, lets go out with a bang!

The task:
---------------------------------------------
Background:

MegaStore Market s considering opening a new store in your area and would like you to help create a simulation of the new store. They are planning to have the store open 24 hours a day, so you will be simulating the throughput of customers for a single 24 hour period from time 1 through time 1440 (24 hrs * 60 min/hr). You will be creating an EVENT DRIVEN simulation, so the clock will be updating according to the time of the next event.

Customer Arrivals:

The first step is to create the customers. One suggestion is to create some sort of customer class that will keep a number of different variables for that customer, including their first name, last name, arrival and departure time into each queue, and various information that will help in calculating the simulation statistics.

The owners of MegaStore Market expect that there will be a total of 1000 customers at the store during a 24 hour period. A file containing a list of first names, and a file containing a list of last names will be given to you. You should store these lists locally. Each of the 1000 customers should randomly be given a first name and a last name from these files. In addition, they should be randomly assigned an arrival time into the store (from 1 to 1440), randomly assigned a number of items that they wish to purchase (from 1 to 100), and randomly assigned whether they are paying by cash(20%), check (10%), or credit card (70%).

Events in MegaStore Market:


Every day for the first year, MegaStore Market will have a drawing for $100 in free groceries, with a second prize of $50 in free groceries. 75% of all customers entering into the store will sign up for the sweepstakes, which takes 30 seconds to sign in (plus the time it takes to wait in line - only one person can sign up at a time!!) One lucky winner will be drawn at the end of the day for each of the prizes. You should report who wins as part of your simulation.

Once customers have entered the store and have signed in for the sweepstakes, 40% of the customers will proceed to the deli where they are waited on one at a time. A normal deli operates a first-come, first-served manner, but the owners of the MegaStore decide to switch things up and help the next person based on the alphabetical order of their last name (followed by their first name, if necessary). This way they get to know who their customers are! Each turn at the deli takes 50 seconds (plus the time waiting in line).

After they exit the deli, each customer finished shopping. It takes 11 seconds to shop per remaining item. After they are finished shopping, they may enter one of four checkouts: Express, Cash only (10 or fewer items); Express ( 10 or fewer items); Regular, Cash only; Regular. It takes 3 seconds per item to check out. If they pay by credit card, it takes 30 seconds to finish; and if they pay by check, it requires 75 seconds to finish.

Simulation Statistics:

At the end of the simulation, you should report a number of statistics for each line, including (BUT NOT LIMITED TO): Number processed, average time in line, longest time in line, longest line length. these should be computed for the following: Sweepstakes line, Deli, Express Cash, Express, Regular Cash, and Regular Lines, as well as the statistics for the simulation as a whole (e.g. what are these values for people entering/exiting the MegaStore Market). In addition, you should report the winner of the $100 in groceries.

-------------------------------------------------
So, I'm assuming I need to randomly generate 1000 numbers, b/w 1 and 1440, I'm guessing those should be unique. For the customer names I'll use 2 string arrays, read in each name from the file into an index, probably upon execution of the program (in the main() function).

Looks like I'll need random indices for the names, possibly create a function just for that.
Also need random number generator for number of items to purchase.

I'm not sure what to do about randomly creating the method of payment based on percentage? Anyone have any good ideas?

Also, what should I do about initializing all the cusomters. Should I make the class, as reccomended, and use a loop:

ex.

//Already have random data for arrival time, # of items to purchase
//payment method stored in an array.

for(i=0; i<1000l i++)
{
//Initialize customers
customer c[i](arrival[i], items[i], payment method[i]);
}

So all customers would then have the initial info to begin the sim. Would this work?

Some other questions:
How could I sort the deli queue alphabetically (if last name and first name are each stored in a separate array), using the last name array, and have the associated first name array be changed to reflect the sort. Or if there is an easier way to perfom the deli line queue sort, please let me know. I'm thinking I'll need the full 40% of customers in line before then?

MY BIGGEST QUESTION(S):

How do I keep up will all of the percentages so I can place the customers in the queue properly based on time?
More importantly, how do I keep up with all the times in general so everything goes in order. This seems like the hardest part of the project and, to me, the most confusing.

I'll be checking the forums often today to see everyones' input (if there is any, PLEASE let there be some). I want to get this thing into a nearly whole form of pseudocode before I start coding.

THANKS GUYS!!!!

Arevos Nov 25th, 2006 3:48 PM

Quote:

Originally Posted by codylee270 (Post 119708)
So, I'm assuming I need to randomly generate 1000 numbers, b/w 1 and 1440, I'm guessing those should be unique. For the customer names I'll use 2 string arrays, read in each name from the file into an index, probably upon execution of the program (in the main() function).

I think you're looking at this the wrong way. Instead of trying to generate random data for 1000 customers, create a function that will create a single customer object with random data. Then repeat that function 1000 times.

Quote:

Originally Posted by codylee270 (Post 119708)
I'm not sure what to do about randomly creating the method of payment based on percentage? Anyone have any good ideas?

Consider a random number generator that generates a number from 1 to 100. There will be a 20% chance the random number will be between 1 and 20, no?

Quote:

Originally Posted by codylee270 (Post 119708)
Also, what should I do about initializing all the cusomters. Should I make the class, as reccomended, and use a loop

Look up the factory design pattern. It would be neater to do it like so:
:

  1. CustomerFactory factory = CustomerFactory(firstnames, lastnames, etc...);
  2.  
  3. for (int i = 0; i < 1000; i++)
  4. {
  5.     customers[i] = factory.newRandomCustomer();
  6. }


Quote:

Originally Posted by codylee270 (Post 119708)
How could I sort the deli queue alphabetically (if last name and first name are each stored in a separate array), using the last name array, and have the associated first name array be changed to reflect the sort. Or if there is an easier way to perfom the deli line queue sort, please let me know. I'm thinking I'll need the full 40% of customers in line before then?

Why is this difficult? You'll have an array or vector of customers representing the deli line queue, no? And each customer object will contain their firstname and lastname, no? So its straightforward to sort them into alphabetical order and pop off the top customer.

Quote:

Originally Posted by codylee270 (Post 119708)
More importantly, how do I keep up with all the times in general so everything goes in order. This seems like the hardest part of the project and, to me, the most confusing.

Surely each customer object will keep track of how much time they need? You could write some simple functions so you could ask each customer when they start shopping, how long they take to pay, and so forth. Your "Megastore" object would presumably coordinate and shuffle customers in and out of queues, and add to an internal counter than keeps track of time.

codylee270 Nov 25th, 2006 5:31 PM

Thanks for the great ideas Arevos:
So, for the random payment method, could I possibly use a random num. generator that produces value 1,2,3. If it comes up with a 1 then his/her payment method is by credit card as long as a variable, such as numCredit != 70% of 1000. And use a 2 for the 20% cash, and 3 for the 10% check? Does that seem viable?

CustomerFactory factory = CustomerFactory(firstnames, lastnames, etc...);

Using this:
:

for (int i = 0; i < 1000; i++)
{
    customers[i] = factory.newRandomCustomer();
}


What class do the customers belong to? Do they have their own customer class? It looks like you are setting one object equal to another. Should I assume that customers[i] is a customerFactory object?

If I use an array for the deli line, what is the data type of the array? How can I get an array of customers to sort based on each objects' last name data member?

Using this method, which I like, it seems there is a chance that customers may end up wih the same arriva time. I don't know if this is allowed or not, but is there a way to prevent this? It seems that once every customer has an arrival time, preferably unique, you could sort them by arrival, and begin the sim. Again this calls for sorting a list/array based on a data member.

If each customer is to keep track of the time needed to complete transactions and what not, does each customer need a data member to store the time waiting in line?

What functions/data memebers would be in the MegaStore object. What does it use for a counter, a loop? It seems like I would also need some sort of function see the location of a customer ( e.g. the sweepstakes lines, deli line, checkout, -- have they left the store) The counter would need to keep going until the last person is out. How about a bool variable, inStore()?

Could you please elaborate more on how I could keep track of the timing and shuffling in and out of lines/ queues? Again, this is still a mystery to me.


Also, I'm planning on using the STL queues and what not, would you recommend this?

Thanks for everything!
Cody

codylee270 Nov 26th, 2006 9:19 PM

anyone else?

Wizard1988 Nov 26th, 2006 11:29 PM

I would make a CustomerFactory class like Arevos mentioned and that would simply return a Customer class with the different specifications you supplied.

The Customer class would have a first and last name variables as well as variables for storing time info for when they entered the store, line, as well as they left those.

I would also have a Store class which would keep track of the time as well as generate the lottery number.

However I don't think generating a number from 1 to 3 would really work for deciding the method of payment.

You should think about how many instances of customer class you will have. Do they interact with each other? or are they just random objects which should be generated as needed.

Theese are just some things you might want to think about.

I hope this helps

crawforddavid2006 Nov 26th, 2006 11:36 PM

well the only input i've got is use code tags becuase if it wasnt for someones post i would have looked right over your effort and told you off for not trying.

mrynit Nov 27th, 2006 2:45 AM

you find more help asking over at this game forum http://www.gamedev.net/community/forums/

Arevos Nov 27th, 2006 5:04 AM

Quote:

Originally Posted by codylee270 (Post 119718)
So, for the random payment method, could I possibly use a random num. generator that produces value 1,2,3. If it comes up with a 1 then his/her payment method is by credit card as long as a variable, such as numCredit != 70% of 1000. And use a 2 for the 20% cash, and 3 for the 10% check? Does that seem viable?

Uh, I don't think you've understood this.

If you generate a random number from 1 to 3, then there is an equal chance of each number coming up. For instance, there is a 33% chance that the function will return 1. However, there is a 67% chance that the generator will return either 1 or 2. By using a range of numbers, you can generate different probabilities.

Now, reread my earlier statement: Consider a random number generator that generates a number from 1 to 100. There will be a 20% chance the random number will be between 1 and 20.

Do you understand now?

Quote:

Originally Posted by codylee270 (Post 119718)
What class do the customers belong to? Do they have their own customer class? It looks like you are setting one object equal to another. Should I assume that customers[i] is a customerFactory object?

You will have no doubt looked up the factory design pattern, and thus you will no doubt know that a factory class is designed to create objects. A CustomerFactory will produce Customer objects.

Quote:

Originally Posted by codylee270 (Post 119718)
If I use an array for the deli line, what is the data type of the array? How can I get an array of customers to sort based on each objects' last name data member?

I'd use a vector myself, or some other similar data structure. Are you allowed to use the C++ STL?

In any case, either you use a sorting algorithm in the language, or you build one yourself. Have you covered quicksorts or bubblesorts?

Quote:

Originally Posted by codylee270 (Post 119718)
If each customer is to keep track of the time needed to complete transactions and what not, does each customer need a data member to store the time waiting in line?

Yes... But only for statistical purposes.

Quote:

Originally Posted by codylee270 (Post 119718)
Could you please elaborate more on how I could keep track of the timing and shuffling in and out of lines/ queues? Again, this is still a mystery to me.

Think of it this way. You have a loop, where each iteration represents one second, and at the end of the loop, a counter is incremented. You query each customer with the current "time", and you discover one who is scheduled to enter the store. It gets placed in line, and you tell it to start paying. Every iteration of the loop you ask it if it has stopped paying, and if it says yes, you remove it from the store. If a customer comes in whilst another is waiting, you place it in the queue.

Quote:

Originally Posted by codylee270 (Post 119718)
Also, I'm planning on using the STL queues and what not, would you recommend this?

The STL is a good bet, but queues are data structures that operate on a FIFO basis (first in, first out). You want a class that delivers customers in alphabetical order.

codylee270 Nov 27th, 2006 10:40 AM

Hello again everyone,

If the customerFactory produces customer objects, then I'm assuming the factory.newRandomCustomer() returns a customer object and the built-in copy constructor assigns it. Correct?

And as for the generating 1, 2, and 3 for payment method, I guess I should have explained my idea little more. I was thinking of generating these numbers, and incrementing a variable for each. Say, it generates a 1, so, numCredit++. There will only be allowed 750 credit payments for the 1000 customers. So you could test using if's to see if the number generated is equal to maxNumCredit which = 750. If not, that person is allowed to pay with credit, if so , generate a number and wait until you get a 2 or 3 and run the same conditional until all customers have a payment method. I do understand what you mean by using a range of values, but I'm unsure how guarantee the correct percentages without using a similar solution as above - testing for max number allowed.

We are allowed to use c++ STL, and I was thinking of using a typical sort function, but I didn't know if there was a common way to do this. So this would be a vector of customer objects? What sorting algorithm would recommend? What about resorting if last names are the same based on first name?

As for the loop to count time, this is what I was thinking too, but this is supposed to be Event Driven. So, I'll need a good way of seeing when the next customer event needs to occur. We went over priority queues for a grand total of 5 minutes in class, but I know there is a STL priority queue, but not sure how to apply it. Does it seem applicable?

Thank you everyone for your help!

Arevos Nov 27th, 2006 1:10 PM

Quote:

Originally Posted by codylee270 (Post 119803)
If the customerFactory produces customer objects, then I'm assuming the factory.newRandomCustomer() returns a customer object and the built-in copy constructor assigns it. Correct?

Yes... Except for the part about the copy constructor. Why would you want to copy the customer object?

Quote:

Originally Posted by codylee270 (Post 119803)
I do understand what you mean by using a range of values, but I'm unsure how guarantee the correct percentages without using a similar solution as above - testing for max number allowed.

Ah, you need to guarantee the percentages? In which case your solution would work, although it would lack a certain randomness, favouring customers at the front of the queue before those at the end.

However, if your customers are all assigned random entry times and random names, you could just assign the first 200 as the 20% being paid by cash, the next 100 as the 10% paying by check and so forth. Because the customers are all assigned random times anyway, then it's equivalent to picking the top N cards of a shuffled deck.

Quote:

Originally Posted by codylee270 (Post 119803)
We are allowed to use c++ STL, and I was thinking of using a typical sort function, but I didn't know if there was a common way to do this. So this would be a vector of customer objects? What sorting algorithm would recommend? What about resorting if last names are the same based on first name?

Read up on customising the sort function: http://web6.codeproject.com/vcpp/stl...0&select=22656

Quote:

Originally Posted by codylee270 (Post 119803)
As for the loop to count time, this is what I was thinking too, but this is supposed to be Event Driven. So, I'll need a good way of seeing when the next customer event needs to occur. We went over priority queues for a grand total of 5 minutes in class, but I know there is a STL priority queue, but not sure how to apply it. Does it seem applicable?

*shrugs* Windows and other GUI systems use an event loop in the same way. Still, if you want to be clever about it, you could always iterate through all of the customers being served, along with the customers arrival time, and find the minimum, then increment by that amount.

Or perhaps some manner of event queue, with customers placing timed events in a queue ready to be picked up by your main class.


All times are GMT -5. The time now is 4:46 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC