// OopHello.C // (c) Burt Rosenberg 1996 // This program demonstrates a basic approach of Object // Oriented Programming. // Also introduces strings as array of char. #include #define MESSAGESIZE 100 class Greetings { const int size = MESSAGESIZE ; char message[MESSAGESIZE] ; public: Greetings( char m[] ) ; void print(void) ; void set(char m[]) ; } ; Greetings::Greetings( char m[] ) { int i = 0 ; while ( m[i] !='\0' ) { message[i] = m[i] ; i = i + 1 ; if ( i == (size-1) ) break ; } // place end of string marker message[i] = '\0' ; } void Greetings::print ( void ) { int i = 0 ; while ( message[i] != '\0' ) { cout << message[i] ; i = i + 1 ; } cout << endl ; } void Greetings::set( char m[] ) { int i = 0 ; while ( m[i] !='\0' ) { message[i] = m[i] ; i = i + 1 ; if ( i == (size-1) ) break ; } // place end of string marker message[i] = '\0' ; } void main() { Greetings hello( "Hello World" ) ; hello.print() ; hello.set( "Goodbye World" ) ; hello.print() ; }