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

Animated 3D Car in Turbo C++ 3.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
/* Animated 3D Car in Turbo C++ 3.0 It consist of Lights effect, Sound Effect. Press 'L' for Lights effect and 'H' for Horn. */ #include<graphics.h> #include<conio.h> #include<dos.h> #include<stdlib.h> #include<process.h> void main() { int gd=DETECT,gm; initgraph(&gd,&gm,"c:\tc\bgi"); int c=12; setbkcolor(0); //setlinestyle(0,1,2); int t; while(1) { settextstyle(2,0,5); outtextxy(100,10,"Press L,H ,T,P"); outtextxy(100,30,"Press 1 for Quit"); as: setcolor(13); ellipse(380,127,20,152,130,35); //////////////////////////////rear////////////////////////// line(490,109,560,142); line(560,142,569,142); line(569,142,582,102); line(582,102,620,92); line(593,132,617,125); line(617,124,627,96); line(620,92,628,97); line(472,86,602,96); line(501,113,575,121); line(443,77,475,80); line(443,77,432,93); line(475,80,472,85); //setcolor(4); line(593,132,593,137); line(593,137,600,141); line(600,141,600,185); line(600,185,608,192); line(608,192,608,234); line(608,234,586,253); line(586,253,577,248); ///////////////////////// mirror line(263,112,363,127); line(193,160,263,112); line(193,160,220,170); line(220,170,280,180); line(280,180,320,185); line(320,185,363,127); ////////////////////////////////sidemirror line(340,194,460,169); line(460,169,519,152); ellipse(512,144,300,30,10,10); ellipse(467,143,28,100,50,30); line(510,128,521,138); line(435,116,440,171); // setcolor(4); ////////////////////////////////////////cont// line(339,194,372,144); // line(372,140,386,128); ellipse(454,208,87,123,128,95); line(372,144,384,128); int b,x,y; ////////////////////////lower line(365,298,524,264); line(365,298,330,310); line(330,310,323,310); ///////////////////////////////bumper ellipse(162,221,135,190,90,40); line(96,193,140,174); line(140,174,160,168); line(160,168,192,161); //////////////////////front ellipse(75,246,95,190,18,18); line(57,251,57,286); //setcolor(4); ellipse(181,178,232,263,200,137); ellipse(195,180,256,286,200,137); ellipse(191,171,228,247,200,100); ellipse(231,198,234,275,200,80); //setcolor(9); //ellipse(195,170,256,286,200,137); //setcolor(12); ellipse(196,167,228,246,200,90); ellipse(231,184,234,276,200,80); ellipse(191,200,228,246,200,90); ellipse(228,218,234,276,200,80); ellipse(258,268,180,220,200,40); ellipse(178,296,244,355,16,10); ellipse(238,249,227,250,200,60); /////////////wheel1 ellipse(302,281,320,77,26,45); ellipse(290,277,65,162,40,45); ellipse(278,288,144,212,31,45); /////////////wheel2 //setcolor(5); ellipse(302+260,229,328,87,26,45); ellipse(290+280-7,277-50+2,90,162,40,45); ellipse(278+270,288-50,144,215,27,45); b=0; int v=0; ///////// ellipse(302+250+v,227+b,295,90,29,41); ellipse(302+234+v,231+b,245,306,50,40); //setlinestyle(3,0,3); ellipse(302+248+v,229+b,0,360,21,30); ellipse(302+247+v,229+b,0,360,8,10); setfillstyle(6,11); //floodfill(302+248+v,230+b,13); //line(546,201,546,257); //line(554,201,554,257); //setcolor(4); line(546+v,201+b,546+v,220+b); line(551+v,201+b-2,551+v,220+b); line(546+v,238+b,546+v,257+b); line(551+v,238+b+2,551+v,257+b+2); line(530+v,225+b,541+v,225+b); line(530+v,230+b,541+v,230); line(557+v,225+b,570+v,225+b); line(557+v,230+b,570+v,230+b); line(563+v,206+b,552+v,222+b); line(534+v,246+b,543+v,232+b); line(566+v,210+b,556+v,223+b); line(536+v,250+b,544+v,238+b); line(536+v,207+b,546+v,222+b); line(532+v,213+b,542+v,224+b); line(556+v,235+b,566+v,247+b); line(551+v,237+b,563+v,253+b); //////////////////////////////////////////////////// v=-260; b=56; ellipse(302+233+v,221+b,260,60,49,51); //ellipse(302+234+v,231+b,245,306,50,40); //setlinestyle(3,0,3); ellipse(302+243+v,224+b,0,360,28,35); // line(249,328,269,328); ellipse(300+245+v,223+b,0,360,10,12); ellipse(285+249+v,239+b,210,260,30,33); //floodfill(285+258+v,230+b,12); b=45; v=v-4; line(546+v,201+b,546+v,220+b+2); line(551+v,201+b,551+v,220+b+2); b=b+8; line(546+v,238+b,546+v,257+b+4); line(551+v,238+b,551+v,257+b+4); v=v-2; line(530+v-6,225+b,541+v,225+b); line(530+v-6,230+b,541+v,230+b); v=v+5; line(557+v,225+b,570+v+3,225+b); line(557+v-1,230+b,570+v+3,230+b); b=b-5; v=v-5; line(565+v+3,206+b,552+v+4,222+b-2); b=b+15; line(534+v,246+b,543+v+3,232+b-5); b=b-10; line(566+v+7,210+b-5,556+v+4,220+b); line(536+v-5,250+b,544+v-2,238+b-4); line(536+v,207+b-8,545+v,222+b-5); line(531+v,212+b-8,542+v,224+b-2); line(556+v,235+b,566+v+3,247+b+5); line(551+v,237+b,563+v+2,253+b+3); ///////////////////lights ellipse(199,250,144,345,18,8); line(185,245,206,230); //setcolor(4); ellipse(223,234,340,110,8,5); line(230,237,217,252); line(206,230,220,229); //setfillstyle(1,4); //floodfill(200,240,12); ///////////////////////////////////// line(90,223,152,236); line(152,236,137,254); line(90,223,90,242); //setfillstyle(10,9); //floodfill(91,230,14); ellipse(240,270,104,136,100,60); ellipse(185,237,120,160,100,60); ellipse(80,221,357,134,10,10); line(152,236,168,228); /////////////////////////////////////////////// line(435,116,440,171); //////////////////////////////////////////hp //line(134,185,220,210); line(134,185,196,160); line(214,212,318,185); /////////////////////////////////////////////////light //setcolor(14); ellipse(166,247,99,330,8,8); ellipse(171,243,310,129,7,7); putpixel(174,250,13); putpixel(173,251,13); putpixel(164,239,13); putpixel(165,238,13); /////////////////////////////////////////road///////////////////// setcolor(13); line(1,430,639,300); line(1,445,639,315); line(1,210,93,194); line(1,195,194,158); //line(1,170,639,71); //line(1,170,229,135); line(520,90,639,71); line(478,86,639,56); int c=0; line(10,194+c,10,208+c); line(40,189+c,40,204+c); line(70,183+c,70,198+c); line(100,176+c,100,190+c); line(130,170+c,130,177+c); line(160,166+c,160,168+c); line(190,160+c,190,161+c); line(190+330,78+c,190+330,89+c); line(190+360,72+c,190+360,85+c); line(190+390,67+c,190+390,81+c); line(190+420,62+c,190+420,76+c); line(190+449,57+c,190+449,71+c); c=236; line(10,192+c,10,208+c); line(40,189+c-2,40,204+c-3); line(70,183+c-3,70,198+c-3); line(100,176+c-2,100,190+c-2); line(130,170+c-2,130,177+c+5); line(160,166+c-3,160,168+c+8); line(190,160+c-4,190,161+c+9); line(190+30,156+c-5,190+30,170+c-5); line(190+30+30,156+c-12,190+30+30,170+c-12); line(190+90,156+c-18,190+90,170+c-17); line(190+120,156+c-25,190+120,170+c-25); line(190+150,156+c-30,190+150,170+c-30); line(190+180,156+c-37,190+180,170+c-36); line(190+210,156+c-42,190+210,170+c-42); line(190+240,156+c-48,190+240,170+c-48); line(190+270,156+c-55,190+270,170+c-54); line(190+300,156+c-61,190+300,170+c-61); line(190+330,78+c+10,190+330,89+c+13); line(190+360,72+c+11,190+360,85+c+13); line(190+390,67+c+10,190+390,81+c+10); line(190+420,62+c+8,190+420,76+c+10); line(190+449,57+c+8,190+449,71+c+8); /////////////////road setcolor(12); /////////////////////////////1 line(1,310,25,306); line(6,318,30,315); line(1,310,6,318); line(25,306,30,314); int k,m; k=13*45+19; m=16*(-8); //2 setcolor(12); line(605,310-128,629,306-128); line(610,318-128,634,315-128); line(605,310-128,610,318-128); line(629,306-128,634,314-128); setcolor(12); //////////////////////////////////3 k=45; m=-8; line(46,302,70,298); line(51,310,75,307); line(46,302,51,310); line(70,298,75,306); setfillstyle(1,0); floodfill(64,303,12); setfillstyle(1,14); floodfill(14,314,12); floodfill(617,183,12); setfillstyle(1,0); floodfill(14,314,12); floodfill(617,183,12); setfillstyle(1,14); floodfill(64,303,12); t=getch(); if(t=='1') exit(0); if(t=='h') { sound(710); delay(500); nosound(); //break; } if(t=='t') { while(!kbhit()) { setfillstyle(1,0); floodfill(536,213,13); floodfill(563,213,13); floodfill(561,244,13); floodfill(538,244,13); floodfill(274,295,13); floodfill(294,295,13); floodfill(274,265,13); floodfill(294,265,13); floodfill(548,250,13); floodfill(548,214,13); floodfill(533,228,13); floodfill(563,228,13); floodfill(262,281,13); floodfill(308,281,13); floodfill(284,251,13); floodfill(284,295,13); setfillstyle(1,random(12)); floodfill(200,250,13); delay(10); //setfillstyle(1,11); floodfill(170,250,13); floodfill(80,230,13); } setfillstyle(1,0); floodfill(200,250,13); delay(10); //setfillstyle(1,11); floodfill(170,250,13); floodfill(80,230,13); } if(t=='l') { while(!kbhit()) { delay(120); setfillstyle(6,0); //////////////////////////ty floodfill(536,213,13); floodfill(563,213,13); floodfill(561,244,13); floodfill(538,244,13); floodfill(274,295,13); floodfill(294,295,13); floodfill(274,265,13); floodfill(294,265,13); setfillstyle(1,0); floodfill(64,303,12); ///////////////////////////////////road setfillstyle(9,0); /////////////////////color floodfill(81-40+5,419+7,13); floodfill(151-40,409+7,13); floodfill(211-40,397+7,13); floodfill(271-40,380+7,13); floodfill(331-40,368+7,13); floodfill(396-40,355+7,13); floodfill(450-40,345+7,13); floodfill(510-40,335+7,13); floodfill(570-40,325+7,13); floodfill(630-40,312+7,13); ////////////////////// floodfill(50,197,13); floodfill(110,177,13); floodfill(166,165,13); floodfill(527,86,13); floodfill(587,71,13); setfillstyle(6,14); //////////////////////////ty floodfill(548,250,13); floodfill(548,214,13); floodfill(533,228,13); floodfill(563,228,13); floodfill(262,281,13); floodfill(308,281,13); floodfill(284,251,13); floodfill(284,295,13); ////////////////////////////////////////road setfillstyle(9,10);///////////////////////////////////color floodfill(19,429,13); floodfill(81,419,13); floodfill(151,409,13); floodfill(211,397,13); floodfill(271,380,13); floodfill(331,368,13); floodfill(396,355,13); floodfill(450,345,13); floodfill(510,335,13); floodfill(570,325,13); floodfill(630,312,13); ////////////////////////////////////// floodfill(20,197,13); floodfill(80,187,13); floodfill(133,174,13); floodfill(517,86,13); floodfill(557,81,13); floodfill(627,70,13); setfillstyle(1,14); floodfill(14,314,12); floodfill(617,183,12); /////////////////////////////////////// setfillstyle(10,4); floodfill(302+248,230,13); floodfill(302+248+v,230+b,13); ///light setfillstyle(6,11); /////////// floodfill(200,250,13); floodfill(170,250,13); floodfill(80,230,13); delay(120); setfillstyle(6,0);/////////////////////ty floodfill(548,250,13); floodfill(548,214,13); floodfill(533,228,13); floodfill(563,228,13); floodfill(262,281,13); floodfill(308,281,13); floodfill(284,251,13); floodfill(284,295,13); /////////////////////////////////////road setfillstyle(9,0); ///////////////color floodfill(19,429,13); floodfill(81,419,13); floodfill(151,409,13); floodfill(211,397,13); floodfill(271,380,13); floodfill(331,368,13); floodfill(396,355,13); floodfill(450,345,13); floodfill(510,335,13); floodfill(570,325,13); floodfill(630,312,13); /////////////////////////////////////////////////////// floodfill(20,197,13); floodfill(80,187,13); floodfill(133,174,13); floodfill(517,86,13); floodfill(557,81,13); floodfill(627,70,13); ///////////////////////////// setfillstyle(1,0); floodfill(14,314,12); floodfill(617,183,12); setfillstyle(6,10); /////////////ty floodfill(536,213,13); floodfill(563,213,13); floodfill(561,244,13); floodfill(538,244,13); floodfill(274,295,13); floodfill(294,295,13); floodfill(274,265,13); floodfill(294,265,13); ////////////////////////////////////////////////road setfillstyle(9,14);/////////////////////////////////////////color floodfill(81-40+5,419+7,13); floodfill(151-40,409+7,13); floodfill(211-40,397+7,13); floodfill(271-40,380+7,13); floodfill(331-40,368+7,13); floodfill(396-40,355+7,13); floodfill(450-40,345+7,13); floodfill(510-40,335+7,13); floodfill(570-40,325+7,13); floodfill(630-40,312+7,13); ///////////////////////////////////////// floodfill(50,197,13); floodfill(110,177,13); floodfill(166,165,13); floodfill(527,86,13); floodfill(587,71,13); setfillstyle(1,14); floodfill(64,303,12); setfillstyle(9,4); floodfill(302+248,230,13); floodfill(302+248+v,230+b,13); delay(20); setfillstyle(1,14); floodfill(200,250,13); floodfill(170,250,13); floodfill(80,230,13); delay(20); setfillstyle(1,0); floodfill(200,250,13); floodfill(170,250,13); floodfill(80,230,13); } } if(t=='p') { int n=0; while(!kbhit()) { if(n<=60) n++; setcolor(0); rectangle(1+1,-10,90-1,-12+n); delay(14); setcolor(9); rectangle(1,-10,90,-10+n); if(n==60) { outtextxy(10,10,"L-LIGHTS"); outtextxy(10,20,"H-HORN"); //outtextxy(10,30,"T-AllOY"); delay(400); } } setcolor(0); rectangle(1,-10,90,-10+n); rectangle(1,-10,90,-11+n); outtextxy(10,10,"L-LIGHTS"); outtextxy(10,20,"H-HORN"); //outtextxy(10,30,"T-AllOY"); } } circle(300,100,3); nosound(); getch(); }

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.

