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++ > Games Code Examples

Heart Breaking Kid

/* Heart Breaking Kid */ #include <stdio.h> #include <ctype.h> #include <alloc.h> #include <graphics.h> #include <dos.h> #include <stdlib.h> #include <conio.h> #define n 25 void start(void); void end(void); void rhits(void); void yhits(void); void phits(void); char *msg; void *ball, *ball1, *ball2, *gun, *bomb[n]; void *rhrt[n], *yhrt[n], *phrt[n]; int rflag[n], yflag[n], pflag[n]; int rx[n], ry[n], yx[n], yy[n], px[n], py[n]; int j, life = 3; int rin=0, yin=0, pin=0; unsigned int size,size1,size2,size3,size4; int count = 0, r = 10, bct=0; int nohits = 0, i; int ats = 0; int xend = 400, yend = 450; char che = 3, ch; int flag = 1, x = 5, gx = 4, hitflag[n]; int speed = 1, hity[n], hitx[n]; int x1 = 200, x2 = 377; int ti=500; int flag1 = 1, flag2 = 1; int rhit = 0, yhit = 0, phit = 0; struct time t; void main(void) { int gd = DETECT, gm; initgraph(&gd, &gm, "c:\tc\bgi"); sprintf(msg,"%c",che); setcolor(RED); settextstyle(0,0,30); outtextxy(getmaxx()/2-130,getmaxy()/2-100,msg); setcolor(WHITE); settextstyle(0,0,0); outtextxy(getmaxx()/2-100,getmaxy()/2-50,"Heart Break Kid Game"); getch(); cleardevice(); start(); for(i=0;i<n;i++) { hitflag[i] = 0; rflag[i] = 0; yflag[i] = 0; pflag[i] = 0; } setcolor(RED); settextstyle(0,0,2); outtextxy(8,10,msg); setcolor(12); setlinestyle(0,0,THICK_WIDTH); rectangle(1,1,xend,getmaxy()); rectangle(1,1,getmaxx()-1,getmaxy()-1); setfillstyle(10,12); bar(xend+1,2,getmaxx()-2,100); rectangle(xend,100,getmaxx()-1,200); line(xend,285,getmaxx(),285); line(1,yend,getmaxx(),yend); setcolor(RED); settextstyle(0,0,2); outtextxy(xend+20,200+10,msg); setcolor(YELLOW); settextstyle(0,0,2); outtextxy(xend+110,200+10,msg); setcolor(12); settextstyle(0,0,2); outtextxy(xend+195,200+10,msg); setcolor(RED); setlinestyle(0,0,NORM_WIDTH); circle(r+5,r+5,r); setcolor(YELLOW); settextstyle(0,0,2); outtextxy(203,155,msg); setcolor(YELLOW); setlinestyle(0,0,NORM_WIDTH); circle(r+200,r+150,r); setcolor(12); settextstyle(0,0,2); outtextxy(xend-20,255,msg); setcolor(12); setlinestyle(0,0,NORM_WIDTH); circle(xend-r-3,r+250,r); setcolor(11); setlinestyle(0,0,THICK_WIDTH); line(5,yend-5,20,yend-5); line(5,yend-5,13,yend-14); line(20,yend-5,13,yend-14); size = imagesize(5,5,25,25); ball = malloc(size); getimage(5,5,25,25,ball); size = imagesize(200,150,220,170); ball1 = malloc(size); getimage(200,150,220,170,ball1); size = imagesize(377,250,397,270); ball2 = malloc(size); getimage(377,250,397,270,ball2); size = imagesize(4,yend-4,21,yend-14); gun = malloc(size); getimage(4,yend-4,21,yend-14,gun); setfillstyle(1,12); bar(4,yend+3,xend-3,getmaxy()-4); setcolor(11); settextstyle(0,0,0); setcolor(12); settextstyle(4,0,2); outtextxy(xend+25,20,"HEART BREAK KID"); outtextxy(xend+50,55,"GAME ZONE"); settextstyle(0,0,1); setcolor(12); outtextxy(xend+10,315,"Right Arrow Move Right Side"); outtextxy(xend+10,345,"Left Arrow Move Left Side"); outtextxy(xend+10,375,"Up Arrow To Fire The Arrow"); outtextxy(xend+10,405,"Exit"); randomize(); while(1) { if(life==0) { delay(1000); end(); } gotoxy(52,16); printf("%3d",rhit); gotoxy(63,16); printf("%3d",yhit); gotoxy(74,16); printf("%3d",phit); if(life<0) life = 0; gotoxy(55,12); printf("Speed : %d Lifes : %2d",speed,life); gotoxy(55,10); printf("Total Points : %4d",count); gotoxy(55,8); printf("No Of Attempts : %4d",ats); if(random(200-speed*10)==150-speed*5) rhits(); if(random(200-speed*10)==77-speed*5) phits(); if(random(200-speed*10)==111-speed*5) yhits(); if(kbhit()) { ch = getch(); if(ch==0) { ch = getch(); putimage(gx,yend-14,gun,XOR_PUT); if(ch==75) { if(gx>=15) gx -= 15; } else if(ch==77) { if(gx<=xend-25) gx += 15; } putimage(gx,yend-14,gun,XOR_PUT); if(ch==72&&life>0) { ats += 1; int remflag = 0; for(i=0;i<n;i++) { if(hitflag[i]>1) { hitflag[i]= 1; remflag = 1; hitx[i] = gx + 8 - 3; hity[i] = yend - 14 - 15; putimage(hitx[i],hity[i],bomb[i],XOR_PUT); break; } } if(remflag==0) { for(i=0;i<n;i++) if(hitflag[i]==0) { bct = i; nohits = i; break; } hitflag[bct] = 1; setcolor(10); setlinestyle(0,0,NORM_WIDTH); line(gx+8,yend-15,gx+8,yend-14-15); line(gx+8,yend-14-15,gx+5,yend-14-10); line(gx+8,yend-14-15,gx+11,yend-14-10); size1 = imagesize(gx+8-3,yend-15,gx+8+3,yend-14-15); bomb[bct] = malloc(size1); getimage(gx+8-3,yend-15,gx+8+3,yend-14-15,bomb[bct]); hitx[bct] = gx + 8 - 3; hity[bct] = yend - 14 - 15; } } } if(tolower(ch)=='e') { end(); } } for(i=0;i<n;i++) if(hitflag[i]==1) { putimage(hitx[i],hity[i],bomb[i],XOR_PUT); hity[i] = hity[i] - 8; if(hitx[i]>=x&&hitx[i]<=x+20&&hity[i]>=5&&hity[i]<=25) { rhits(); count += 3; rhit += 1; hitflag[i] = 2; } if(hitx[i]>=x1&&hitx[i]<=x1+20&&hity[i]>=150&&hity[i]<=170) { yhits(); count += 2; yhit+=1; hitflag[i] = 2; } if(hitx[i]>=x2&&hitx[i]<=x2+20&&hity[i]>=250&&hity[i]<=270) { phits(); count += 1; phit+=1; hitflag[i] = 2; } if(hity[i]<=2) { hitflag[i] = 2; } if(hitflag[i]==1) { putimage(hitx[i],hity[i],bomb[i],XOR_PUT); } } if(ti>=500) { gettime(&t); sprintf(msg," Current Time:%2d:%02d:%02d",t.ti_hour, t.ti_min, t.ti_sec); setfillstyle(1,12); bar(xend+3,yend+3,getmaxx()-4,getmaxy()-4); setcolor(BLACK); settextstyle(0,0,0); outtextxy(xend+15,yend+10,msg); ti = 0; } putimage(x,5,ball,XOR_PUT); putimage(x1,150,ball1,XOR_PUT); putimage(x2,250,ball2,XOR_PUT); if(flag==1) x += speed; else x -= speed; if(x>=xend-23) { flag = 0; } if(x<=1) { flag = 1; } if(flag1==1) x1 += 1+speed; else x1 -= 1+speed; if(x1>=xend-23) { flag1 = 0; } if(x1<=1) { flag1 = 1; } if(flag2==1) x2 += 2+speed; else x2 -= 2+speed; if(x2>=xend-23) { flag2 = 0; } if(x2<=1) { flag2 = 1; } putimage(x,5,ball,XOR_PUT); putimage(x1,150,ball1,XOR_PUT); putimage(x2,250,ball2,XOR_PUT); for(i=0;i<n;i++) if(rflag[i]==1) putimage(rx[i],ry[i],rhrt[i],XOR_PUT); for(i=0;i<n;i++) if(yflag[i]==1) putimage(yx[i],yy[i],yhrt[i],XOR_PUT); for(i=0;i<n;i++) if(pflag[i]==1) putimage(px[i],py[i],phrt[i],XOR_PUT); for(i=0;i<n;i++) { if(rflag[i]==1) { ry[i] += speed+2; if(rx[i]>=gx-5&&rx[i]<=gx+20&&ry[i]>=yend-15&&ry[i]<=yend-5) { // count -= 3; rflag[i] = 2; life--; } } } for(i=0;i<n;i++) { if(yflag[i]==1) { yy[i] += speed+1; if(yx[i]>=gx-5&&yx[i]<=gx+20&&yy[i]>=yend-15&&yy[i]<=yend-5) { // count -= 2; yflag[i] = 2; life--; } } } for(i=0;i<n;i++) { if(pflag[i]==1) { py[i] += speed; if(px[i]>=gx-5&&px[i]<=gx+20&&py[i]>=yend-15&&py[i]<=yend-5) { // count -= 1; pflag[i] = 2; life--; } } } for(i=0;i<n;i++) if(ry[i]>=yend-5) { rflag[i] = 2; } for(i=0;i<n;i++) if(yy[i]>=yend-5) { yflag[i] = 2; } for(i=0;i<n;i++) if(py[i]>=yend-5) { pflag[i] = 2; } for(i=0;i<n;i++) if(rflag[i]==1) putimage(rx[i],ry[i],rhrt[i],XOR_PUT); for(i=0;i<n;i++) if(yflag[i]==1) putimage(yx[i],yy[i],yhrt[i],XOR_PUT); for(i=0;i<n;i++) if(pflag[i]==1) putimage(px[i],py[i],phrt[i],XOR_PUT); if(count<5) speed = 1; if(count>=30) speed = 2; if(count>=60) speed = 3; if(count>=90) speed = 4; if(count>=120) speed = 5; delay(12-speed); ti += 12-speed; } } void end(void) { char m[3]; sprintf(m,"%c",3); clrscr(); cleardevice(); restorecrtmode(); textattr(11); cprintf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$"); gotoxy(20,3); cprintf("THE SCORE BOARD FOR HEART BREAK KID"); printf(" "); cprintf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$"); gotoxy(20,7); textattr(11); cprintf("TOTAL NUMBER OF FIRE SHOOTED : %d",ats); gotoxy(20,9); cprintf("TOTAL NUMBER OF POINTS SCORED : %d",count); gotoxy(20,11); textattr(RED); cprintf("TOTAL NUMBER OF HITS TO RED HEART : %d",rhit); gotoxy(20,13); textattr(YELLOW); cprintf("TOTAL NUMBER OF HITS TO YELLOW HEART : %d",yhit); gotoxy(20,15); textattr(12); cprintf("TOTAL NUMBER OF HITS OT PINK HEART : %d",phit); printf(" "); textattr(11); cprintf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$"); getch(); /* int gd=DETECT, gm; initgraph(&gd,&gm,"c:\tc\bgi"); while(!kbhit()) { setcolor(random(getmaxcolor())); settextstyle(0,0,1); outtextxy(random(getmaxx()),random(getmaxy()),m); setcolor(12); settextstyle(0,0,2); outtextxy(100,250,"THANK YOU FOR PLAYING HBK"); } closegraph(); restorecrtmode();*/ exit(0); } void start(void) { cleardevice(); settextstyle(10,0,3); setcolor(12); outtextxy(150,100,"HEART BREAK KID"); settextstyle(0,0,2); getch(); cleardevice(); } void rhits(void) { int rflg = 0; for(j=0;j<n;j++) { if(rflag[j]>1) { rflag[j] = 1; rflg = 1; rx[j] = x-1; ry[j] = 26; putimage(rx[j],ry[j],rhrt[j],XOR_PUT); break; } } if(rflg==0) { rflag[rin] = 1; settextstyle(0,0,1); setcolor(RED); sprintf(msg,"%c",che); outtextxy(x,28,msg); size2 = imagesize(x-1,28-2,x+8,34); rhrt[rin] = malloc(size2); getimage(x-1,28-2,x+8,34,rhrt[rin]); rx[rin] = x-1; ry[rin] = 26; for(j=0;j<n;j++) if(rflag[j]==0) { rin = j; break; } } } void yhits(void) { int yflg = 0; for(j=0;j<n;j++) { if(yflag[j]>1) { yflag[j] = 1; yflg = 1; yx[j] = x1-1; yy[j] = 171; putimage(yx[j],yy[j],yhrt[j],XOR_PUT); break; } } if(yflg==0) { yflag[yin] = 1; settextstyle(0,0,1); setcolor(YELLOW); sprintf(msg,"%c",che); outtextxy(x1,171,msg); size3 = imagesize(x1-1,171,x1+8,179); yhrt[yin] = malloc(size3); getimage(x1-1,171,x1+8,179,yhrt[yin]); yx[yin] = x1-1; yy[yin] = 171; for(j=0;j<n;j++) if(yflag[j]==0) { yin = j; break; } } } void phits(void) { int pflg = 0; for(j=0;j<n;j++) { if(pflag[j]>1) { pflag[j] = 1; pflg = 1; px[j] = x2-1; py[j] = 281; putimage(px[j],py[j],phrt[j],XOR_PUT); break; } } if(pflg==0) { pflag[pin] = 1; settextstyle(0,0,1); setcolor(12); sprintf(msg,"%c",che); outtextxy(x2,281,msg); size4 = imagesize(x2-1,281,x2+8,289); phrt[pin] = malloc(size4); getimage(x2-1,281,x2+8,289,phrt[pin]); px[pin] = x2-1; py[pin] = 281; for(j=0;j<n;j++) if(pflag[j]==0) { pin = j; break; } } }

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.

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.

