// file: foo.cc // // system include files // #include #include // define a simple class // class Toaster { protected: // define some data // long len_d = (long)0; long width_d = (long)0; float weight_d = (float)0.0; // define some simple functions // public: long get_len() { return len_d; } long get_width() { return width_d; } float get_weight() { return weight_d; } // define some functions // bool display(FILE* fp, char*); bool set_values(long len, long width, float weight); // demonstrate an overloaded function // // bool compare(Toaster arg1); // bool compare(Toaster* arg1); // bool compare(Toaster& arg1); private: // end of class }; // define a main program // int main(int argc, char** argv) { // declare an object // Toaster kitchenaide; Toaster bosch; // set some values // kitchenaide.set_values(10, 5, 27.0); kitchenaide.display(stdout, (char*)"kitchenaide"); // print some stuff // bosch.display(stdout, (char*)"bosch"); // exit gracefully // return(0); } // method: display() // bool Toaster::display(FILE* fp, char* str) { // print the contents // fprintf(fp, "object name: %s\n", str); fprintf(fp, "length = %d\n", len_d); fprintf(fp, "width = %d\n", width_d); fprintf(fp, "weight = %f\n", weight_d); // exit gracefully // return true; } // method: set_values() // bool Toaster::set_values(long len_a, long width_a, float weight_a) { // assign values // len_d = len_a; width_d = width_a; weight_d = weight_a; // exit gracefully // return true; }