// file: lecture_37/car_00.cc // local include files // #include "car.h" // define a data structure to track all cars being manufactured // //LinkedList cars; // implement a destructor // Car::~Car() { fprintf(stdout, "....> executing the destructor\n"); 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 | weight = %f\n", str, model_d, color_d, weight_d); fprintf(stdout, "weight_d is located at: %u\n", &weight_d); } // default constructor // Car::Car(char* model_a, char* color_a, float weight_a) { fprintf(stdout, "**> hello world from the constructor\n"); // 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); // set the weight // weight_d = weight_a; // display the instance // //myprint((char*)"Default Constructor", stdout); } // method: set // void Car::set(char* model_a, char* color_a, float weight_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); weight_d = weight_a; } // initialize static variables // float Car::weight_d = (float)-1.0;