getmaxcolor() returns highest possible color value. The header file graphics.h contains getmaxcolor() function, which returns maximum color value for current graphics mode and driver. As color numbering starts from zero, total number of colors available for current graphics mode and driver are ( getmaxcolor() + 1 ) . getmaxcolor returns the maximum color value. There are various colors that are also mentioned in graphics.h header file and the possible color values are from 0 - 15:

the gettime() function is used to find current system time. We pass address of a structure varibale of type ( struct time ). gettime() function asks for a time object to be passed and then uses that object to get the current hour and minute etc. The gettime() function fills in the fields of the time structure pointed to by the t parameter. The current system time data is written in DOS format.

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.

#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 header file graphics.h contains closegraph() function which closes the graphics mode, deallocates all memory allocated by graphics system and restores the screen to the mode it was in before you called initgraph. closegraph() function is used to re-enter in the text mode and exit from the graphics mode. If you want to use both text mode and graphics mode in the program then you have to use both initgraph() and closegraph() function in the program. This function deallocates all memory allocated by graphics system and restores the screen to that mode in which it was presented before you called the initgraph() function.

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 getmaxx() function which returns the maximum X coordinate for current graphics mode and driver. getmaxx() returns the maximum (screen-relative) x value for the current graphics driver and mode. For example, on a CGA in 320*200 mode, getmaxx returns 319. getmaxx is invaluable for centering, determining the boundaries of a region onscreen, and so on.

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.

