Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes

C++ Programming Code Examples

C++ > Computer Graphics Code Examples

Game Pack in C++.

/* Game Pack in C++. */ #include<string.h> #include<math.h> #include<graphics.h> #include<dos.h> #include<stdlib.h> #include<stdio.h> #include<conio.h> #include<iostream.h> #include<process.h> #include<time.h> void main(); int temp_life; int i=8,j=18,a[20][20],ri,rj,max=2,speed=2,op_graph=0; int score=0,nbox=5,life=5,level=1; clock_t start, end; void draw(int); void drawbox(int); void decr(); void genbox(); void shotbox(int); void strt(); void putscore(int); void lifebox(int ); int global=9;int open_times=0,prev_card=0,comp=0; void card(int left,int top,int right,int bottom) { int x,y; long int er=0; if(global==9) er=2000; else er=200; for (long double g=0;g<er;g++) { x=random(right); y=random(bottom); if(x<left) { g--; continue; } if(y<top) { g--; continue; } int colors=random(15); if(colors==1||colors==10) { g--; continue; } setcolor(BLACK); setfillstyle(SOLID_FILL,colors); bar3d(x-4,y-4,x+4,y+4,1,1); } } void open(int left[],int top[],int right[],int bottom[],int game[],int z) { sound(900); delay(16); nosound(); int x; global=909; for(int j=left[z],k=top[z],l=right[z],i=bottom[z];j<=right[z];j++) { setfillstyle(SOLID_FILL,BLACK); bar(j+1,k,l+1,i+1); setcolor(WHITE); rectangle(j+1,k,l+1,i+1); sound(j*20); delay(5); nosound(); } int number=game[z]; char string[5]; setcolor(BLACK); settextstyle(TRIPLEX_FONT,HORIZ_DIR,1); outtextxy(left[z]+25,top[z]+35,itoa(number, string, 10)); if(open_times==0) prev_card=z; if(open_times==1) if(game[z]==game[prev_card]) game[prev_card]=game[z]=-100; open_times++; if(open_times==2) for(int k=0,t=19,b=99;k<4;k++,t+=120,b+=121) //displaying cards for(int i=0,l=55,r=125;i<4;i++,l+=150,r+=150) { sound(1000); delay(60); nosound(); if(k==0 && i==0) delay(90); card(l,t,r,b); open_times=0; } } void menu(int a,int b,int c,int d,int e) { setcolor(a); settextstyle(TRIPLEX_FONT,HORIZ_DIR,7); outtextxy(22,100,"1. BRICKS"); setcolor(b); settextstyle(TRIPLEX_FONT,HORIZ_DIR,7); outtextxy(22,200,"2. PAIRS II"); setcolor(c); settextstyle(TRIPLEX_FONT,HORIZ_DIR,4); outtextxy(15,300,"3. HELP"); setcolor(d); settextstyle(TRIPLEX_FONT,HORIZ_DIR,4); outtextxy(15,350,"4. CREDITS"); setcolor(e); settextstyle(TRIPLEX_FONT,HORIZ_DIR,4); outtextxy(15,400,"5. EXIT"); } void open_graph() { int x_center = 320, y_center = 240, rad = 220; int z,k,x[10],y[10]; setcolor(4); for(int xi=30;xi>4;xi--) { sound(xi*20); settextstyle(GOTHIC_FONT,HORIZ_DIR,xi); outtextxy(xi,220,"Gaming begins here......"); delay(320); cleardevice(); } setcolor(10); for (z=0;z<10;z++) { x[z]=x_center+rad*cos(36*z*3.14159/180); y[z]=y_center+rad*sin(36*z*3.14159/180); } for (z=0;z<10;z++) for (k=0;k<10;k++) { sound(k*200); delay(50); line(x[z],y[z],x[k],y[k]); nosound(); } for(int h=0;h<500;h++) { sound(h*9); setfillstyle( random(12),random(15) ); bar3d(random(640),random(480),random(640),random(480),random(30), random(18)); } op_graph++; } void loading() { cleardevice(); setcolor(13); settextstyle(TRIPLEX_FONT,HORIZ_DIR,0); setusercharsize(2, 1, 1, 1); outtextxy(138,198,"LOADING"); //LOADING setcolor(13); settextstyle(TRIPLEX_FONT,HORIZ_DIR,0); setusercharsize(2, 1, 1, 1); setcolor(BLUE); rectangle(119,199,421,231); rectangle(118,198,422,232); setcolor(10); for(int ii=120;ii<=420;ii++) { line(ii,200,ii,230); sound(ii+1500); delay(10); nosound(); } } void gameover() { cleardevice(); settextstyle(GOTHIC_FONT,0,10); cout<<"a"; for(int g=0;g<450;g++) { sound(g*10); delay(3); setcolor(LIGHTRED); if(g%20==0) {cleardevice();setcolor(12);} outtextxy(70,g,"game over"); nosound(); } main(); } void main() { int gdriver = DETECT, gmode; initgraph(&gdriver, &gmode, "c:\tc\bgi"); cleardevice(); if(op_graph==0) open_graph(); settextstyle(TRIPLEX_FONT,HORIZ_DIR,0); for(int si=1;si<10;si++) { sound(si*850); setcolor(LIGHTCYAN); setusercharsize(si,1,si,1); outtextxy(13,150,"GAME PACK"); delay(250); nosound(); cleardevice(); } randomize(); setfillstyle(3,RED); bar3d(0, 0,639,479, 0, 0);//background setcolor(WHITE); settextstyle(4,HORIZ_DIR,7); outtextxy(220,25,"MENU"); char lion; int move=5; lion=getch(); while(lion!=27) { if(lion==13) break; if(lion=='P') move++; if(lion=='H') move--; if(move<1)move=5; if(move>5)move=1; if(move==1) menu(10,8,8,8,8); if(move==2) menu(8,10,8,8,8); if(move==3) menu(8,8,10,8,8); //7 gray 14-yellow if(move==4) menu(8,8,8,10,8); if(move==5) menu(8,8,8,8,10); lion=getch(); sound(1700); delay(7); nosound(); } cleardevice(); if(move==5) exit(0); if(move==1) { //bricks video game shooting prg. loading(); int gd=DETECT,gm; initgraph(&gd,&gm,"D:\CPP\TC\BGI"); setcolor(10); outtextxy(500,75,"score :"); outtextxy(500,150,"level :"); outtextxy(500,225,"Life"); lifebox(10); putscore(10); strt(); } /* PAIRS II */ if(move==2) { int a[8],game[16],i=0,z=8,k,flag,temp,t,b,l,j=0,u=0,o=0,p=0; int left[16],top[16],right[16],bottom[16]; randomize(); loading(); for(int ii=0;ii<=640;ii++) line(ii,0,ii,480); setcolor(1); for(ii=0;ii<=640;ii++) line(0,ii,640,ii); setcolor(3); for(ii=640;ii>=0;ii--) line(ii,0,ii,480); setcolor(BLUE); for(ii=640;ii>=0;ii--) line(0,ii,640,ii); setcolor(RED); for(ii=0;ii<=640;ii++) { sound(ii*5); line(640,ii,ii,480); delay(5); nosound(); } setcolor(0); for(ii=0;ii<=640;ii++) { sound(ii*5); line(0,ii,640,480); delay(2); nosound(); } //selecting 8 nos (1-100)without repeating randomize(); a[0]=random(100); while(i!=8) { redo: temp=random(100); flag=1; for(k=0;k<=i;k++) if(a[k]==temp){flag=5;break;} if (flag==5) goto redo; else { a[i++]=temp; game[z++]=temp; } } //randomly filling the 8 nos from an array without repeating int r=0; while(r!=8) { label: temp=a[random(8)]; flag=1; for(k=0;k<=r;k++) if(game[k]==temp){flag=5;break;} if (flag==5) goto label; else game[r++]=temp; } setfillstyle(11,RED); setcolor(YELLOW); bar(0, 0,638,478);//backgrond for(k=0,t=19,b=99;k<4;k++,t+=120,b+=121) //displaying cards for(i=0,l=55,r=125;i<4;i++,l+=150,r+=150) { left[j++]=l; top[u++]=t; right[o++]=r; bottom[p++]=b; sound(i*200); card(l,t,r,b); } nosound(); for(int you=1;you<=20;you++) { if(you%2) setcolor(LIGHTGREEN); else setcolor(RED); for(k=0,t=15,b=103;k<4;k++,t+=120,b+=121) //high light cursor for(i=0,l=50,r=130;i<4;i++,l+=150,r+=150) for(int we=1;we<=5;we++) { sound(we*900); rectangle(l-we,t-we,r+we,b+we); nosound(); } delay(100); } setcolor(0); char ch=getch(); int pntr=0,turn=1; while(ch!=27) { if(ch=='M') pntr++; if(ch=='K') pntr--; if(ch=='H') pntr=pntr-4; if(ch=='P') pntr+=4; if(pntr>=17) pntr=pntr-16; if(pntr<1) pntr=pntr+16; int m=1; if(open_times==1) if(pntr-1==prev_card) { ch=getch(); continue; } int var_new34=9; if(game[pntr-1]==-100) var_new34=0; end: for(k=0,t=15,b=103;k<4;k++,t+=120,b+=121) //high light cursor for(i=0,l=50,r=130;i<4;i++,l+=150,r+=150) { setcolor(BLACK); if(m==pntr) { setcolor(LIGHTGREEN); if(game[pntr-1]==-100) setcolor(LIGHTRED); } for(int we=1;we<=5;we++) rectangle(l-we,t-we,r+we,b+we); m++; } if(var_new34) if(ch==13) open(left,top,right,bottom,game,pntr-1); //open card int y=0; for(int wer=0;wer<16;wer++) if(game[wer]==-100) y++; if(y==16) gameover(); ch=getch(); sound(2500); delay(6); nosound(); } if(ch==27) main(); } if(move==3) { char ctrl; do { char help_topic[]=" ************HELP*************** USERS MANUAL 1. PAIRS II The general outline of the game is as follows. * It is basically a card game. * One can flip and see only two cards at a time simultaneously in the given set of cards. * One has to match the cards in the given set. * One wins the game if all the matches are made correctly. * This game is a time-trailed game i.e. one's score becomes invalid if it exceeds the tine limit. * To navigate one can use the arrow keys. * To open the card you can hit enter. " ; char help_brick[]=" BRICKS The general outline is as follows. *It is a brick game. *It consist of a shooting box and we have to shoot the bricks. *To move the shooting box right press the right direction key and to move left press the left direction key. *To shoot press the up direction key. *Basically there are 5 levels in the game. *You can win each level when u reach the score of 2500. *When u hit each brick you get 25 points. *But if the bricks touch the shooting box or if it touches the ground one of your life is lost. *In total there are 5 lives."; textcolor(10); for(int i=0;i<strlen(help_topic);i++) { sound(i*20); cout<<help_topic[i]; delay(15); nosound(); } int cv; for(i=0,cv=2000;i<strlen(help_brick);i++,cv--) { sound(cv*2); cout<<help_brick[i]; delay(15); nosound(); } ctrl=getch(); }while(ctrl!=27&&ctrl<28&&ctrl>25); if(ctrl==27) main(); } if(move==4) { cleardevice(); setcolor(LIGHTGREEN); settextstyle(TRIPLEX_FONT,HORIZ_DIR,0); setusercharsize(1,1,1,1); setcolor(LIGHTGREEN); settextstyle(TRIPLEX_FONT,HORIZ_DIR,6); outtextxy(320,250,"&"); setcolor(LIGHTGREEN); rectangle(1,1,638,478);//background for(int ab=5,bc=420;ab<350;ab++,bc--) { sound(ab*620); setfillstyle(6,BLACK); bar(5, 130,637,250); bar(9,350,635,450); setcolor(random(15)); settextstyle(TRIPLEX_FONT,HORIZ_DIR,6); settextstyle(TRIPLEX_FONT,HORIZ_DIR,6); sound(bc*2000); delay(1); nosound(); } sleep(1); main(); } }//void main's block void strt() { int op; setcolor(0); line(60+i*25,j*25,60+rj*25,ri*25); for(ri=0;ri<19;ri++) for(rj=0;rj<16;rj++) a[ri][rj]=0; randomize(); genbox(); drawbox(12); start=clock(); op=getch(); while(1) { while(!kbhit()) { end = clock(); if((end - start) / CLK_TCK > speed) { decr(); start=clock(); } } while(kbhit()) { op=getch(); switch(op) { case 77: draw(0); if(i<15) i++; draw(10); break; case 75: draw(0); if(i>0) i--; draw(10); break; case 72: shotbox(i); break; case 27:main(); } } } } void draw(int color) { int c; c=getcolor(); setcolor(color); setfillstyle(INTERLEAVE_FILL,color); bar(50+25*i,j*25,75+25*i,j*25+25); rectangle(50+25*i,j*25,75+25*i,j*25+25); setcolor(14); rectangle(50,0,450,475); setcolor(c); } void genbox() { int x; for(x=0;x<nbox;x++) { rj=rand()%16; if(a[0][rj]==1) x--; a[0][rj]=1; } } void decr() { if(max<17) { drawbox(0); for(ri=max;ri>=0;ri--) for(rj=0;rj<16;rj++) a[ri+1][rj]=a[ri][rj]; for(rj=0;rj<16;rj++) a[0][rj]=0; genbox(); drawbox(12); } else { printf("a"); lifebox(0); --life; lifebox(10); if(life==0) gameover(); else {drawbox(0);strt();} } } void drawbox(int c) { setcolor(c); for(ri=0;ri<18;ri++) for(rj=0;rj<16;rj++) if(a[ri][rj]==1) { max=ri; setfillstyle(INTERLEAVE_FILL,c); bar(50+rj*25,ri*25,50+rj*25+25,ri*25+25); if(c!=0) setcolor(14); rectangle(50+rj*25,ri*25,50+rj*25+25,ri*25+25); } setcolor(14); rectangle(50,0,450,475); } void shotbox(int rj) { int ri,r; drawbox(0); for(ri=18;ri>=0;ri--) if(a[ri][rj]==1) {a[ri][rj]=0; file://for(r=18;r>=ri;r--) setcolor(13); line(60+i*25,j*25,60+rj*25,ri*25); sound(480); delay(25); nosound(); putscore(0); if(score%100==0 && score!=0 ) { putscore(0); level++; putscore(10); if(speed==1) if(nbox==5) nbox=7; else if(nbox==7) nbox=9; else if(nbox==9) nbox=11; else { setcolor(10); drawbox(12); cout<<"a"; cleardevice(); gameover(); main(); } else speed--; putscore(0); score++; putscore(10); strt();break;} else{ score++; putscore(10); break;}} drawbox(12); setcolor(0); line(60+i*25,j*25,60+rj*25,ri*25); } void putscore(int color) { char str[20]; int c; c=getcolor(); setcolor(color); itoa(score*25,str,10); outtextxy(550,75,str); itoa(level,str,10); outtextxy(550,150,str); setcolor(c); } void lifebox(int color) { int i,c; c=getcolor(); setcolor(color); for(i=1;i<=life;i++) { setfillstyle(INTERLEAVE_FILL,color); bar(500,250+i*25,525,275+i*25); if(color) setcolor(14); rectangle(500,250+i*25,525,275+i*25); } setcolor(c); }

