इस page में एक ही program को different तरीकों से बनाया गया है जहां first program multiple string initialization का एक उदाहरण है।
create loading bar in C++ using array
क्या यह संभव है कि एक single dimensional array में एक से अधिक string को किया जा सके अर्थात ,
char array-variable[size]={"string1","string2","string3"};
सामान्य तौर पर यह संभव नहीं है इसलिए यह ऊपर दिया गया syntax गलत होगा। इसके लिए हम यहाँ पर एक different keyword को प्रयोग में लाते है इसलिए इसका सही syntax इस प्रकार होगा –
typedef char array-variable[size];
array-variable[] = {"string1","string2","string3"};
सबसे पहले, एक identifier को char data type का array declared किया जाता हैफिर, उस identifier से string का intialize किया जाता है-
arr[ ] = { " working on it", " "};
याद रहे, हम इसे direct नहीं कर सकते-
char arr[ ] = { "working on it", " "}; // error
लेकिन, two dimensional array में यह possible है, जैसे
char arr[10][20]= { " working on it", " "};
हम नीचे दिए गए कार्यक्रम में single dimentional array का use किया गया है –
#include<iostream.h>
#include<conio.h> // _setcursortype()
#include<dos.h> // 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
यहाँ पर अन्य उदाहरण दिए गए हैं।
creating a searching progress bar in c++
#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
creating a printing progress bar in C++
#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,