restorecrtmode restores the original video mode detected by initgraph. This function can be used in conjunction with setgraphmode to switch back and forth between text and graphics modes. Textmode should not be used for this purpose; use it only when the screen is in text mode, to change to a different text mode. restorecrtmode is implemented in winbgim, but it does not do any work. This is because both the graphics window and the text window are always open during any Windows program, so there is no need to switch back and forth between the two modes.

setlinestyle() is a function which is used to draw the line of different- different styles. Turbo C compiler provides five line styles that are solid, dotted, center, dashed and user defined. These all five line styles are already enumerated in graphics.h header file as given below: setlinestyle() function contains three parameters type, pattern and thickness. First parameter contains the type of line like solid, dashed or dotted etc. Second parameter is applicable only when type of line is user defined. Third parameter specifies the thickness of the line it takes values 1 (line thickness of one pixel (normal)) or 3 (line thickness of three pixels (thick).

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.

putimage puts the bit image previously saved with getimage back onto the screen, with the upper left corner of the image placed at (left,top). bitmap points to the area in memory where the source image is stored. The op parameter to putimage specifies a combination operator that controls how the color for each destination pixel onscreen is computed, based on the pixel already onscreen and the corresponding source pixel in memory.

In the C++ Programming Language, the #define directive allows the definition of macros within your source code. These macro definitions allow constant values to be declared for use throughout your code. Macro definitions are not variables and cannot be changed by your program code like variables. You generally use this syntax when creating constants that represent numbers, strings or expressions. The syntax for creating a constant using #define in the C++ is: #define token value

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.

Convert uppercase letter to lowercase. Converts c to its lowercase equivalent if c is an uppercase letter and has a lowercase equivalent. If no such conversion is possible, the value returned is c unchanged. The tolower() function in C++ converts a given character to lowercase. It is defined in the cctype header file. Notice that what is considered a letter may depend on the locale being used; In the default "C" locale, an uppercase letter is any of: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z, which translate respectively to: a b c d e f g h i j k l m n o p q r s t u v w x y z. The tolower() function accepts the following parameter: c - a character, casted to int type or EOF. The tolower() function returns: Function returns the lowercase equivalent to c, if such value exists, or c (unchanged) otherwise. The value is returned as an int value that can be implicitly casted to char.

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.

Positions cursor in text window. The gotoxy() function places the cursor at the desired location on the screen. This means it is possible to change the cursor location on the screen using the gotoxy() function. It is basically used to print text wherever the cursor is moved. If the coordinates are in any way invalid the call to gotoxy is ignored. Neither argument to gotoxy can be zero.

In C++, classes and structs are blueprints that are used to create the instance of a class. Structs are used for lightweight objects such as Rectangle, color, Point, etc. Unlike class, structs in C++ are value type than reference type. It is useful if you have data that is not intended to be modified after creation of struct. C++ Structure is a collection of different data types. It is similar to the class that holds different types of data. A structure is declared by preceding the struct keyword followed by the identifier(structure name). Inside the curly braces, we can declare the member variables of different types.

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)

