//arrayoftimes.cpp //a very abbreviated version of time #include //cout, endl using namespace std; class Time{ public: void set(int hr, int min); void display(); private: int hour; int minute; }; void Time::set(int hr, int min) {hour=hr; minute=min;} void Time::display() { cout << hour << ':'; if (minute<10) cout << '0'; cout << minute; } //global functions //using an array as an a parameter void firstandlast(Time theArray[ ],int arraySize); //can use an array element as a parameter Time swap( Time & a, Time & b); int main() { Time schedule[5]; //an array always uses the default constructor schedule[0].set(6,40); schedule[1].set(7,0); schedule[2].set(3,20); schedule[3].set(10,45); int i; for(i=0;i<=3;i++) { schedule[i].display(); //an entry calling a member function cout << endl; } firstandlast(schedule,4); //no brackets when the //whole array is the argument //Arrays always passed by reference for(i=0;i<=3;i++) { schedule[i].display(); cout << endl; } Time snack; snack.set(16,30); swap(snack,schedule[1]); //an entry as an argument schedule[1].display(); return 1; } void firstandlast(Time theArray[ ],int arraySize) { cout << "First time : "; theArray[0].display(); cout << endl; cout << "Last time : "; theArray[arraySize-1].display(); cout << endl; //Let's change the array theArray[0].set(12,5); return; } Time swap( Time & a, Time & b) { Time temp=a; a=b; b=temp; return a; }