#include using namespace std; void sec2ore (); void ore2sec (); void get_ore (int&,int&); void get_minuti (int&,int&); int get_totale (int,int,int); int main () { //Dichiarazione variabili char scelta; //Scelta azione cout << "Scegli come vuoi convertire:\n" << "a) da secondi in ore, minuti, secondi\n" << "b) da ore, minuti, secondi in secondi\n" << "Inserisci la tua scelta (a/b): "; cin >> scelta; //Richiamo funzione adeguata switch (scelta) { case 'a': sec2ore(); break; case 'b': ore2sec(); break; default: cout << "Scelta non ammessa!" << endl; } return(0); } void sec2ore () { //Dichiarazione variabili int secondi=0, minuti=0, ore=0, totale=0; //Rihiesta e acquisizione dati cout << "Inserisci i secondi: "; cin >> totale; //Conversione secondi = totale; get_ore(secondi, ore); get_minuti(secondi, minuti); cout << totale << " secondi equivale a " << ore << " ore, " << minuti << " minuti e " << secondi << " secondi." << endl; } void ore2sec () { //Dichiarazione variabili int secondi=0, minuti=0, ore=0, totale=0; //Rihiesta e acquisizione dati cout << "Inserisci le ore: "; cin >> ore; cout << "Inserisci i minuti: "; cin >> minuti; cout << "Inserisci i secondi: "; cin >> secondi; //Conversione totale = get_totale(ore, minuti, secondi); cout << ore << " ore, " << minuti << " minuti e " << secondi << " secondi equivale a " << totale << " secondi." << endl; } void get_ore (int& sec, int&ore) { ore = sec/3600; sec = sec%3600; } void get_minuti (int& sec, int&min) { min = sec/60; sec = sec%60; } int get_totale (int ore, int min, int sec) { return (ore*3600 + min*60 + sec); }