The header file graphics.h contains getmaxy() function which returns the maximum Y coordinate for current graphics mode and driver. getmaxy returns the maximum (screen-relative) y value for the current graphics driver and mode. For example, on a CGA in 320*200 mode, getmaxy returns 199. getmaxy is invaluable for centering, determining the boundaries of a region onscreen, and so on.

It is a predefined function in "conio.h" (console input output header file) used to clear the console screen. It is a predefined function, by using this function we can clear the data from console (Monitor). Using of clrscr() is always optional but it should be place after variable or function declaration only. It is often used at the beginning of the program (mostly after variable declaration but not necessarily) so that the console is clear for our output.

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.

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.

getimage() function copy a specific portion into memory. This specific image would be any bit image like rectangle, circle or anything else. getimage() copies an image from the screen to memory. Left, top, right, and bottom define the screen area to which the rectangle is copied. Bitmap points to the area in memory where the bit image is stored. The first two words of this area are used for the width and height of the rectangle; the remainder holds the image itself.

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.

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.

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.

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.

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:

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().)

Allocate memory block. Allocates a block of size bytes of memory, returning a pointer to the beginning of the block. The content of the newly allocated block of memory is not initialized, remaining with indeterminate values. If size is zero, the return value depends on the particular library implementation (it may or may not be a null pointer), but the returned pointer shall not be dereferenced. Malloc function in C++ is used to allocate a specified size of the block of memory dynamically uninitialized. It allocates the memory to the variable on the heap and returns the void pointer pointing to the beginning address of the memory block. The values in the memory block allocated remain uninitialized and indeterminate. In case the size specified in the function is zero then pointer returned must not be dereferenced as it can be a null pointer, and in this case, behavior depends on particular library implementation. When a memory block is allocated dynamically memory is allocated on the heap but the pointer is

This library function is declared in graphics.h and used to draw a circle; it takes centre point coordinates and radius. Circle function is used to draw a circle with center (x,y) and third parameter specifies the radius of the circle. The code given below draws a circle. Where, (x, y) is center of the circle. 'radius' is the Radius of the circle.

The header file graphics.h contains imagesize() function which returns the number of bytes required to store a bit-image. This function is used when we are using getimage. imagesize() function returns the required memory area to store an image in bytes. imagesize() function returns the number of bytes needed to store the top-left corner of the screen at left, top and the bottom-right corner at right, bottom. This function is usually used in conjunction with the getimage() function. The imagesize() function only works in graphics mode.

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.

Write formatted data to string. Composes a string with the same text that would be printed if format was used on printf, but instead of being printed, the content is stored as a C string in the buffer pointed by str. The size of the buffer should be large enough to contain the entire resulting string (see snprintf for a safer version). A terminating null character is automatically appended after the content. After the format parameter, the function expects at least as many additional arguments as needed for format.











Program calculates the standard deviation of 10 data using arrays. This program calculates the 'standard deviation' of a individual series using arrays. calculate "Standard Deviation",