![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#21 |
|
Unverified User
Join Date: Sep 2005
Posts: 209
Rep Power: 0
![]() |
oops... sorry... let me try again..
well, for one the updated .zip is below. 2) the compiler actually did not give me an error for the missing (), that's weird... |
|
|
|
|
|
#22 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 852
Rep Power: 4
![]() |
This bit of code in handleSweepsDepart:
sweepsNext.push_back(deli.front()); // Next person in the sweeps queue moves into processing vector |
|
|
|
|
|
#23 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 852
Rep Power: 4
![]() |
There were a couple more like that, where you had copied the code, but hadn't changed all the variables over.
Also, the handleShopDepart crashes when there is nothing left in the shop after you remove the customer. In the driver, you use a variable called holder, which is not initialised. I don't think you need it at all - you should be using random_integer. This is the result I got:
The winner of the $100 grocery give away is: Fez Bonds
The winner of the $50 grocery give away is: Abe Circe
Number Processed Average Time in Line Longest Time in Line Longest Line Length
---------------- -------------------- -------------------- ------------------- Sweepstakes: 749 58 140 4
Deli: 411 56 150 2
Express Cash: 25 10 10 0
Express: 74 0 10 0
Regular Cash: 165 2 19 -858993460
Regular: 736 53327 83679 720
Press any key to continue . . .One thing you really need to do is to put in some trace writes. At the top of the functions, stick in something that says which function you are entering. That way you can at least narrow down where the crash is, if you aren't using a debugger. Remember to flush out any trace writes before continuing, otherwise the screen might not update before the crash. |
|
|
|
|
|
#24 |
|
Unverified User
Join Date: Sep 2005
Posts: 209
Rep Power: 0
![]() |
DARK!! I meant to get back to you sooner, but you have literally saved my life... lol.. I corrected all of what you found, and I even corrected that god awful neg number in the output and formatted it, too.
I have 2 more questions: I'm using this to get the random percentages of different pay types: int customerFactory::randomPayType()
{
//Precondition: none
//Postcondtion: Returns 1 for check, 2 for cash, 3 for credit
int num = randomNumGen();
if(num <= 10)
return(1); // for 10% check
else if(num > 10 && num <= 30)
return(2); // for 20% cash
else
return(3); // for 70% credit
}Does this even make sense. Sure it generates plenty of random numbers, but do the percentages workout. Is there a better way? 2) I went in and put the snapshots in as you said, not only for debugging, but I'm going to need to turn them in as a sample trace through. I want to write these to a file - so , do I need to open up an outfile in the main() or should I do this in the constructor and close it when the sim is up? Can I open a file for writing in the constructor and close it in main or do I need to open and close in main.... Your thoughts... Oh, also, I'm also using this, the predicate function given by Aravos, to sort the deli by last name, then by first if some last names match, in descending order, so I can retrieve the next closest name beginning with A, at the end of the vector. bool DeliSortPredicate(const Customer&, const Customer&); //Sorts vector based on last name
bool DeliSortPredicate(const Customer& lhs, const Customer& rhs)
{
return lhs.lastName > rhs.lastName ||(lhs.lastName == rhs.lastName && lhs.firstName > rhs.firstName);
}this is the function called in the depart function just before the next customer in line is moved to the processing vector: sort(deli.begin(), deli.end(), DeliSortPredicate); // Sort deli based on last name, then first name if some first names are equal Does this even work? I can't tell b/c the screenshots go so fast, and the command prompt won't even let me scroll up to see all printouts. Thanks again Dark, you have certainly made me successful this semester, and I truly appreciate it! |
|
|
|
|
|
#25 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 852
Rep Power: 4
![]() |
1. That looks OK to me. To test it, just write a quick loop that calls it a million times, record the result and see if you get roughtly the percentages of answers that you expect.
2. There is lots of ways to do the tracing. I think the simplest would be just to have an output stream and open it in the constructor and close it in the destructot (although the closing is probably automatic). Note that this would only let you do the trace writes from within the class that has the stream variable. If you don't want to be able to have multiple trace writes to different output files, and you want to be able to write trace writes from any class, I'd probably go for a separate class with a static member function to do the trace write. The other (crappier) option is to write your tracewrites to stderr and just redirect stderr to a file using the command line. 3. Looks OK to me. You can tell by redirecting your output to a file (or changing your trace writes). If you are under Windows, you can also change the number of lines that you can scroll back using the Layout tab of the command prompt window's Properties menu. I usually set all mine to 9999 rows (the max). |
|
|
|
|
|
#26 | |
|
Unverified User
Join Date: Sep 2005
Posts: 209
Rep Power: 0
![]() |
Alrighty guys, I might have found a possible problem.
I've formatted the output and all times are now in hour:min:sec format. Well, due to this I noticed that one of the checkout lines had a god awful wait time, that seems like it is possibly due to an error. Quote:
I've attached all my files, including the 2 .txt files required to generate names, and the .txt that the program writes a log of events to. Can someone please take a look at my code, and see if they can find the issue, or if it's just the luck of the draw with the random num gen. If you do compile and run this, please be reminded that this thing prints out a snapshot of every customers movement within the store. So while it may look like it's stuck in an infinite loop, it's just printing a bunch of snapshots and will eventually end in stat printouts. Thanks guys !!!!!!!!!! EDIT !!!!!!!!!!!!!!!! I totaled up the percentages of the payment methods, and they are correct. Last edited by codylee270; Dec 8th, 2006 at 8:04 PM. |
|
|
|
|
|
|
#27 |
|
Unverified User
Join Date: Sep 2005
Posts: 209
Rep Power: 0
![]() |
Ok, don't mean to double post but I've found another issue.
The program sets stats for every customers wait based on each line they enter. So each customer gets a deliWait, sweepsWait, and so on. When I set these in the file, as they go through each line in the sim, I printed them out to see that something is actually getting set. When I try to print out these stats at the bottom of main, I always get 0 for deliWait, sweepsWait, and so on. I know these values are change for some people, at least for those who have to wait in line. But if you loop through the 1000 customers in main(), it acts like noone's value ever changes from the 0 that initializes these variables in the Customer constructor. The vector was passed by reference, so each customers data should change. Why won't it give me the data instead of 0? !!!!! EDIT !!!!!!!!! I've attached the latest file set w/ more comments for clarity - and I deleted where I was printing out the stats of the customers from main to a Customer member function called printStats(). The index for the customer trying to be printed was just a random number for testing, and as you can see produces all zeros. Last edited by codylee270; Dec 8th, 2006 at 10:40 PM. |
|
|
|
|
|
#28 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 852
Rep Power: 4
![]() |
There is a bug in your handleShopArrival function.
This code: nextShopD = arrTime + (shop.back().getItems()) * 11 ; //The next shopping vector departure is set to the the value of the customer it should be nextShopD = shop.back().lineArrival + (shop.back().getItems()) * 11 ; //The next shopping vector departure is set to the the value of the customer They way I found this was to add an output of the time to cout for each loop in the driver. I then noticed that the times jumped back back a number of hours at certain points. When the time changed I looks at the console log and saw this: Time: 87094 Penelope Booth has arrived in the Regular Checkout Time: 6531 Agatha Clinton has arrived in the Regular Checkout Time: 42280 Agatha Clinton has left the Deli |
|
|
|
|
|
#29 |
|
Unverified User
Join Date: Sep 2005
Posts: 209
Rep Power: 0
![]() |
OMG, another copy error it looks like. You are an absolute life saver.. I would have never found that, didn't even think to look in that part.
Alrighty, I've got one more issue and I think I'm going to call it quits for this project. Like I said above, I am having trouble printing out how long a customer stays in a particular line. I've found some error in the logic, fixed that, but I still have no printout. In handleDeliArrival(), if the customer does not stand in line and moves right into the processing vector, i set their wait time to 0, no problem. If the customer has to wait anytime whatsoever, their wait time should be set. Ive only fixed the deli so far, but here is the most up-to-date code for it which exhibits what I'm trying to explain. Inside handleDeliDepart(), I have: if((nextDeliD - 50) != deliNext[0].getArrival()) // If the customer being tracked had to stand in line
{
dTotal+=(nextDeliDepart() - deliNext[0].getLineArrival());
deliNext[0].setDeliWait(nextDeliDepart() - deliNext[0].getLineArrival()); //if the customer stood in line, their total time in the deli line is the time they
// were processed - the time they arrived in the deli line
}
if(dLongest > deliNext[0].getLongestWait())
deliNext[0].setLongestWait(dLongest); // update wait stat for customer
// Used to show that the customers wait time is set if they have to wait
log << endl << endl << deliNext[0].getDeliWait() << endl << endl;If you look at the log, the line of code just above this sentence shows that the wait time in the deli is being set and printed. However, if I try to run something like this in main() int longest =0;
int index;
for(i=0; i<1000; i++)
{
if(c[i].getDeliWait() > longest)
{
longest = c[i].getDeliWait();
index = i;
}
}
cout << endl << longest << endl << endl;I get the longest deli wait to be 0, and I know from the log that someone had to wait in the deli for more than 0 seconds due to the log file stats. It also give me 0 if I do longestLineWait, for all lines. I know I have stats for the longest wait in each line, But i wanted to loop through and find the index of the person with the longest wait time, so I could print out that "So and So waited the longest time in line with a total of HR:MIN EC".Can anyone see the problem... Dark!!!! HELP!!!! As usual, the zip file below has been refreshed to reflect my current code. |
|
|
|
|
|
#30 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 852
Rep Power: 4
![]() |
I'm pretty sure your problem is that you are looking at the c array for info, whereas the rest of your program is working with the custVect vector.
I must admit I didn't really know what you were getting at with this loop: vector<Customer> custVect;
Customer c[1000];
for(int i = 0; i<1000; i++)
{
c[i] = factory.newRandomCustomer();
custVect.push_back(c[i]);
}This loop is creating two completely separate collections of customers. So anything done to custVect (e.g. by megastore) will not be reflected in c. I don't think you need c at all. I think your best bet would be to drop the c array and just use custVect everywhere. something like: vector<Customer> custVect;
for(int i = 0; i<1000; i++)
{
custVect.push_back(factory.newRandomCustomer());
} |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Instant Messaging System Final Year Project | bondito | Java | 20 | Oct 28th, 2007 11:08 PM |
| Need help making a game plan for final programming project! | codylee270 | C++ | 27 | Dec 1st, 2006 7:29 PM |
| help with timers for final class project | Rath72 | Visual Basic | 8 | Jun 14th, 2006 6:55 AM |
| Final Year Project | smakazmi | Other Programming Languages | 8 | Oct 7th, 2005 2:09 AM |
| University Final Year Project | nez | Project Ideas | 3 | May 23rd, 2005 8:59 AM |