Answers to Project 1 Questions: CMSC 341 -- Fall 2001 -- Project 1 Kyu Bae xxx-xx-5868 Section 201 kyu_bae@yahoo.com / kbae1@umbc.edu 1. (10 points) The project description required you to use the author's vector class to hold the goods on the truck. Describe the programming complexities (the nitty, gritty details that got in your way) that this requirement caused in your code, if any. Do you think the vector was a good choice to hold the goods? If so why? If not, what mechanism do you think would have been better, and why? answer: I didn't have any problems with vector class. I think the vector class was a good choice to hold the goods. Because with the vector class, you can do array indexing, sizing, and copying. By using the vector class, you don't have to allocate a lot of empty memory space in advance for your Goods to be added and waste their memory space when they are not in use (not yet to be added to your list). Vector class creates and allocate memory space as you go and need. This saves a lot of memory spaces and overhead. Since you don't know how many items to be loaded in advance, this vector class is very good choice. You create as you load your item. One of the vector class's member functions is sizing. This functions allows you to increase and decrease your item list anytime. This functions gives convinience of deleting the item, also. You can size list to zero with this. Using vector gives another advantage, object name of vector works like array. This helps a lot in passing it as parameter or print its data members with output operator. 2. (10 points) The Truck class was defined as a template, presumably so it could hold different types of goods. Yet, main( ) had to determine what type of goods were being held in the truck, instantiate the appropriate kind of truck and call a specialized function (delieverPerishableGoods() or deliverEquipment() ) based on the kind of goods held in the truck. Does this mean that making Truck a template was a mistake? Would it have been easier to just make two kinds of trucks since we need to call special functions for each type of truck anyway? Be sure to justify your answer. answer: No, i don't think that making Truck a template was a mistake. Even if you create two kinds of Truck, their functions are identical. Basically you are overloading same function twice. By creating two functions you are wasting a lot of memory / overheads. That is why template is there for. The template eases off the burden of writing one function twice. Although one truck is instantiated and call a specialized function(deliverPerishableGoods() or deliverEquipment() based on the kind of goods held in the truck), two functions use same member functions of Truck class. And they are calling same identical member functions of truck class. So Truck should be a template. Why do you want to create and write another function when you have already written one. If deliverPerishableGoods() requires different functions than deliverEquipment(), then it makes a sense to write two Truck functions.