As the name already suggests, these operators help in assigning values to variables. These operators help us in allocating a particular value to the operands. The main simple assignment operator is '='. We have to be sure that both the left and right sides of the operator must have the same data type. We have different levels of operators. Assignment operators are used to assign the value, variable and function to another variable. Assignment operators in C are some of the C Programming Operator, which are useful to assign the values to the declared variables. Let's discuss the various types of the assignment operators such as =, +=, -=, /=, *= and %=. The following table lists the assignment operators supported by the C language:

Switch statement in C tests the value of a variable and compares it with multiple cases. Once the case match is found, a block of statements associated with that particular case is executed. Each case in a block of a switch has a different name/number which is referred to as an identifier. The value provided by the user is compared with all the cases inside the switch block until the match is found. If a case match is NOT found, then the default statement is executed, and the control goes out of the switch block. • The expression can be integer expression or a character expression. • Value-1, 2, n are case labels which are used to identify each case individually. Remember that case labels should not be same as it may create a problem while executing a program. Suppose we have two cases with the same label as '1'. Then while executing the program, the case that appears first will be executed even though you want the program to execute a second case. This creates problems in the program and

setusercharsize gives you finer control over the size of text from stroked fonts used with graphics functions. The values set by setusercharsize are active only if charsize equals 0, as set by a previous call to settextstyle. With setusercharsize, you specify factors by which the width and height are scaled. The default width is scaled by multx: divx, and the default height is scaled by multy: divy. where multx : divx is the scaling ratio for text width, and multy : divy is the scaling ratio for height. It means the default width is scaled by multx : divx, and the default height is scaled by multy : divy.

