Hi!! Please I need on a program in C++. Well I have to complete the following program. The objective is that the program asks the user a number and the user writes 10 for example but the user must say if he wants to add this number to the hours, minutes or seconds. Another trouble is that if the user writes -10 the program must not add but subtract. Finally if we have set 9:30:56 and the user enters 10 the program must add 4 seconds to the seconds and the rest to the minutes, just as real life. Please help me!!!!
The program is right here!!
#include "stdafx.h"
#include <iomanip>
#include <iostream>
using namespace std;
class Hora
{
private:
int horas; // 0 - 23 (formato 24-horas )
int minutos; // 0 - 59
int segundos; // 0 -59
public:
Hora(); // Constructor
void setHoras( int h); //Fija Horas
void setMinutos( int m); //Fija Minutos
void setSegundos( int s); //Fija Segundos
int getHoras(); // Retorna las horas
int getMinutos(); // Retorna los minutos
int getSegundos(); // Retorna los segundos
int compara(Hora h); //Se compara con h
void mostrar(); // Imprime la hora.
};
// Implementacion de la clase hora
Hora::Hora()
{ setHoras(0); setMinutos(0); setSegundos(0);
}
void Hora::mostrar() // Imprime la hora.
{ cout << setfill( '0' ) << setw( 2 ) << horas << ":";
cout << setfill( '0' ) << setw( 2 ) << minutos << ":";
cout << setfill( '0' ) << setw( 2 ) << segundos;
}
void Hora::setHoras(int h) // Fija Hora
{ horas = ( h >= 0 && h < 24 ) ? h : 0; // valida la hora
}
void Hora::setMinutos(int m) // Fija Minuto
{ minutos = ( m >= 0 && m < 60 ) ? m : 0; // valida minutos
}
void Hora::setSegundos( int s) // Fija Segundos
{ segundos = ( s >= 0 && s < 60 ) ? s : 0; // valida segundos
}
int Hora::getHoras() // Retorna las horas
{ return horas;
}
int Hora::getMinutos() // Retorna los minutos
{ return minutos;
}
int Hora::getSegundos() // Retorna los segundos
{ return segundos;
}
int Hora::compara(Hora h) //Se compara con h
{ if (horas > h.getHoras()) return 1;
if (horas < h.getHoras()) return -1;
if (minutos > h.getMinutos()) return 1;
if (minutos < h.getMinutos()) return -1;
if (segundos > h.getSegundos()) return 1;
if (segundos < h.getSegundos()) return -1;
return 0;
}