Date: Mon, Oct 11 17:07:34 > As far as the style of commenting goes for our header files, can I have all > the function comments below the actual class declaration, or must they be > right before the declaration of each function in the class declaration? The latter > method seems to make the class body very cluttered. Either style is acceptable.
Date: Sun, 10 Oct 1999 15:17:10 > I have a quick question about Proj2. The assignment says not to make > any changes to Proj2.C, but would it be okay to add #includeand > set_new_handler () for memory checking purposes? Certainly.
Date: Fri, 8 Oct 1999 13:45:24 > 1. I went to the tutor and ask them about the Empty() which I used > ~ClassList() inside the Empty(). She told me that we should not use > that. So what is destructor for then? Let's start by emphasizing the distinction between emptying a list and destroying a list. In my design of the ClassList class, a ClassList object can exist and be empty. In fact, when a ClassList object is intially constructed, it is empty. A hidden assumption in my design is that the programmer will empty a list when he/she has finished using the list. Under this assumption, the ClassList class does not need a destructor, and I have not asked you to write one. Actually, this is not a particularly good assumption, and it is especially bad because I never documented it. Even if I had, there is no guarrantee that the programmer would remember to empty the list, and so there is great potential for a memory leak here. A better design approach would be to provide a destructor that automatically empties the list before it is destroyed. To return to your question, remember that in general, programmers don't explicitly make calls to destructors. Destructors get called "behind the scene" when an object is destroyed. Even it is was legal to do so, we wouldn't want to call the destructor in the Empty() function, because we may want to re-use the list after it has been emptied. On the other hand, if you decide to add a destructor to the ClassList class, you could have the destructor call Empty(). > 2. How can you use the Prepend function? Proj1 we have CreateNode which > return StudentNode* but in the P2, we have only constructor.(it does not > return anything) Lines such as: StudentNode* newNode = CreateNode (aStudent); would be replaced by: StudentNode* newNode = new StudentNode (aStudent);
Date: Fri, 8 Oct 1999 13:17:55 > In our makefile does the ( .o) file which we used for c get captialized > to a (.O) file for c++ > > A logical question, but no, all object files are customarily named with a (lowercase) .o extension on the UNIX system, regardless of the source language.
Date: Thu, 7 Oct 1999 12:38:22 > > In writing the default constructor for the StudentNode class is it > ok to do the following: > > StudentNode::StudentNode (Student* aStudent) > { > _data = aStudent; > _next = null; > } > This is perfectly legal and, in fact, correct (or almost correct - null should be all uppercase - i.e, NULL). Be careful, though, you shouldn't be calling this a "default" constructor. A "default" constructor doesn't have any arguments. So clearly this is a non-default constructor. > If the above is OK then we would not need to make a StudentNode > destructor since the Student destructor would be called > when the StudentNode object went out of scope. Both parts of this sentence are incorrect. You DO need a destructor for StudentNode. If you look back at Project 1, when a StudentNode is destroyed, it is the node's responsibility to destroy the Student that "data" points at. Although this is not the only way to design the linked list implementation, it is the one that I chose and I would like you to follow. Also, remember that Student's are allocated dynamically, so the issue of "out of scope" does not apply.
Date: Thu, 7 Oct 1999 12:24:07 > Is the GetGpaSum() function supposed to return the "sum" > of all student gpa's, or should it return the average of all student > gpa's? The average would tell you in general how well the students are > doing. The sum would be over 4.00, and wouldn't stand for anything, would > it? The function should return the sum, not the average. I agree that this result is not terribly useful. The function is mainly there for purposes of testing and grading the project. I could have also asked you to calculate the average, but then there would probably be a lot of questions about how many decimal places to show, and we haven't yet discussed that aspect of C++ I/O. If we do want to calculate the average, we can simply use this function together with the GetCount() function.
Date: Wed, 6 Oct 1999 10:30:15 > what is the correct number of spaces to indent in our projects? > The number of the spaces is not as important as the presence and CONSISTENT use of indentation where needed. I recommend 3 or 4, and my personal preference is 4. I believe that 1 or 2 spaces is not enough to make the indentation obvious. If you use larger numbers (for example, typically the TAB key gives you an indentation level of 8 spaces), you will quickly find yourself running off the edge of the screen when writing code involving nested loops, if-structures, etc.
Date: Sat, 2 Oct 1999 14:11:28 > How do we format our output with cout? For example, > if I wanted the id number to be displayed in a field of 8, how would I > write this using cout? We'll cover this later in the course. (If you want to look ahead, see Chapter 6 in the textbook.) But for now, here's a fairly easy way to do that. I'll show an example: ------------------------------------------------ (Need to include the header file iomanip.h) int n = 7, a = 5; cout << setw(5) << n << setw(8) << a << endl; ------------------------------------------------ Output is: ____7_______5 (where _ represents a space)
Date: Sat, 2 Oct 1999 13:51:00 > On the web page, it says that for Student.H there is a > function called Print(), and it is supposed to replace the PrintList() > function. Is this a mistake? Printlist() doesn't exist in Student.H, it > exists in ClassList.H. Shouldn't Print() in Student.H be replacing the > "PrintStudent" function instead? > Yes, another typo on my part. Thanks for finding it. I will fix it.
Date: Sat, 2 Oct 1999 10:22:18 > It appears to me that there may be an oversight in Proj2 instructions at > Task 3. the forth bullet item where it states: > o A function called Print() (replaces the Printlist() function): > > Unless I do not understand the complete picture at this early stage of > completing proj2, it appears that within Student.C we would have a print > function that would replace the PrintStudent() function from Student.c, > and later on in Classlist.C we would have a member function Print() that > would replace the PrintList() function. This later ClassList member > function would most likely call the Print() member function in the Student > class... > Nothing wrong (and in fact quite "normal") for two or more classes to have a function by the same name. This is a good example of what is referred to as "class scope". The question of which Print() function is to be called will be determined by the data type of the host object for which the function is invoked. So yes, the Print() function in ClassList will call the Print() function in the Student class. The reason I had you change the names: When you write functions in the context of a class the type of object being operated on is implied. When the function is called, it is also apparent from the data type (and hopefully the name) of the host object. So instead of: theList.PrintList(); // somewhat redundant we can just have: theList.Print(); // improved readability