-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstopwatch.cpp
85 lines (72 loc) · 1.83 KB
/
stopwatch.cpp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <conio.h>//para ver que tecla ha sido presionada//kbhit()
#include <stdlib.h>
#include <time.h>
#include <thread>//necesario
#include <chrono>//necesario
#include <stdio.h>
#include <sstream>
using namespace std;
using namespace std::this_thread;//sleep for//hacer que el programa duerma por una cantidad de tiempo
using namespace std::chrono;
string tiempoTranscurrido (int x, int y, int z);
int main (){
int s=0;
int m=0;
int h=0;
string c;
cout<<"Pulse una tecla para empezar a cronometrar";
getch();
system("cls");
while(!kbhit()){//mientras no se pulse ninguna tecla
cout<<"\nPulse una tecla para dejar de cronometrar: ";
ostringstream hour;
ostringstream min;
ostringstream sec;
string horas;
string minutos;
string segundos;
hour<<h;
min<<m;
sec<<s;
if(hour.str().size()==1){
horas="0"+hour.str();
}
else{
horas=hour.str();
}
if(min.str().size()==1){
minutos ="0"+min.str();
}
else{
minutos=min.str();
}
if(sec.str().size()==1){
segundos ="0"+sec.str();
}
else{
segundos=sec.str();
}
cout<<horas<<":"<<minutos<<":"<<segundos;
s++;
if (s==60){
s=0;
m++;
if(m==60) {
m=0;
h++;
}
}
sleep_for (seconds(1));//sleep for (min, seconds,hours(tiempo))
system ("cls");
c=tiempoTranscurrido (h, m, s);
}
cout<<"Tiempo transcurrido: "<<c;
}
string tiempoTranscurrido (int x, int y, int z){
string tempo;
ostringstream t;
t<<x<<":"<<y<<":"<<z;
tempo =t.str();
return tempo;
}