An array is defined as the collection of similar type of data items stored at contiguous memory locations. Arrays are the derived data type in C++ programming language which can store the primitive type of data such as int, char, double, float, etc. It also has the capability to store the collection of derived data types, such as pointers, structure, etc. The array is the simplest data structure where each data element can be randomly accessed by using its index number. C++ array is beneficial if you have to store similar elements. For example, if we want to store the marks of a student in 6 subjects, then we don't need to define different variables for the marks in the different subject. Instead of that, we can define an array which can store the marks in each subject at the contiguous memory locations.

Break statement in C++ is a loop control statement defined using the break keyword. It is used to stop the current execution and proceed with the next one. When a compiler calls the break statement, it immediately stops the execution of the loop and transfers the control outside the loop and executes the other statements. In the case of a nested loop, break the statement stops the execution of the inner loop and proceeds with the outer loop. The statement itself says it breaks the loop. When the break statement is called in the program, it immediately terminates the loop and transfers the flow control to the statement mentioned outside the loop.

#include is a way of including a standard or user-defined file in the program and is mostly written at the beginning of any C/C++ program. This directive is read by the preprocessor and orders it to insert the content of a user-defined or system header file into the following program. These files are mainly imported from an outside source into the current program. The process of importing such files that might be system-defined or user-defined is known as File Inclusion. This type of preprocessor directive tells the compiler to include a file in the source code program.

