Thursday, January 20, 2022

Stop Watch Program in C++

This is a Character based User Interface or CUI based simple computerized solution to manage the system activities. This prototype code saves time and energy of its user by automating certain tasks. This system is either file handling type or ROM type, and stores activities in a coder-defined file or on ROM memory temporarily.

C++ is a typed language, so no need of code explanation as everything will be cleared by itself by reading the code. If you know C++, you know this code. It’s that simple!

Note to students, draw a class diagram and flow chart of system by reading the code itself. The Code::Blocks IDE 20.03+MinGW and Cygwin tool are used to test the code.

Note that some systems are very simple and need enhancement but they are complete on their own in other terms.

 

StopWatchProgram.cpp

 

 

 

 

#include <bits/stdc++.h>

#include <iostream>

#include <stdlib.h>

#include <iomanip>

#include <windows.h>

#include <unistd.h>

 

using namespace std;

 

int hours,minutes,seconds;//initial

int hour,minute,second;//target

int stopWatch();

void setTime();

 

bool check()

{

    return(hours==hour && minutes==minute && seconds==second)?true:false;

}

int main()

{

    system("color 02");

    cout<<setfill(' ')<<setw(30)<<"STOP WATCH"<<endl;

    setTime();

    stopWatch();

    return 0;

}

void setTime()

{

    cin>>hour>>minute>>second;

    for(int i=1; i<=5; ++i)

    {

        cout<<"\n";

    }

}

int stopWatch()

{

 

    while(1)

    {

        cout<<setfill(' ')<<setw(30)<<hours<<"|"<<minutes<<"|"<<seconds<<"\t\t\n";

        // cout<<hour-hours<<"|"<<minute-minutes<<"|"<<second-seconds<<endl;

        if(check())

        {

            for(int i=1; i<=5; ++i)

            {

                cout<<"\n";

            }

            cout<<setfill(' ')<<setw(30)<<"TIMES UP!"<<endl;

            return 0;

        }

        Sleep(1);

        ++seconds;

        if(seconds==60)

        {

            ++minutes;

            seconds=0;

            if(minutes==60)

            {

                ++hours;

                minutes=0;

            }

        }

    }

}

 

 

 

For more C/C++ codes related information click here.

…till next post, bye-bye and take care. 

 

No comments:

Post a Comment