ECS 40
ECS 40 Practice Midterm #2 Key
1. (15 points) I have web pages all over my account. Each has a unique name, and has an .html extensions. I would
like to copy all of my web pages to a directory named Web in my home directory. Write a UNIX command line that will
accomplish this task. You may assume that I am in the home directory of my account. You should also be aware that
there are directories with names that end with “html”.
Pts: 2 1 1 1 1 11 1 2 1 1 1 1
find . –type f –name ”*.html” –exec cp {} Web \;
For the rest of this exam you will provide the appropriate C++ code to make the code on the handout work properly.
The program reads in events from a user, and stores them in a double linked list. When the user is done entering events,
the list saves them into a file. Note that the ListNodes actually store pointers to the data type (Date* in this program).
There is no need for comments.
3. (22 points) Provide the implementation code for the save method of the List class that would be in list.h. The method
writes to the specified file, and deletes the ListNodes. The header is provided. You may wish to do #4 first.
Pts
void save(const char *filename) {
3 ofstream outf(filename);
9 for(ListNode
{
4 ptr->data->print(outf);
4 head = ptr->next;
2 delete ptr;
} // for
}
4. (66 points) Provide the complete DateTime.h file including all preprocessor directives appropriate for a large multi-file
program. The file should include all of the code necessary to implement the DateTime class. The DateTime class is
derived from the Date class, and contains an int hour, and int minute. The DateTime class has two methods, a normal
constructor and print(). Note that your print() method must format the line to match the output in the example.
1234567890123456789
June 7 8:03
Pts
2 #ifndef DateTimeH
2 #define DateTimeH
2 #include
2 #include
2 #include “date.h”
3 using namespace std;
4 class DateTime : Date
{
2 int hour;
2 int minute;
1 public:
18 DateTime(const char *mo, int d, int h, int m):Date(mo,d), hour(h),
minute(m){}
5 void print(ostream &os) const{
19 os << setw(10) << getMonth() << setw(3) << day << setw(3)
<< hour << ":" << setfill('0') << setw(2) << minute << setfill(' ')
<< endl;
}
1 };
1 #endif
5. (57 points) Provide the implementation code for the List insert method that would appear in list.cpp. Beware that you
are dealing with pointers to Dates. The list sorted using the operator<.
Pts
3 template
7 void List
{
5 ListNode
14 for(ptr = head; ptr && *(ptr->data) < *d; ptr = ptr->next)
prev = ptr;
2 if(prev)
{
7 prev->next = new ListNode
2 if(ptr)
4 ptr->prev = prev->next;
}
1 else
{
6 head = new ListNode
2 if(ptr)
4 ptr->prev = head;
}
}