// ptr10.cpp By: Aiman Hanna - ©1993-2006 Aiman Hanna // This program gives more information about pointers to objects. #include "ptr9.h" car::car(int doors, int cyl) { num_doors = doors; num_cyl = cyl; } char* car::GetModel() { return car_model; } void car::SetModel(char* mdl) { car_model = mdl; } void car::SetColor( avail_colors col) { car_color = col; } char* car::GetColor() { switch (car_color) { case white: return "white"; case black: return "black"; case green: return "green"; case red: return "red"; } return "Unknown"; } int main() { car *car_ptr = new car[3], *tmp_ptr; // Declare 3 car objects tmp_ptr = car_ptr; car_ptr -> SetModel( "BMW" ); car_ptr -> SetColor( green ); car_ptr++; car_ptr -> SetModel( "VW" ); car_ptr -> SetColor(); car_ptr++; car_ptr -> SetModel( "BENZ" ); car_ptr -> SetColor( black ); car_ptr = tmp_ptr; // Set it back to it initial place. for (int i = 0; i < 3 ; i++) { cout << "The model of car # " << i+1 << " is: " << car_ptr -> GetModel() << "\n"; cout << " and its color is: " << car_ptr -> GetColor() << "\n"; car_ptr++; } return 0; } // The following is the result of compilation //Compilation successful // The following is the result of running the program /* The model of car # 1 is: BMW and its color is: green The model of car # 2 is: VW and its color is: white The model of car # 3 is: BENZ and its color is: black */