#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.

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.

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.

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.

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.

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)

setbkcolor() function is used to set the background color in graphics mode. The default background color is black and default drawing color as we know is white. setbkcolor() function takes only one argument it would be either the name of color defined in graphics.h header file or number associated with those colors. If we write setbkcolor(yellow) it changes the background color in Green. The possible color values are from 0 - 15 black, blue, green, cyan, red, magenta, brown, lightgray, darkgray, lightblue, lightgreen, lightcyan, lightred, lightmagenta, yellow, white and blink (128).

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.

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.

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 putpixel() function which plots a pixel at location (x, y) of specified color. Where, (x, y) is the location at which pixel is to be put, and color specifies the color of the pixel. To put a pixel on the screen at a particular position, calling the pixel() function is a good way. This function takes three parameters as the position of the pixel and also the color of the pixel.

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.

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.

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.

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.

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.

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.

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.

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

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

Ellipse is used to draw an ellipse (x,y) are coordinates of center of the ellipse, startangle is the starting angle, end angle is the ending angle, and fifth and sixth parameters specifies the X and Y radius of the ellipse. To draw a complete ellipse strangles and end angle should be 0 and 360 respectively. Making a circle and an ellipse in C can be done easily. How to do is, first initialize a graph with two parameters and a path to the "bgi" folder in your system.

floodfill function is used to fill an enclosed area. Current fill pattern and fill color is used to fill the area.(x, y) is any point on the screen if (x,y) lies inside the area then inside will be filled otherwise outside will be filled, border specifies the color of boundary of area. To change fill pattern and fill color use setfillstyle.








A C++ Program to check whether an directed graph is tree or not. Graph is tree if it doesn't contain cycles. Pointer to an array containing adjacency lists. Returns true if there is a cycle


In computer science, An "Interval Tree" is an ordered tree data structure to hold intervals. Specifically, it allow one to efficiently find all intervals that overlap with any given interval


In case of 'an array' we check that a given key or a number is present in array at any index or not by "comparing each element" of array. By traversing the whole data structure elements