View Single Post
Old Nov 27th, 2006, 5:04 AM   #8
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by codylee270 View Post
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 View Post
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 View Post
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 View Post
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 View Post
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 View Post
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.
Arevos is offline   Reply With Quote