Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

  • 0
Davide Silva

validação de dados de entrada

Pergunta

/*
Oi Galera, como faço para implementar os seguintes itens abaixo?
● método que imprime a instancia em formato de 12 horas (AM/ PM)
● previousSecond() 
● nextMinute() 
● previousMinute() 
● nextHour() 
● previousHour()
*/
/* Test Driver for the Time class */
#include <iostream>
#include "Time.h"    // include header of Time class
using namespace std;
int main() {
    Time t_2;
    int minut;
    int seg;
    int hor;
    cout<< "\n Informe a hora: ";
    cin>>hor;
    t_2.setHour(hor);
    cout<< "\n Informe o minuto: ";
    cin>>minut;
    t_2.setMinute(minut);
    cout<< "\n Informe o segundo: ";
    cin>>seg;
    t_2.setSecond(seg);
   cout<<"Object t1 state: \n";
   cout << "Hour is "   << t_2.getHour()   << endl;
   cout << "Minute is " << t_2.getMinute() << endl;
   cout << "Second is " << t_2.getSecond() << endl;
   return 0;
}

//=======================================================================================

/* Header for the Time class (Time.h) */
#ifndef TIME_H   // Include this "block" only if TIME_H is NOT defined
#define TIME_H   // Upon the first inclusion, define TIME_H so that
                 //  this header will not get included more than once
class Time {
private:  // private section
   // private data members
   int hour;     // 0 - 23
   int minute;   // 0 - 59
   int second;   // 0 - 59
public:   // public section
   // public member function prototypes
   //Time(int h = 0, int m = 0, int s = 0);        // Constructor with default values
   int getHour() const;                                   // public getter for private data member hour
   void setHour(int h);                                  // public setter for private data member hour
   int getMinute() const;                             // public getter for private data member minute
   void setMinute(int m);                           // public setter for private data member minute
   int getSecond() const;                          // public getter for private data member second
   void setSecond(int s);                          // public setter for private data member second
   void setTime(int h, int m, int s);        // set hour, minute and second
   void print() const;                               // Print a description of this instance in "hh:mm:ss"
   void nextSecond();                            // Increase this instance by one second
};                                                             // need to terminate the class declaration with a semicolon
#endif  // end of "#ifndef" block
//======================================================================================


/* Implementation for the Time Class (Time.cpp) */
#include <iostream>
#include <iomanip>
#include "Time.h"    // include header of Time class
using namespace std;
// Constructor with default values. No input validation
/*Time::Time(int h, int m, int s) {
   hour = h;
   minute = m;
   second = s;
}
*/
// public getter for private data member hour
int Time::getHour() const {
   return hour;
}
// public setter for private data member hour. No input validation
void Time::setHour(int h) {
   hour = h;
}
// public getter for private data member minute
int Time::getMinute() const {
   return minute;
}
// public setter for private data member minute. No input validation
void Time::setMinute(int m) {
   minute = m;
}
// public getter for private data member second
int Time::getSecond() const {
   return second;
}
// public setter for private data member second. No input validation
void Time::setSecond(int s) {
   second = s;
}
// Set hour, minute and second. No input validation
void Time::setTime(int h, int m, int s) {
   hour = h;
   minute = m;
   second = s;
}
// Print this Time instance in the format of "hh:mm:ss", zero filled
void Time::print() const {
   cout << setfill('0');    // zero-filled, need <iomanip>, sticky
   cout << setw(2) << hour  // set width to 2 spaces, need <iomanip>, non-sticky
        << ":" << setw(2) << minute
        << ":" << setw(2) << second << endl;
}
// Increase this instance by one second
void Time::nextSecond() {
   ++second;
   if (second >= 60) {
      second = 0;
      ++minute;
   }
   if (minute >= 60) {
      minute = 0;
      ++hour;
   }
   if (hour >= 24) {
      hour = 0;
   }
}
/* Test Driver for the Time class */
#include <iostream>
#include "Time.h"    // include header of Time class
using namespace std;
int main() {
    Time t_2;
    int minut;
    int seg;
    int hor;
    cout<< "\n Informe a hora: ";
    cin>>hor;
    t_2.setHour(hor);
    cout<< "\n Informe o minuto: ";
    cin>>minut;
    t_2.setMinute(minut);
    cout<< "\n Informe o segundo: ";
    cin>>seg;
    t_2.setSecond(seg);
   cout<<"Object t1 state: \n";
   cout << "Hour is "   << t_2.getHour()   << endl;
   cout << "Minute is " << t_2.getMinute() << endl;
   cout << "Second is " << t_2.getSecond() << endl;
   return 0;
}
 
//=======================================================================================
 
/* Header for the Time class (Time.h) */
#ifndef TIME_H   // Include this "block" only if TIME_H is NOT defined
#define TIME_H   // Upon the first inclusion, define TIME_H so that
                 //  this header will not get included more than once
