13.07.2015 Views

29 The Power of Inheritance and Polymorphism

29 The Power of Inheritance and Polymorphism

29 The Power of Inheritance and Polymorphism

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Inheritance</strong> <strong>and</strong> <strong>Polymorphism</strong> 1044#if defined(SYMANTEC)fputc(ch, stdout);fflush(stdout);#elifputch(ch);#endif}Functions like WindowRep::Delay() <strong>and</strong> WindowRep::GetChar() similarlyrepackage code from "Cursor Graphics" example.<strong>The</strong> WindowRep::Putcharacter() function only does the cursor movement<strong>and</strong> character output operations when necessary. This function also keeps theWindowRep object's image array consistent with the screen.void WindowRep::PutCharacter(char ch, int x, int y){if((xCG_WIDTH)) return;if((yCG_HEIGHT)) return;}if(ch != fImage[y-1][x-1]) {MoveCursor(x,y);PutCharacter(ch);fImage[y-1][x-1] = ch;}<strong>The</strong> CloseDown() function clears the screen, performs any device specifictermination, then after a short delay lets the WindowRep object self destruct.void WindowRep::CloseDown(){Clear();#if defined(SYMANTEC)csetmode(C_ECHO, stdin);#endifsWindowRep = NULL;Delay(2);delete this;}Window<strong>The</strong> constructor for class Window initializes the simple data members like the width<strong>and</strong> height fields. <strong>The</strong> foreground <strong>and</strong> background arrays are created. <strong>The</strong>y arevectors, each element <strong>of</strong> which represents an array <strong>of</strong> characters (one row <strong>of</strong> theimage).Window::Window(int x, int y, int width, int height,char bkgd, int framed ){fX = x-1;fY = y-1;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!