The kbhit is basically the Keyboard Hit. This function is present at conio.h header file. So for using this, we have to include this header file into our code. The functionality of kbhit() is that, when a key is pressed it returns nonzero value, otherwise returns zero. kbhit() is used to determine if a key has been pressed or not. If a key has been pressed then it returns a non zero value otherwise returns zero.

The header file graphics.h contains setfillstyle() function which sets the current fill pattern and fill color. Current fill pattern and fill color is used to fill the area. setfillstyle sets the current fill pattern and fill color. To set a user-defined fill pattern, do not give a pattern of 12 (USER_FILL) to setfillstyle; instead, call setfillpattern.

bar() function is a C graphics function that is used to draw graphics in the C programming language. The graphics.h header contains functions that work for drawing graphics. The bar() function is also defined in the header file. Bar function is used to draw a 2-dimensional, rectangular filled in bar. Coordinates of left top and right bottom corner are required to draw the bar. Left specifies the X-coordinate of top left corner, top specifies the Y-coordinate of top left corner, right specifies the X-coordinate of right bottom corner, bottom specifies the Y-coordinate of right bottom corner. Current fill pattern and fill color is used to fill the bar. To change fill pattern and fill color use setfillstyle.

setcolor() function is used to set the foreground color in graphics mode. After resetting the foreground color you will get the text or any other shape which you want to draw in that color. setcolor sets the current drawing color to color, which can range from 0 to getmaxcolor. The current drawing color is the value to which pixels are set when lines, and so on are drawn. The drawing colors shown below are available for the CGA and EGA, respectively.