class Time {
private:  // private section
   // private data members
   int hour;     // 0 - 23
   int minute;   // 0 - 59
   int second;   // 0 - 59
public:   // public section
   // public member function prototypes
   //Time(int h = 0, int m = 0, int s = 0);             // Constructor with default values
   int getHour() const;                                // public getter for private data member hour
   void setHour(int h);                               // public setter for private data member hour
   int getMinute() const;                            // public getter for private data member minute
   void setMinute(int m);                           // public setter for private data member minute
   int getSecond() const;                          // public getter for private data member second
   void setSecond(int s);                         // public setter for private data member second
   void setTime(int h, int m, int s);            // set hour, minute and second
   void print() const;                          // Print a description of this instance in "hh:mm:ss"
   void nextSecond();                          // Increase this instance by one second
};                                            // need to terminate the class declaration with a semicolon
#endif  // end of "#ifndef" block
//======================================================================================
 
 
/* Implementation for the Time Class (Time.cpp) */
#include <iostream>
#include <iomanip>
#include "Time.h"    // include header of Time class
using namespace std;
// Constructor with default values. No input validation
/*Time::Time(int h, int m, int s) {
   hour = h;
   minute = m;
   second = s;
}
*/
// public getter for private data member hour
int Time::getHour() const {
   return hour;
}
// public setter for private data member hour. No input validation
void Time::setHour(int h) {
   hour = h;
}
// public getter for private data member minute
int Time::getMinute() const {
   return minute;
}
// public setter for private data member minute. No input validation
void Time::setMinute(int m) {
   minute = m;
}
// public getter for private data member second
int Time::getSecond() const {
   return second;
}
// public setter for private data member second. No input validation
void Time::setSecond(int s) {
   second = s;
}
// Set hour, minute and second. No input validation
void Time::setTime(int h, int m, int s) {
   hour = h;
   minute = m;
   second = s;
}
// Print this Time instance in the format of "hh:mm:ss", zero filled
void Time::print() const {
   cout << setfill('0');    // zero-filled, need <iomanip>, sticky
   cout << setw(2) << hour  // set width to 2 spaces, need <iomanip>, non-sticky
        << ":" << setw(2) << minute
        << ":" << setw(2) << second << endl;
}
// Increase this instance by one second
void Time::nextSecond() {
   ++second;
   if (second >= 60) {
      second = 0;
      ++minute;
   }
   if (minute >= 60) {
      minute = 0;
      ++hour;
   }
   if (hour >= 24) {
      hour = 0;
   }
}

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

0 respostas a esta questão

Recommended Posts

