|
C M S C 2 1 4 C o m p u t e r S c i e n c e II F a l l 2 0 0 4 |
Some students are having a hard time tracking down core dumps. Remember that a constructor (copy or default or other) may be called for EACH part (and sub part) and that dtor's are run at various times and operator= (even if you don't write it) and so you have to really "look hard" to find the actual line(s) which are causing the core dump.
Two rules of thumb:
Additional note: a new version of "checkMemory" will be posted soon
which might be helpful for finding a small portion of memory errors.
Look for a FAQ about that later.
Unfortunately the Event class is very "restricted" and there are no "set"
functions provided so this is a little difficult - but not impossible.
In particular this question arises when you try to add someone to the
participants list. More hints will be posted here soon but note that
it just requires thinking about what type of access you have to the
EventList class and how you update events in that list.
UPDATE (9/24/04): Ok, so the hint was to think about how you "update"
events in the EventList class - and the answer is "by using the update
function" - so how does the update function work, should be the next
question. Looking at update's prototype we see that it takes
an Event object by value (yes this is inefficient, and const
reference would be better, but such is how it is) - so we have to
have an Event object (a local variable "outside" the update function)
in order to call update and then the update
function goes through the linked list looking for a node that contains
an Event with the same title and when it finds it, it "overwrites"
that Event (there are a couple ways to do this - some "safer" than
others). And that's it.
So if we think about that, and how things work just before we call the
update function (for the EventList class) hopefully it is possible to
see that even though the Event class has no set functions and it
is nearly impossible to modify an Event object (even non-const
ones) after it's ctor has been run it is still very easy to "update"
an Event in the EventList - just declare an Event object (non-dynamic
is perfectly fine) with the title, start_date, ... and participant list
that you want (either bigger or smaller than the old participants list -
which you can get a copy of since there are many "get" functions
available for Event objects (just no "set" ones)) and then pass in this
updated Event into the update function and it will find the corresponding
event in the EventList and update it to be like the one passed in.
UPDATE (9/27/04): So after reading the above if it still isn't clear
here is some (not quite complete) code:
There were several errors in the originally posted primary.output In
particular the following errors:
On the project description the <find_same_venue_fail> BNF is
listed as follows:
There was also a very minor error in the EventList.h header file - in
particular there was a "forward class declaration" of "class MList;" but
this was supposed to be "class EventList;" and has been updated - but it
turns out that this line is fine either way and is actually not needed
for the project to compile so either way it appears is fine (do not
remove it).
Yes. The only exception is when it states that it is "optional" in the
project description - primarily the only optional ones are a few (not
all) of the default ctor's and dtor's and operator='s - and in these
cases if the "autogenerated ones" work fine (don't cause memory leaks,
etc.) then you must not write them, otherwise you must. This applies
to very few functions and only the functions that EXPLICITLY state
they are optional - all others you MUST implement so they work as
described (otherwise points may be deducted).
After each project is completed and you have submitted it, it is
recommended that you "clean up your account a little" - by deleting
any unneeded files. NOTE HOWEVER YOU SHOULD KEEP A BACKUP COPY OF
YOUR SOURCE files for your own reference. By "cleaning up" we mean
deleting any old .o (object) files, old core files, old
executable programs (a.out or p0 or ...) and the
cxx_repository directory (if it exists). Note that these
things just listed may take up a lot of your "Disk Space" of which your
account has a limited supply. Your account has enough space to store
all the code for all of your projects and the executables for one
project (the "current" one) but it does not have enough space to store
old core dumps, old executable files, ... for all of the projects.
If you encounter disk quota/space issues you should try to clean out
your account and then if necessary see someone in office hours. Note
that a common problem that occurs when you use up all of your disk
space is that your program may fail to compile. You can always check
your quota by running the UNIX quota command and if the
blocks used is almost as high as your quota limit or
you have about 20% left then chances are this could be the source of
some problems.
So what is the mysterious cxx_repository directory? It is
a directory created/used by the cxx compiler to compile certain types
of C++ programs (generally ones that use templates or libraries that
use templates) and it can be deleted anytime after your executable
file has been created - but doesn't hurt to leave around until you
are done with that project (after which you might as well delete it).
So how do you delete this directory? The long way is to cd into the
directory and remove all the files and then cd up one and then delete
the directory using the UNIX rmdir command. There are
shorter/quicker ways but they are more "dangerous" to do and could
result in deleting many files you didn't want to delete.
When you come to see someone in office hours for help on your project,
you should always bring a current printout of your code and if
possible a printout of the compiler error messages (if there are any) and
if it compiles a printout of the programs output (and the input used to
generate that output). If you want to get the output of the compiler's
error messages you will need to redirect error output as follows:
Having the requested information above will assist the instructional staff
in being better able to assist you and others who are waiting to be
assisted. Please also understand that the office hour room is a shared
resource with other classes and we ask that you be respectful of the
room and others using the room.
Don't forget to attempt to "debug" your code as much as possible prior
to coming for assistance (and be prepared to describe how you did this
and where you think the problem is).
Project #1 is due by 11PM on Tuesday, September 28th, 2004. Note:
any project may be turned in late up to 2 days as specified on the
class syllabus. For details regarding the late policy and any
penalties associated with submitting late projects please see the
class syllabus.
Event e1( .... ); // has some title, namelist, etc.
... // some code
// now we want to change the title of e1 - but how?
string s1;
cout << "Enter the new title you want: ";
cin >> s1;
Event temp( s1, e1.getYear(), e1.getVenue(), ..., e1.getParticipants() );
// so now we have temp which is basically a copy of e1 but with a different
// title HOWEVER what we wanted to do was change e1's title
e1 = temp;
// and now we are done - e1 has been changed.
There are no other errors in the primary input/output and submit now
accepts properly working programs.
<find_same_venue_fail> ::= "Events with the same duration:"<endl>
"No events found."<endl><endl><endl>
however it should be as follows:
<find_same_venue_fail> ::= "Events with the same venue:"<endl>
"No events found."<endl><endl><endl>
% cxx main.cpp csll.cpp >& my.comp.errors
and then the text file "my.comp.errors" will contain your compiler errors
(note: if you changed your Unix shell the above may not work).
|
See the class syllabus for policies concerning email Last Modified: Mon Sep 27 23:49:27 EDT 2004 |
|
|
|
|
|