A program shall contain a global function named main, which is the designated start of the program in hosted environment. main() function is the entry point of any C++ program. It is the point at which execution of program is started. When a C++ program is executed, the execution control goes directly to the main() function. Every C++ program have a main() function.

To create a program in Graphics Mode, the first step would be to include the header file graphics.h. This file is required for Graphics programming. After this, the graphics have to be initialized. C Language supports 16 Bit's MS-DOS environment. Initializing the Graphics mode is to call various functions, one such is called initgraph. initgraph initializes the graphics system by loading a graphics driver from disk (or validating a registered driver), and putting the system into graphics mode. To start the graphics system, first call the initgraph function. initgraph loads the graphics driver and puts the system into graphics mode. You can tell initgraph to use a particular graphics driver and mode, or to autodetect the attached video adapter at run time and pick the corresponding driver. If you tell initgraph to autodetect, it calls detectgraph to select a graphics driver and mode. initgraph also resets all graphics settings to their defaults (current position, palette, color, viewport, and so on)

In computer programming, we use the if statement to run a block code only when a certain condition is met. An if statement can be followed by an optional else statement, which executes when the boolean expression is false. There are three forms of if...else statements in C++: • if statement, • if...else statement, • if...else if...else statement, The if statement evaluates the condition inside the parentheses ( ). If the condition evaluates to true, the code inside the body of if is executed. If the condition evaluates to false, the code inside the body of if is skipped.

