Popular Posts

25. Write a program using constructors and destructors and show elapsed time .

25. Write a program using constructors and destructors and show elapsed time .


#include
#include
#include
class timer
{
clock_t start;
public:
timer();
~timer();
};
timer::timer()
{
start=clock();
}
timer::~timer()
{
clock_t end;
end=clock();
cout<<"Elapsed time: "<<(end-start)/(CLK_TCK)<<"\n"; } int main() { timer ob; char c; cout<<"Press a key followed by ENTRE: "; cin>>c;
getch();
return 0;
}

Output:

Press a key followed by ENTRER: T
Elapsed time:6.098901
Press a key followed by ENTRER:

No comments: