Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. #include "estacionamento.h"
  2. using estacionamento::Tempo;
  3. using estacionamento::Cliente;
  4. using estacionamento::CaixaEstacionamento;
  5. #include <time>
  6. using
  7.  
  8. //Classe Tempo
  9. Tempo::Tempo(int hora = 0, int minuto = 0, int segundo = 0)
  10. throw (invalid_argument){
  11. if(hora < 0 || hora > 23 || minuto < 0 || minuto > 59 || segundo < 0 || segundo > 59){
  12. throw invalid_argument("Entrada invalida!");
  13. }
  14. else{
  15. setHora(hora);
  16. setMinuto(minuto);
  17. setSegundo(segundo);
  18. }
  19. }
  20. Tempo::Tempo(const Tempo &tempo) throw (invalid_argument){
  21. if(tempo.getHora() < 0 || tempo.getHora() > 23 || tempo.getMinuto() < 0 || tempo.getMinuto() > 59 || tempo.getSegundo() < 0 || tempo.getSegundo() > 59){
  22. throw invalid_argument("Hora invalida!");
  23. }
  24. else{
  25. setHora(tempo.getHora());
  26. setMinuto(tempo.getMinuto());
  27. setSegundo(tempo.getSegundo());
  28. }
  29. }
  30. const int &Tempo::getHora() const{
  31. return hora;
  32. }
  33. const int &Tempo::getMinuto() const{
  34. return minuto;
  35. }
  36. const int &Tempo::getSegundo() const{
  37. return segundo;
  38. }
  39. const double Tempo::calcularDiferencaHoraAtual() const{
  40.  
  41. int horas1 = getHora() * 3600;
  42. int minutos1 = getMinuto() * 60;
  43. int segundos1 = getSegundo();
  44. int total1 = (horas1 + minutos2 + segundos2) / 3600;
  45. Tempo* tempo2 = getHoraAtual();
  46. int horas2 = tempo2.getHora() * 3600;
  47. int minutos2 = tempo2.getMinuto() * 3600;
  48. int segundos2 = tempo2.getSegundo();
  49. int total2 = (horas2 + minutos2 + segundos2) / 3600;
  50. int total3 = total2 - total1;
  51. return total3;
  52. }
  53. void Tempo::setHora(const int &hora) throw (invalid_argument){
  54. if(hora > 23 || hora < 0){
  55. throw invalid_argument("Hora invalida!");
  56. }
  57. else{
  58. this -> hora = hora;
  59. }
  60. }
  61. void Tempo::setMinuto(const int &minuto) throw (invalid_argument){
  62. if(minuto > 59 || minuto < 0){
  63. throw invalid_argument("Minuto invalido!");
  64. }
  65. else{
  66. this -> minuto = minuto;
  67. }
  68. }
  69. void Tempo::setSegundo(const int &segundo) throw (invalid_argument){
  70. if(segundo > 59 || minuto < 0){
  71. throw invalid_argument("Segundo invalido!");
  72. }
  73. else{
  74. this -> segundo = segundo;
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement