// file: lecture_37/car.h // local include files // #include "car.h" // define a data structure to track all cars being manufactured // //LinkedList cars; // implement a destructor // Car::~Car() { if (model_d != (char*)NULL) { delete [] model_d; } if (color_d != (char*)NULL) { delete [] color_d; } // exit gracefully // } // implement a print method // void Car::myprint(char* str, FILE* fp) { fprintf(fp, "(%s): model = %s | color = %s\n", str, model_d, color_d); } // default constructor // Car::Car(char* model_a, char* color_a) { // create a copy of the argument // model_d = new char[strlen(model_a) + 1]; strcpy(model_d, model_a); // create a copy of the argument // color_d = new char[strlen(color_a) + 1]; strcpy(color_d, color_a); // display the instance // myprint((char*)"Default Constructor", stdout); } // method: set // void Car::set(char* model_a, char* color_a) { if (model_d != (char*)NULL) { delete [] model_d; } model_d = new char[strlen(model_a) + 1]; strcpy(model_d, model_a); if (color_d != (char*)NULL) { delete [] color_d; } color_d = new char[strlen(color_a) + 1]; strcpy(color_d, color_a); }