The getch() is a predefined non-standard function that is defined in conio.h header file. It is mostly used by the Dev C/C++, MS- DOS's compilers like Turbo C to hold the screen until the user passes a single value to exit from the console screen. It can also be used to read a single byte character or string from the keyboard and then print. It does not hold any parameters. It has no buffer area to store the input character in a program. The getch() function does not accept any parameter from the user. It returns the ASCII value of the key pressed by the user as an input.

Settextstyle function is used to change the way in which text appears, using it we can modify the size of text, change direction of text and change the font of text. settextstyle sets the text font, the direction in which text is displayed, and the size of the characters. A call to settextstyle affects all text output by outtext and outtextxy.

Generate random number. Returns a pseudo-random integral number in the range between 0 and RAND_MAX. This number is generated by an algorithm that returns a sequence of apparently non-related numbers each time it is called. This algorithm uses a seed to generate the series, which should be initialized to some distinctive value using function srand. RAND_MAX is a constant defined in <cstdlib>. The rand() function in C++ is used to generate random numbers; it will generate the same number every time we run the program. In order to seed the rand() function, srand(unsigned int seed) is used. The srand() function sets the initial point for generating the pseudo-random numbers. The rand() function generates numbers randomly.

Continue statement is used inside loops. Whenever a continue statement is encountered inside a loop, control directly jumps to the beginning of the loop for next iteration, skipping the execution of statements inside loop's body for the current iteration. The continue statement works somewhat like the break statement. Instead of forcing termination, however, continue forces the next iteration of the loop to take place, skipping any code in between. For the for loop, continue causes the conditional test and increment portions of the loop to execute. For the while and do...while loops, program control passes to the conditional tests.

In while loop, condition is evaluated first and if it returns true then the statements inside while loop execute, this happens repeatedly until the condition returns false. When condition returns false, the control comes out of loop and jumps to the next statement in the program after while loop. The important point to note when using while loop is that we need to use increment or decrement statement inside while loop so that the loop variable gets changed on each iteration, and at some point condition returns false. This way we can end the execution of while loop otherwise the loop would execute indefinitely. A while loop that never stops is said to be the infinite while loop, when we give the condition in such a way so that it never returns false, then the loops becomes infinite and repeats itself indefinitely.

delay() function is used to hold the program's execution for given number of milliseconds, it is declared in dos.h header file. There can be many instances when we need to create a delay in our programs. C++ provides us with an easy way to do so. We can use a delay() function for this purpose in our code. We can run the code after a specific time in C++ using delay() function.

