Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "estacionamento.h"
- using estacionamento::Tempo;
- using estacionamento::Cliente;
- using estacionamento::CaixaEstacionamento;
- #include <time>
- using
- //Classe Tempo
- Tempo::Tempo(int hora = 0, int minuto = 0, int segundo = 0)
- throw (invalid_argument){
- if(hora < 0 || hora > 23 || minuto < 0 || minuto > 59 || segundo < 0 || segundo > 59){
- throw invalid_argument("Entrada invalida!");
- }
- else{
- setHora(hora);
- setMinuto(minuto);
- setSegundo(segundo);
- }
- }
- Tempo::Tempo(const Tempo &tempo) throw (invalid_argument){
- if(tempo.getHora() < 0 || tempo.getHora() > 23 || tempo.getMinuto() < 0 || tempo.getMinuto() > 59 || tempo.getSegundo() < 0 || tempo.getSegundo() > 59){
- throw invalid_argument("Hora invalida!");
- }
- else{
- setHora(tempo.getHora());
- setMinuto(tempo.getMinuto());
- setSegundo(tempo.getSegundo());
- }
- }
- const int &Tempo::getHora() const{
- return hora;
- }
- const int &Tempo::getMinuto() const{
- return minuto;
- }
- const int &Tempo::getSegundo() const{
- return segundo;
- }
- const double Tempo::calcularDiferencaHoraAtual() const{
- int horas1 = getHora() * 3600;
- int minutos1 = getMinuto() * 60;
- int segundos1 = getSegundo();
- int total1 = (horas1 + minutos2 + segundos2) / 3600;
- Tempo* tempo2 = getHoraAtual();
- int horas2 = tempo2.getHora() * 3600;
- int minutos2 = tempo2.getMinuto() * 3600;
- int segundos2 = tempo2.getSegundo();
- int total2 = (horas2 + minutos2 + segundos2) / 3600;
- int total3 = total2 - total1;
- return total3;
- }
- void Tempo::setHora(const int &hora) throw (invalid_argument){
- if(hora > 23 || hora < 0){
- throw invalid_argument("Hora invalida!");
- }
- else{
- this -> hora = hora;
- }
- }
- void Tempo::setMinuto(const int &minuto) throw (invalid_argument){
- if(minuto > 59 || minuto < 0){
- throw invalid_argument("Minuto invalido!");
- }
- else{
- this -> minuto = minuto;
- }
- }
- void Tempo::setSegundo(const int &segundo) throw (invalid_argument){
- if(segundo > 59 || minuto < 0){
- throw invalid_argument("Segundo invalido!");
- }
- else{
- this -> segundo = segundo;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement