Unformatted text preview:

Object Oriented Programming Using C CLASS 17 IDLOOPC1998 1 Objectives Change a type specific Array class to a template IDLOOPC1998 2 include iostream h template class T class Array friend ostream operator ostream const Array friend istream operator istream Array Fig 8 4 Pg 474 IDLOOPC1998 3 include iostream h template class T class Array friend ostream operator ostream const Array T friend istream operator istream Array T Fig 8 4 Pg 474 IDLOOPC1998 4 public Array int 10 Array const Array Array int getSize const const Array operator const Array bool operator const Array const bool operator const Array right const return this right int operator int const int operator int const static int getArrayCount Fig 8 4 Pg 474 IDLOOPC1998 5 public Array int 10 Array const Array T Array int getSize const const Array T operator const Array T bool operator const Array T right const bool operator const Array T const return this right T operator int const T operator int const static int getArrayCount Fig 8 4 Pg 474 IDLOOPC1998 6 private int ptr int size static int arrayCount Fig 8 4 Pg 474 IDLOOPC1998 7 private T ptr int size static int arrayCount Fig 8 4 Pg 474 IDLOOPC1998 8 Initialize static data member at file scope int Array arrayCount 0 Fig 8 4 Pg 475 IDLOOPC1998 9 Initialize static data member at file scope int Array T arrayCount 0 Fig 8 4 Pg 475 IDLOOPC1998 10 Array Array int arraySize size arraySize 0 arraySize 10 ptr new int size assert ptr 0 arrayCount for int i 0 i size i ptr i 0 Fig 8 4 Pg 475 IDLOOPC1998 11 Array T Array int arraySize size arraySize 0 arraySize 10 ptr new T size assert ptr 0 arrayCount for int i 0 i size i ptr i 0 Fig 8 4 Pg 475 IDLOOPC1998 12 Array Array const Array init size init size ptr new int size assert ptr 0 arrayCount for int i 0 i size i ptr i init ptr i Fig 8 4 Pg 475 IDLOOPC1998 13 Array T Array const Array T init size init size ptr new T size assert ptr 0 arrayCount for int i 0 i size i ptr i init ptr i Fig 8 4 Pg 475 IDLOOPC1998 14 Array Array arrayCount delete ptr Get the size of the array int Array getSize const return size Fig 8 4 Pg 475 IDLOOPC1998 15 Array T Array arrayCount delete ptr Get the size of the array int Array T getSize const return size Fig 8 4 Pg 475 IDLOOPC1998 16 Overloaded assignment operator const Array Array operator const Array right if size right size delete ptr size right size ptr new int size assert ptr 0 for int i 0 i size i ptr i right ptr i return this Fig 8 4 Pg 476 IDLOOPC1998 17 Overloaded assignment operator const Array T Array T operator const Array T right if size right size delete ptr size right size ptr new T size assert ptr 0 for int i 0 i size i ptr i right ptr i return this Fig 8 4 Pg 476 IDLOOPC1998 18 int Array operator const Array right const if size right size return false for int i 0 i size i if ptr i right ptr i return false return true Fig 8 4 Pg 476 IDLOOPC1998 19 int Array T operator const Array T right const if size right size return false for int i 0 i size i if ptr i right ptr i return false return true Fig 8 4 Pg 476 IDLOOPC1998 20 const int Array operator int subscript check for subscript out of range error assert 0 subscript subscript size return ptr subscript Fig 8 4 Pg 476 IDLOOPC1998 21 const T Array T operator int subscript check for subscript out of range error assert 0 subscript subscript size return ptr subscript Fig 8 4 Pg 476 IDLOOPC1998 22 int Array getArrayCount return arrayCount istream operator istream input Array a for int i 0 i a size i input a ptr i return input Fig 8 4 Pg 477 IDLOOPC1998 23 int Array T getArrayCount return arrayCount istream operator istream input Array T a for int i 0 i a size i input a ptr i return input Fig 8 4 Pg 477 IDLOOPC1998 24 ostream operator ostream output const Array a for int i 0 i a size i output a ptr i if i 1 4 0 output endl if i 4 0 output endl return output Fig 8 4 Pg 477 IDLOOPC1998 25 ostream operator ostream output const Array T a for int i 0 i a size i output a ptr i if i 1 4 0 output endl if i 4 0 output endl return output Fig 8 4 Pg 477 IDLOOPC1998 26 main cout of arrays instantiated Array getArrayCount Array integers1 7 integers2 cout of arrays instantiated Array getArrayCount endl endl Fig 8 4 Pg 477 IDLOOPC1998 27 main cout of arrays instantiated Array int getArrayCount Array int integers1 7 integers2 cout of arrays instantiated Array int getArrayCount endl endl Fig 8 4 Pg 477 IDLOOPC1998 28 Garage Stack Template IDLOOPC1998 29 The SCRATCHEMUP parking garage contains a single lane that holds up to 10 cars There is only a single entrance exit to the garage at one end of the lane If a customer arrives to pick up a car that is not nearest the exit all cars blocking it s path are moved out the customer s car is driven out and the other cars are restored in the same order that they were in originally IDLOOPC1998 30 Write a program that processes a group of input lines Each input line contains an A for arrival or a D for departure and a license plate number Cars are assumed to arrive and depart in the order specified by the input The program should print a message whenever a car arrives or departs When a car arrives the message should specify whether or not there is room for the car in the garage If there is no room the car leaves without entering the garage IDLOOPC1998 31 GARAG E 121 IDLOOPC1998 32 GARAG E 121 333 IDLOOPC1998 33 GARAG E 121 333 297 IDLOOPC1998 34 GARAG E 121 333 297 IDLOOPC1998 35 GARAG E 121 297 333 IDLOOPC1998 36 GARAG E 297 333 IDLOOPC1998 37 GARAG E 333 297 IDLOOPC1998 38 GARAG E 333 297 IDLOOPC1998 39 Exercises Page 665 IDLOOPC1998 40 Exercises a friend void f1 Page 665 IDLOOPC1998 41 Exercises a friend void f1 friend of all template classes instantiated Page 665 IDLOOPC1998 42 Exercises b friend void f2 C1 T1 Page 665 IDLOOPC1998 43 Exercises b friend void f2 C1 T1 friends of only a friend of C1 particular type Page 665 IDLOOPC1998 44 Exercises c friend void C2 f4 Page 665 IDLOOPC1998 45 Exercises c friend void C2 f4 f4 is part of C2 class a friend of all Page 665 IDLOOPC1998 46 Exercises d friend void C3 T1 f5 C1 T1 Page 665 IDLOOPC1998 47 Exercises d friend void C3 T1 f5 C1 …


View Full Document

SMU CSE 2341 - Object-Oriented Programming Using C++

Loading Unlocking...
Login

Join to view Object-Oriented Programming Using C++ and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Object-Oriented Programming Using C++ and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?