Get string length. Returns the length of the C string str. C++ strlen() is an inbuilt function that is used to calculate the length of the string. It is a beneficial method to find the length of the string. The strlen() function is defined under the string.h header file. The strlen() takes a null-terminated byte string str as its argument and returns its length. The length does not include a null character. If there is no null character in the string, the behavior of the function is undefined.

The cout is a predefined object of ostream class. It is connected with the standard output device, which is usually a display screen. The cout is used in conjunction with stream insertion operator (<<) to display the output on a console. On most program environments, the standard output by default is the screen, and the C++ stream object defined to access it is cout. The "c" in cout refers to "character" and "out" means "output". Hence cout means "character output". The cout object is used along with the insertion operator << in order to display a stream of characters.

Compute cosine. Returns the cosine of an angle of x radians. cos() function is a library function of cmath header, it is used to find the cosine of the given number (angle), it accepts a number (x) and returns the cosine of angle x radians. In trigonometry, the cos function of a right-angled triangle is defined as the length of the adjacent side over the longest side, i.e., the hypotenuse. The cos function in C++ works precisely like the cosine function in trigonometry. The return value of the cos function is the cosine of an angle given in radian. Function returns cosine of x radians.

bar3d draws a three-dimensional rectangular bar, then fills it using the current fill pattern and fill color. The three-dimensional outline of the bar is drawn in the current line style and color. The bar's depth in pixels is given by depth. The topflag parameter governs whether a three-dimensional top is put on the bar. If topflag is nonzero, a top is put on; otherwise, no top is put on the bar (making it possible to stack several bars on top of one another). The upper left and lower right corners of the rectangle are given by (left, top) and (right, bottom), respectively.

Relational operators for string. Performs the appropriate comparison operation between the string objects lhs and rhs. The functions use string::compare for the comparison. These operators are overloaded in header <string>. If strings are compared using relational operators then, their characters are compared lexicographically according to the current character traits, means it starts comparison character by character starting from the first character until the characters in both strings are equal or a NULL character is encountered.

Convert integer to string (non-standard function). Converts an integer value to a null-terminated string using the specified base and stores the result in the array given by str parameter. If base is 10 and value is negative, the resulting string is preceded with a minus sign (-). With any other base, value is always considered unsigned. str should be an array long enough to contain any possible value: (sizeof(int)*8+1) for radix=2, i.e. 17 bytes in 16-bits platforms and 33 in 32-bits platforms. Function returns a pointer to the resulting null-terminated string, same as parameter str.

In C++, goto is a jump statement and sometimes also referred as unconditional jump statement. It can be used to jump from goto to a labeled statement within the same function. The target label must be within the same file and context. Please note that the use of goto statement is highly discouraged in any programming language because it makes difficult to trace the control flow of a program, making hard to understand and modify the program.

Use the textcolor function to define what color you want to use for text. You can use this function to vary the text colors of your output. Colors must be written in all caps, or expressed as a numeral. Now, if you want your text to blink then while calling the textcolor() function pass the color and also say BLINK. This will like this: textcolor(BLUE+BLINK).

Our system can create various sounds on different frequencies. The sound() is very useful as it can create very nice music with the help of programming and our user can enjoy music during working in out the program. Sound function produces the sound of a specified frequency. Used for adding music to a C++ program.

C programming language provides sleep() function in order to wait for a current thread for a specified time. slepp() function will sleep given thread specified time for the current executable. Of course, the CPU and other processes will run without a problem. The sleep() function shall cause the calling thread to be suspended from execution until either the number of realtime seconds specified by the argument seconds has elapsed or a signal is delivered to the calling thread and its action is to invoke a signal-catching function or to terminate the process. The suspension time may be longer than requested due to the scheduling of other activity by the system. The sleep() function shall cause the calling thread to be suspended from execution until either the number of realtime seconds specified by the argument seconds has elapsed or a signal is delivered to the calling thread and its action is to invoke a signal-catching function or to terminate the process. The suspension time may be longer than requested

