// file: lecture_26/myprog.h // // system include files // #include #include #include // define a simple class // class Toaster { protected: // define some data // char* name_d; char* model_d; long len_d; long width_d; float weight_d; // define some simple functions // public: // default constructor // Toaster() { // initialize data // name_d = (char*)NULL; name_d = new char[4]; strcpy(name_d, "Joe"); model_d = (char*)NULL; len_d = (long)0; width_d = (long)0; weight_d = (float)0.0; // display some information about the object // fprintf(stdout, "default constructor: len_d is located at %u\n", &len_d); fprintf(stdout, "default constructor: width_d is located at %u\n", &width_d); } // constructor with arguments // Toaster(long len_a, float weight_a) { // initialize data // name_d = (char*)NULL; name_d = new char[4]; strcpy(name_d, "Joe"); model_d = (char*)NULL; len_d = len_a; width_d = (long)0; weight_d = weight_a; // display some information about the object // fprintf(stdout, "constructor with args: len_d is located at %u\n", &len_d); fprintf(stdout, "constructor with args: width_d is located at %u\n", &width_d); } // default destructor // ~Toaster() { fprintf(stdout, "destructor: hello class!\n"); if (name_d != (char*)NULL) { delete [] name_d; name_d = (char*)NULL; } } long get_len() { return len_d; } long get_width() { return width_d; } float get_weight() { return weight_d; } // define some useful public functions // bool display(FILE* fp, char*); bool set_values() { return set_values(1, 1, 99.0); } bool set_values(long len, long width = 3, float weight = 27.0); // demonstrate an overloaded function // // bool compare(Toaster arg1); // bool compare(Toaster* arg1); // bool compare(Toaster& arg1); private: // print the data of manufacturing // bool display(FILE* fp); // end of class };