Até agora não há respostas para essa pergunta


  • Conteúdo Similar

    • Por ale_plie
      Alguém conhece algum algoritimo que calcule em série temporal com picos, tempo de subida e descida, duração e amplitude dos picos não negativos?
       
      calcular tempo de subida e descida em picos em series temporais.
    • Por GilvanBM46
      Rapaziada estou meio adoentado é preciso entregar uma tarefa simples amanha a noite, Preciso fazer um algorítimo em visualg que calcule o tempo gasto de saída de casa é chegada ao trabalho é mostre as horas gastas os minutos gastos é os segundos gastos.
       
      Consegui fazer ate a metade mais não estou conseguindo processar o resto.
      Quem poder da um tombo te agradeço muito. 
      Fiz uma parte 
       
      Var
      he,hs,me,ms,hora:inteiro
       
      Inicio
      escreva ("Digite a hora de entrada: ")
      leia (he)
      escreva ("Digite os minutos de entrada: ")
      leia (me)
      escreva("Digite a hora de saida: ")
      leia (hs)
      escreva ("Digite os minutos de saida: ")
      leia(ms)
      hora:= hs-he
      escreva("Passou", hora , ":horas")
      Fimalgoritmo
    • Por Motta
      Facebook anuncia criação da própria 'unidade de tempo'
      Time is on my side, yes it is.
      Time is on my side, yes it is.
    • Por Davide Silva
      /* Perdão. Desconsiderem o primeiro envio. Como faço para implementar os seguintes itens abaixo? ● método que imprime a instancia em formato de 12 horas (AM/ PM) ● previousSecond() ● nextMinute() ● previousMinute() ● nextHour() ● previousHour() */ /* Test Driver for the Time class */ #include <iostream> #include "Time.h"    // include header of Time class using namespace std; int main() {     Time t_2;     int minut;     int seg;     int hor;     cout<< "\n Informe a hora: ";     cin>>hor;     t_2.setHour(hor);     cout<< "\n Informe o minuto: ";     cin>>minut;     t_2.setMinute(minut);     cout<< "\n Informe o segundo: ";     cin>>seg;     t_2.setSecond(seg);    cout<<"Object t1 state: \n";    cout << "Hour is "   << t_2.getHour()   << endl;    cout << "Minute is " << t_2.getMinute() << endl;    cout << "Second is " << t_2.getSecond() << endl;    return 0; } //======================================================================================= /* Header for the Time class (Time.h) */ #ifndef TIME_H   // Include this "block" only if TIME_H is NOT defined #define TIME_H   // Upon the first inclusion, define TIME_H so that                  //  this header will not get included more than once class Time { private:  // private section    // private data members    int hour;     // 0 - 23    int minute;   // 0 - 59    int second;   // 0 - 59 public:   // public section    // public member function prototypes    //Time(int h = 0, int m = 0, int s = 0);        // Constructor with default values    int getHour() const;                                   // public getter for private data member hour    void setHour(int h);                                  // public setter for private data member hour    int getMinute() const;                             // public getter for private data member minute    void setMinute(int m);                           // public setter for private data member minute    int getSecond() const;                          // public getter for private data member second    void setSecond(int s);                          // public setter for private data member second    void setTime(int h, int m, int s);        // set hour, minute and second    void print() const;                               // Print a description of this instance in "hh:mm:ss"    void nextSecond();                            // Increase this instance by one second };                                                             // need to terminate the class declaration with a semicolon #endif  // end of "#ifndef" block //====================================================================================== /* Implementation for the Time Class (Time.cpp) */ #include <iostream> #include <iomanip> #include "Time.h"    // include header of Time class using namespace std; // Constructor with default values. No input validation /*Time::Time(int h, int m, int s) {    hour = h;    minute = m;    second = s; } */ // public getter for private data member hour int Time::getHour() const {    return hour; } // public setter for private data member hour. No input validation void Time::setHour(int h) {    hour = h; } // public getter for private data member minute int Time::getMinute() const {    return minute; } // public setter for private data member minute. No input validation void Time::setMinute(int m) {    minute = m; } // public getter for private data member second int Time::getSecond() const {    return second; } // public setter for private data member second. No input validation void Time::setSecond(int s) {    second = s; } // Set hour, minute and second. No input validation void Time::setTime(int h, int m, int s) {    hour = h;    minute = m;    second = s; } // Print this Time instance in the format of "hh:mm:ss", zero filled void Time::print() const {    cout << setfill('0');    // zero-filled, need <iomanip>, sticky    cout << setw(2) << hour  // set width to 2 spaces, need <iomanip>, non-sticky         << ":" << setw(2) << minute         << ":" << setw(2) << second << endl; } // Increase this instance by one second void Time::nextSecond() {    ++second;    if (second >= 60) {       second = 0;       ++minute;    }    if (minute >= 60) {       minute = 0;       ++hour;    }    if (hour >= 24) {       hour = 0;    } }    
    • Por RogerTi
      Fala galera blz, estou precisando de um plugin para previsão do tempo, dei uma vasculhada no sr,Google e encontrei alguns mas nada satisfatório, alguém conhece um plugin bacana para previsão do tempo? Plugin capaz de satisfazer o usuário que entre no site a localizar sua própria região ou qualquer outra e pesquisar o tempo nos próximos dias, e dias atuais.
       
      print de como o que achei é
       
      => http://prnt.sc/f03ao4
       
      Código para alguém que queira usar, não encontrei no site onde peguei o script formas de como alterar a cidade, localizei onde é passado a cidade, mas não encontrei uma forma correta de configurar para exibir uma outra
       
      <!--Weather Forecast courtesy of www.tititudorancea.com.br--> <style> .WFOT1 {border:2px solid #E1E1E1; background-color:#F1F1F1; padding:10px} .WFH1 {font:bold 14px Arial, sans-serif; margin-bottom:6px} TABLE.WFOT TD {vertical-align:top} .FCOVTMP {font:14px Arial, sans-serif; line-height:16px; padding-bottom:4px} .FCOVEXP {font:12px Arial, sans-serif; line-height:14px; text-align:center} .WFI {background-color:#3399FF;padding:0} .WTL {color:blue;font-weight:bold} .WTH {color:red;float:right;font-weight:bold} .WFLK {font-size:11px;color:#900;text-decoration:none} .WFDAY {font-size:12px;text-align:center;font-weight:bold} </style> <div style="position:relative;background-color:#FFFFFF"> <div id="wf_div"></div> <script type="text/javascript" src="http://tools.tititudorancea.com/weather_forecast.js?place=rio_de_janeiro_aeroporto&amp;s=1&amp;days=7&amp;utf8=no&amp;columns=7&amp;lang=pt"></script> <div style="font:10px Arial, sans-serif;color:#000000" align="right"><a href="http://www.tititudorancea.com.br/z/tempo_pt.htm">Previsão do tempo</a> fornecido por <a href="http://www.tititudorancea.com.br/">tititudorancea.com.br</a></div> </div> <!--end of Weather Forecast-->  
×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.