312-174
Lab 1
Spring 2000
Due (PreLab, bridge): beginning of class, Friday, 28 Jan.
Due (Lab): beginning of class, Monday, 31 Jan.
Due (PostLab): Monday, 31 Jan, beginning of class.
For this lab you are to complete the following items.
- Complete prelab 1 and the bridge exercise from the Data Structures in C++
lab manual by Roberge. Note that this must be turned in by the end of your lab
period. You may work in pairs for the PreLab and bridge. For the prelab
you have only to implement the member functions Logbook (the constructor), putEntry,
getEntry, month, year, daysInMonth, and leapYear.
- You must next complete in-lab exercise 1 from the lab book.
The Lab must be done individually.
- Finally, you must complete a postlab exercise 1 from the book. This must be done individually and is due
Monday 31 January at the beginning of class.
Late prelabs, bridges, and postlabs will be penalized as described in the study guide.
All results must be put into the appropriate lab folder on
the cs174jb nova account.
All prelabs must have a heading identifying the people who worked on the
project. Programs must also contain appropriate comments. See the style
sheets.
Additional requirements:
- You must include pre and post conditions in every member function that
you write (both preLab and Lab).
- Your member functions must check for any requirements (preconditions) that
are part of the ADT structure given on pages 2 and 3. If the requirements
are not met by the parameters, the member functions must provide a proper
responce.
- Add to the Test Plan for Test 1:
Test case Logbook month No. of days in month Checked
Incorrect input 15 1999 30
Hints:
- You may have to change test.cpp to read int main() instead of
void main() depending on the compiler you use.
- Note the colon following the function declaration on page 10 of the lab manual.
This indicates an initialization list. The list consists of members of the class. The
value in parenthesis are the values that these members are to take. Thus the list
logMonth(month), logYear(year) has the effect of:
{
logMonth = month;
logYear = year;
}
You may use initialization lists in your code of you may do explicit initialization in
the body of the constructor. Note that const and reference members (declared
with the ampersand operator, ie & ) must be initialized using
initialization lists.
Further, note that class members may not contain initializations. In other words
the following is illegal:
class logBook
{ public:
/* declarations */
private:
logMonth = 1; // illegal
logYear = 99; // illegal
};
- If you want to do an initialization by default, you can use the following type of
constructor:
logBook::logBook(int month = 1, int year = 99)
: logMonth(month), logYear(year)
{ /* empty body */ }
This constructor takes from 0 to 2 parameters and you would no longer need to define any
other constructor.
Return to Student Pages
Return to John Barr's Home Page
Last Modified: 4 January 2000
THIS PAGE MAINTAINED BY:
John Barr, Ithaca College