// ptr13.cpp By: Aiman Hanna - ©1993-2006 Aiman Hanna // This is the same program as ptr11.cpp except that it is using arrays // instead of pointers. #include "ptr13.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 car::GetNumCyl() { return num_cyl; } void car::SetNumCyl(int nc) { num_cyl = nc; } int main() { car car_arr[3]; // Declare 3 car objects car_arr[0].SetModel( "BMW" ); car_arr[0].SetColor( green ); car_arr[1].SetModel( "VW" ); car_arr[1].SetColor(); car_arr[2].SetModel( "BENZ" ); car_arr[2].SetColor( black ); for (int i = 0; i < 3 ; i++) { cout << "\n The model of car # " << i+1 << " is: " << car_arr[i].GetModel(); cout << "\n and its color is: " << car_arr[i].GetColor() << "\n"; cout << " The name of this model consists of " << strlen( car_arr[i].GetModel() ) << " characters \n"; } 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 name of this model consists of 3 characters The model of car # 2 is: VW and its color is: white The name of this model consists of 2 characters The model of car # 3 is: BENZ and its color is: black The name of this model consists of 4 characters */