In computer programming, loops are used to repeat a block of code. For example, when you are displaying number from 1 to 100 you may want set the value of a variable to 1 and display it 100 times, increasing its value by 1 on each loop iteration. When you know exactly how many times you want to loop through a block of code, use the for loop instead of a while loop. A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.

rectangle() is used to draw a rectangle. Coordinates of left top and right bottom corner are required to draw the rectangle. left specifies the X-coordinate of top left corner, top specifies the Y-coordinate of top left corner, right specifies the X-coordinate of right bottom corner, bottom specifies the Y-coordinate of right bottom corner.

The header file graphics.h contains cleardevice() function. cleardevice() is a function which is used to clear the screen by filling the whole screen with the current background color. It means that cleardevice() function is used to clear the whole screen with the current background color and it also sets the current position to (0,0). Both clrscr() and cleardevice() functions are used to clear the screen but clrscr() is used in text mode and cleardevice function is used in the graphics mode.

outtextxy displays a text string in the viewport at the given position (x, y), using the current justification settings and the current font, direction, and size. To maintain code compatibility when using several fonts, use textwidth and textheight to determine the dimensions of the string. If a string is printed with the default font using outtext or outtextxy, any part of the string that extends outside the current viewport is truncated. outtextxy is for use in graphics mode; it will not work in text mode.

Compute sine. Returns the sine of an angle of x radians. sin() function is a library function of cmath header, it is used to find the sine of the given number (angle), it accepts a number (x) and returns the sine of angle x radians. Additional overloads are provided in this header (<cmath>) for the integral types: These overloads effectively cast x to a double before calculations (defined for T being any integral type). This function is also overloaded in <complex> and <valarray> (see complex sin and valarray sin).

The exit function terminates the program normally. Automatic objects are not destroyed, but static objects are. Then, all functions registered with atexit are called in the opposite order of registration. The code is returned to the operating system. An exit code of 0 or EXIT_SUCCESS means successful completion. If code is EXIT_FAILURE, an indication of program failure is returned to the operating system. Other values of code are implementation-defined. Calls all functions registered with the atexit() function, and destroys C++ objects with static storage duration, all in last-in-first-out (LIFO) order. C++ objects with static storage duration are destroyed in the reverse order of the completion of their constructor. (Automatic objects are not destroyed as a result of calling exit().)

The header file graphics.h contains line() function which is used to draw a line from a point(x1, y1) to point(x2, y2) i.e. (x1, y1) and (x2, y2) are end points of the line. The function line() draws a line on the graphics screen between two specified points. So this function requires four parameters namely x1, y1, x2, and y2 to represent two points. This function draws a line from (x1, y1) coordinates to (x2, y2) coordinates on the graphics screen.

An array is a collection of data items, all of the same type, accessed using a common name. A one-dimensional array is like a list; A two dimensional array is like a table; The C++ language places no limits on the number of dimensions in an array, though specific implementations may. Some texts refer to one-dimensional arrays as vectors, two-dimensional arrays as matrices, and use the general term arrays when the number of dimensions is unspecified or unimportant. (2D) array in C++ programming is also known as matrix. A matrix can be represented as a table of rows and columns. In C/C++, we can define multi dimensional arrays in simple words as array of arrays. Data in multi dimensional arrays are stored in tabular form (in row major order).

The nosound() function in C language is used to stop the sound played by sound() function. The nosound() function is simply silent the system. The sound() and nosound() functions are very useful as they can create very nice music with the help of programming and our user can enjoy music during working in out the program.

To write a "Multiline Comment" you have to write "/*" at the start of the Comment. After this you can write as many number of lines of description. When you are done with writing

A function is like a black box. It takes in input, does something with it, and then spits out an answer. We have some "terminology" to refer to functions: A function, call it f, and that uses

Column number of first matrix must be same as the row number of second matrix. Initialize matrix. Print values of the passed matrix and mutiply two matrices and return the resultant