Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 4th, 2006, 10:27 PM   #21
codylee270
Unverified User
 
Join Date: Sep 2005
Posts: 209
Rep Power: 0 codylee270 is an unknown quantity at this point
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...
Attached Files
File Type: zip MegaStore_Files.zip (9.9 KB, 10 views)
codylee270 is offline   Reply With Quote
Old Dec 5th, 2006, 12:22 AM   #22
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
This bit of code in handleSweepsDepart:
		sweepsNext.push_back(deli.front()); // Next person in the sweeps queue moves into processing vector
This causes a crash when there is nothing left in the deli queue.
The Dark is offline   Reply With Quote
Old Dec 5th, 2006, 12:33 AM   #23
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
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.
The Dark is offline   Reply With Quote
Old Dec 5th, 2006, 10:34 PM   #24
codylee270
Unverified User
 
Join Date: Sep 2005
Posts: 209
Rep Power: 0 codylee270 is an unknown quantity at this point
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!
codylee270 is offline   Reply With Quote
Old Dec 6th, 2006, 12:01 AM   #25
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
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).
The Dark is offline   Reply With Quote
Old Dec 8th, 2006, 7:45 PM   #26
codylee270
Unverified User
 
Join Date: Sep 2005
Posts: 209
Rep Power: 0 codylee270 is an unknown quantity at this point
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:

Regular: 717 08:55:08 17:21:31 503
The times here are some waiting stats, and 17 hours seems to be the longest wait in that line. I'm thinking there could be an issue with the randomness of the data that determines the number of items and payment method or something to cause a random gen of so many people whom have more than 10 items and don't pay with cash ( a requirement for that checkout line).

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.
Attached Files
File Type: zip MegaStore_Files.zip (36.5 KB, 6 views)

Last edited by codylee270; Dec 8th, 2006 at 8:04 PM.
codylee270 is offline   Reply With Quote
Old Dec 8th, 2006, 9:46 PM   #27
codylee270
Unverified User
 
Join Date: Sep 2005
Posts: 209
Rep Power: 0 codylee270 is an unknown quantity at this point
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.
Attached Files
File Type: zip MegaStore_Files.zip (14.6 KB, 11 views)

Last edited by codylee270; Dec 8th, 2006 at 10:40 PM.
codylee270 is offline   Reply With Quote
Old Dec 9th, 2006, 12:54 AM   #28
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
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
is saying that the next show departure is the arrival time for the last customer plus 11 times the number of items for the chosen customer. Effectively it is saying that each time a new customer comes into the shop, everyone else has to start again from scratch.
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
This ends up causing your time line to not always go forward, which severely stuffs up any stats calculations.

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
when I looked for the previous event with Agatha Clinton it was this
Time: 42280
Agatha Clinton has left the Deli
So somehow she had gone back in time after leaving the deli!
The Dark is offline   Reply With Quote
Old Dec 9th, 2006, 10:21 AM   #29
codylee270
Unverified User
 
Join Date: Sep 2005
Posts: 209
Rep Power: 0 codylee270 is an unknown quantity at this point
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:MINEC".

Can anyone see the problem... Dark!!!! HELP!!!!

As usual, the zip file below has been refreshed to reflect my current code.
Attached Files
File Type: zip MegaStore_Files.zip (14.9 KB, 7 views)
codylee270 is offline   Reply With Quote
Old Dec 9th, 2006, 3:32 PM   #30
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
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]);
	}
At the time, someone else was helping you and I didn't want to confuse the issue.
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());
	}
The Dark is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:17 AM.

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