// Crea la struttura Time #include using namespace std; #include // structure definition struct Time { public: // non e' necessario perche' senza specificatore si ha public !! void set_values(int, int, int); int ore() {return (hour);}; int minuti() {return (minute);}; int secondi() {return (second);}; private: int hour; // 0-23 (24-hour clock format) int minute; // 0-59 int second; // 0-59 }; // end struct Time void Time::set_values (int a, int b, int c){ hour = a; minute = b; second = c; } void printUniversal ( Time & ); void printStandard ( Time & ); int main() { Time dinnerTime; dinnerTime.set_values(18,30,0); cout << "Dinner will be held at "; printUniversal( dinnerTime );//struttura passata per riferimento ad una funzione cout << " universal time, \n which is "; printStandard( dinnerTime ); cout << " standard time." << endl; return (0); } // end main // print time in universal-time format void printUniversal( Time& t ) { cout << setfill( '0' ) << setw( 2 ) << t.ore() << ":" << setw( 2 ) << t.minuti() << ":" << setw( 2 ) << t.secondi(); } // print time in standard-time format void printStandard( Time &t ) { cout << ( ( t.ore() == 0 || t.ore() == 12 ) ? 12 : t.ore() % 12 ) << ":" << setfill( '0' ) << setw( 2 ) << t.minuti() << ":" << setw( 2 ) << t.secondi() << ( t.ore() < 12 ? " AM" : " PM" ); } //g++ -o Struct_Time Struct_Time.cc //./Struct_Time // Dinner will be held at 18:30:00 universal time, // which is 6:30:00 PM standard time.