Conversión de long a clase
Publicado por flwrd21 (1 intervención) el 31/03/2018 15:29:41
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <iomanip>
using namespace std;
class Tiempo{
private:
int h;
int m;
int s;
public:
Tiempo(int=22, int=15, int=59);
void setTime(int, int, int);
void getTime();
Tiempo(long);
//~Tiempo();
}; //fin declaracion de la clase
//IMPLEMENTACION
Tiempo::Tiempo(int hs, int min, int seg)
{
h=hs;
m=min;
s=seg;
}
//Tiempo::~Tiempo(){cout<<"\n soy el DESTRUCTOR de: ";}
Tiempo::Tiempo(long horafinal)
{
h=int(horafinal/3600);
m=int(((horafinal/3600)-h)*60);
s=int((((horafinal/3600)-h)-m)*60);
}
void Tiempo::setTime(int hs, int min, int seg)
{
h=hs;
m=min;
s=seg;
return;
}
void Tiempo::getTime()
{
cout<<"Hey bitch, the time is: ";
cout<<setfill('0')
<<setw(2)<<h<<":"
<<setw(2)<<m<<":"
<<setw(2)<<s;
cout<<endl;
return;
}
int main(){
//creo objetos tipo time:
Tiempo a, b, c(8,5,59), d(30336);//para la hora c se estableció anteponiendo como type el nombre de la clase y entre () los parameters, bitch-
b.setTime(16,29,59);
a.getTime();
b.getTime();
c.getTime();
d.getTime();
a=Tiempo(52200);
cout<<"El tiempo en a era 22:15:59, ahora es ";
a.getTime();
return 0;
}
Valora esta pregunta


0