Saturday, January 15, 2022

Count Down Meter 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.

 

CountDownMeterProgram.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;

int hour,minute,second;

 

int countDownMeter();

void setTime();

 

bool check()

{

 

    cout<<setfill(' ')<<setw(20);

    cout<<hour<<"|"<<minute<<"|"<<second<<endl;

 

    if(hours==hour && minutes==minute && seconds==second)

    {

        cout<<endl<<endl<<endl;

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

        cout<<endl<<endl<<endl;

        return true;

    }

    return false;

}

 

int main()

{

    system("color 02");

    cout<<endl<<endl<<endl;

    cout<<setfill(' ')<<setw(30)<<"COUNTDOWN METER"<<endl;

    cout<<endl<<endl<<endl;

    setTime();

    countDownMeter();

    return 0;

}

 

 

void setTime()

{

    cout<<"set the time"<<endl;

    cin>>hour>>minute>>second;

}

int countDownMeter()

{

 

    while(1)

    {

 

        if(check())

        {

            return 0;

        }

 

        Sleep(1);

        --second;

 

        if(second==0)

        {

            if(minute==0)

            {

                if(hour>0)

                {

                    if(check())

                    {

                        return 0;

                    }

                    Sleep(1);

                    --hour;

                    minute=59;

                    second=59;

                }

            }

            else

            {

                if(check())

                {

                    return 0;

                }

                Sleep(1);

                --minute;

                second=59;

            }

        }

    }

}

 

 

 


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

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

 


No comments:

Post a Comment