creating loading bar in C++

Here in this page we will create a loading bar in three ways where the first program is an example of multiple string initialization.

The three programs are created in different ways, but their output will be the same.

let’s start,

 

Creating loading bar

Is it possible that in a single dimensional array we can initialize more than one string? means,

data-type array-variable[size]={"string1","string2","string3"};

  In a single dimensional array, the initialization of more than one string is slightly different. for this first we use typedef data type. here is the step,

First, an identifier is declared a character array of char data type. such as-

typedef char arr[50];

Then, the initialization of the string is done from that identifier.

arr[ ] = { " working on it", " "};

Remember, we can’t do such as direct,

char arr[ ] = { "working on it", " "}; // error

But, In two dimensional array is possible,such as

char arr[10][20]= { " working on it", " "};

we use single dimensional array in below program,

#include
#include  // _setcursortype()
#include  // delay 
void main() 
{ 
   typedef char arr[50];
   arr d[]={"Working on it",""};

//char d[10][20]={"Working on it",""}; // will also work 

   int a,i=0,time=60;
   char c;

   _setcursortype(_NOCURSOR); // disable mouse cursor on monitor screen

   while(i<5) // increase value for more loading 
    { 
      for(int a=0;a<3;a++)
       {
          gotoxy(28,10);
          cout<<d[0]<<" |.... ";
          delay(time);

          gotoxy(28,10);
          cout<<d[0]<<" \\.... ";
          delay(time);

          gotoxy(28,10);
          cout<<d[0]<<" /.... ";
          delay(time); 
      }i++;
    }
 getch();
}

OUTPUT:-

The above program was only for, how to initialize multiple strings ?, where we have repeated the same code over and over, which would not be considered a better way of programming.

Therefore, this program has also been made below which will give the same result.

creating a searching bar

#include<iostream.h>
#include<conio.h>
#include<dos.h> 

 void main() 
  {
    char load[]={'|','\\','/'};
    clrscr();
    int second,i=0,time=60;
    char c;

    cout<<"Enter loading time in second:";
    cin>>second;

    _setcursortype(_NOCURSOR);

    while(i<second)
     {
       for(int j=0;j<3;j++)
        {
           gotoxy(28,10);
           cout<<"searching record "<<load[j]<<"....";
           delay(time);
           clrscr();

        } i++;
     }
    getch();
  }

OUTPUT:-

Here is another one,

creating a printing record bar…

#include<iostream.h>
#include<conio.h>
#include<dos.h>

 void main()
  {
    int pr,dl;
    char load[10][10]={".","..","...","...."};
    pr=0;dl=300;

    _setcursortype(_NOCURSOR);

    while(pr<2)
     {
       for(int i=0;i<4; i++)
        {
          gotoxy(30,10);
          cout<<"Record Printing"<<load[i];delay(dl);
          clrscr();
        }
      pr++;
     }
  }

OUTPUT:-

we can also make visual bar without using graphics tool, we is the one,

creating a downloading bar in C++

#include<iostream.h>
#include<conio.h>
#include<dos.h>
 
 void main()
 {
   int count=2;
   clrscr(); 
   _setcursortype(_NOCURSOR);

   gotoxy(31,10);
   cout<<"File Downloaing..";3
    
while(count<26)
{ gotoxy(25+count,12); cprintf("%c",176); cout<<count*4<<"%"; delay(200);3 if(count==26-1) { gotoxy(31,10); cout<<"Download Complete!"; } count++; } getch(); }

OUTPUT:-

The meaning of giving these three programs here, is to tell only the control-statement’s importance, we can make whatever we want from the control-statement.