Monday 24 June 2013

MENU in C/C++

Program : NAVIGATIONAL MENU
Platform : Turbo C 3.0Description : It is a program to demonstrate the menu system in C/C++. It also uses navigation through ARROW keys..........!!

View or Download CPP


#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
int ch=1;

void menu();
void choice();

int main()
{
menu();
getch();
return 0;
}
////////////////////////////////
////////////////////////////////

void menu()
{
int gdriver = DETECT, gmode,i;

/* initialize graphics mode */
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
setcolor(2);
for(i=0;i<10;i++){rectangle(10+i,10+i,620+i,460+i);delay(50);}
setfillstyle(1,15);
bar(40,40,600,440);
settextstyle(7,0,5);
outtextxy(270,60,"MENU");
setcolor(4);
settextstyle(1,0,2);
/* 1 */
rectangle(180,145,450,180);
rectangle(185,147,445,178);
/* 2 */
rectangle(180,195,450,230);
rectangle(185,197,445,228);
/* 3 */
rectangle(180,245,450,280);
rectangle(185,247,445,278);
/* 4 */
rectangle(180,295,450,330);
rectangle(185,297,445,328);
/* 5 */
rectangle(180,345,450,380);
rectangle(185,347,445,378);
setcolor(1);
outtextxy(230,150,"1.EDUCATION");
outtextxy(230,200,"2.SPORTS");
outtextxy(230,250,"3.ENTERTAINMENT");
outtextxy(230,300,"4.POLITICS");
outtextxy(230,350,"5.EXIT");
setcolor(9);
rectangle(180,145,450,180);
rectangle(185,147,445,178);
choice();
}

//////////////////////////////////
//////////////////////////////////

void choice()
{
switch(getch())
 { case 'H':
    switch(ch)
   {
     case 2:setcolor(4);
    rectangle(180,195,450,230);
    rectangle(185,197,445,228);
    setcolor(9);
    rectangle(180,145,450,180);
    rectangle(185,147,445,178);
    ch--;
    choice();

     case 3:setcolor(4);
    rectangle(180,245,450,280);
    rectangle(185,247,445,278);
    setcolor(9);
    rectangle(180,195,450,230);
    rectangle(185,197,445,228);
    ch--;
    choice();

     case 4:setcolor(4);
    rectangle(180,295,450,330);
    rectangle(185,297,445,328);
    setcolor(9);
    rectangle(180,245,450,280);
    rectangle(185,247,445,278);
    ch--;
    choice();

     case 5:setcolor(4);
    rectangle(180,345,450,380);
    rectangle(185,347,445,378);
    setcolor(9);
    rectangle(180,295,450,330);
    rectangle(185,297,445,328);
    ch--;
    choice();

     default : choice();
   }

    break;
 case 'P':/*if(ch<5&&ch>=1){ch++;*/
    switch(ch)
   {
     case 1:setcolor(4);
    rectangle(180,145,450,180);
    rectangle(185,147,445,178);
    setcolor(9);
    rectangle(180,195,450,230);
    rectangle(185,197,445,228);
    ch++;
    choice();

     case 2:setcolor(4);
    rectangle(180,195,450,230);
    rectangle(185,197,445,228);
    setcolor(9);
    rectangle(180,245,450,280);
    rectangle(185,247,445,278);
    ch++;
    choice();

     case 3:setcolor(4);
    rectangle(180,245,450,280);
    rectangle(185,247,445,278);
    setcolor(9);
    rectangle(180,295,450,330);
    rectangle(185,297,445,328);
    ch++;
    choice();

     case 4:setcolor(4);
    rectangle(180,295,450,330);
    rectangle(185,297,445,328);
    setcolor(9);
    rectangle(180,345,450,380);
    rectangle(185,347,445,378);
    ch++;
    choice();

     default : choice();
   }

    /*}*/break;
   case 27: exit(0);
   case 13: switch(ch){
case 1:setcolor(MAGENTA);outtextxy(230,150,"1.EDUCATION");
      setcolor(3);outtextxy(200,400,"You selected EDUCATION");getch();exit(0);
case 2:setcolor(MAGENTA);outtextxy(230,200,"2.SPORTS");
      setcolor(3);outtextxy(200,400,"You selected SPORTS");getch();exit(0);
case 3:setcolor(MAGENTA);outtextxy(230,250,"3.ENTERTAINMENT");
      setcolor(3);outtextxy(200,400,"You selected ENTERTAINMENT");getch();exit(0);
case 4:setcolor(MAGENTA);outtextxy(230,300,"4.POLITICS");
      setcolor(3);outtextxy(200,400,"You selected POLITICS");getch();exit(0);
case 5:exit(0);
default : choice;
      }
   default : choice();
 }

}
/* Codetechie.blogspot.com */

Friday 21 June 2013

Code Complexity

Code Complexity is influenced by the factors :
  • Average Hierarchy Height
  • Average Number of Derived Classes
  • Afferent Coupling (no. of other packages that depend upon classes within a package )
  • Efferent Coupling ( no.of other packages that classes from this package depend upon )
  • Number of “if” condition statements and many more.........!
Cyclomatic Complexity (MCC)
It was developed by Thomas J. McCabe in 1976 and is used to indicate the complexity of a program. It directly measures the number of linearly independent paths through a program's source code.

Cyclomatic complexity is computed using the control flow graph of the program.
The cyclomatic complexity of a section of source code is the count of the number of linearly independent paths through the source code.
For ex : If the source code contained no decision points such as IF statements or FOR loops, the complexity would be 1, since there is only a single path through the code.
If the code had a single IF statement containing a single condition there would be two paths through the code, one path where the IF statement is evaluated as TRUE and one path where the IF statement is evaluated as FALSE.

Mathematically the complexity M is then defined as :
M = E − N + 2 P
where
E = no. of edges of the graph
N = no. of nodes of the graph
P = no. of connected components (exit nodes)

A simpler method of computing the MCC is demonstrated in the equation below. If D is the number of decision points in the program, then
M = D + 1 (Since, each decision point normally has two possible paths)

Some standard values of Cyclomatic Complexity are shown below:
M = D + 1
Assessment
1-10
not much risk
11-20
moderate risk
21-50   
high risk
51+
Not testable, very high risk

Thursday 20 June 2013

JAVA VS C++

  • C++ was designed for systems and applications programming
  • It is Write Once Compile Anywhere ( WOCA )
  • It Allows procedural programmingfunctional programmingobject-oriented programminggeneric programming, and template metaprogramming
  • It Runs as native executable machine code for the target instruction sets
  • It has multiple binary compatibility standards 
  • Pointers, references, and pass-by-value are supported for all types
  • Supports Single and Multiple inheritance of classes, including virtual inheritance
  • Java is a general-purpose, class-based, object-oriented computer programming language that is specifically designed to have as few implementation dependencies as possible
  • It is Write Once Run Anywhere / Everywhere ( WORA / WORE )
  • It strongly encourages exclusive use of the object-oriented programming paradigm. It also includes support for generic programming and creation of scripting languages
  • Runs in a virtual machine
  • It allows metaprogramming and dynamic code generation at runtime
  • It has a single, OS- and compiler-independent binary compatibility standard
  • All types (primitive and reference ) are always passed by value
  • It supports single inheritance of classes, and supports multiple inheritance through the Interfaces


Execution time for different Environment for Pentium PC ( Windows 95 )
Version
Execution Environment
Execution Time
Java array
Classic VM, JDK-1.2.2-001
81s

HotSpot VM 1.0.1 / Client VM 1.3beta-O
58s / 58s
Java Vector
HotSpot VM 1.0.1 / Client VM 1.3beta-O
216s / 215s
Java ArrayList
Client VM 1.3beta-O
166s
C++ pointer
MS Visual C++ 6.0
44s

Cygwin B20.1, egcs-2.91.57
19s
C++ object
MS Visual C++ 6.0
11s

Cygwin B20.1, egcs-2.91.57
16s
C++ vector
Cygwin B20.1, egcs-2.91.57
15s
C++ STL
Cygwin B20.1, egcs-2.91.57
11s

Tuesday 18 June 2013

MOUSE in C++

This is a simple program made in C/C++ to :
  • Initialize Mouse
  • Show mouse
  • Read Mouse Position
  • Detect Mouse Clicks (Left / Right) 

DOWNLOAD CPP / SOURCE CODE



/*  Program Starts Here */
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<process.h>

void MouseMenu();
void main()
{
     MouseMenu();

}

///////////////////////////////////////
///////////////////////////////////////

void MouseMenu()
{
int i,j,k,l;
clrscr();_setcursortype(_NOCURSOR);
textmode(C80);textcolor(14);
for(i=1;i<=4;i++){gotoxy(35,5*i);cprintf("%c",201);gotoxy(45,5*i);cprintf("%c",187);
gotoxy(36,5*i);cprintf("%c%c%c%c%c%c%c%c%c",205,205,205,205,205,205,205,205,205);
gotoxy(36,5*i+3);cprintf("%c%c%c%c%c%c%c%c%c",205,205,205,205,205,205,205,205,205);
gotoxy(35,5*i+3);cprintf("%c",200);gotoxy(45,5*i+3);cprintf("%c",188);
gotoxy(35,5*i+1);cprintf("%c",186);gotoxy(45,5*i+1);cprintf("%c",186);
gotoxy(35,5*i+2);cprintf("%c",186);gotoxy(45,5*i+2);cprintf("%c",186);
      }
textcolor(13);
gotoxy(37,6);cprintf("MENU 1");
gotoxy(37,11);cprintf("MENU 2");
gotoxy(37,16);cprintf("MENU 3");
gotoxy(37,21);cprintf("MENU 4");
textcolor(12);
gotoxy(38,7);cprintf("JAVA");
gotoxy(38,12);cprintf("C++");
gotoxy(38,17);cprintf("PHP");
gotoxy(37,22);cprintf("ANDROID");
_setcursortype(_NOCURSOR);
REGS regs;
//Initializing mouse
regs.x.ax=0;int86(0x33,&regs,&regs);
//Showing mouse
regs.x.ax=1;int86(0x33,&regs,&regs);

/* Reading current position of mouse */
   while(1){
   regs.x.ax=3;int86(0x33,&regs,&regs);
  if(regs.x.cx>=270&&regs.x.cx<=365&&regs.x.dx>=32&&regs.x.dx<=63)
  {
   textcolor(14);
   gotoxy(37,6);cprintf("MENU 1");
   textcolor(14);
   gotoxy(38,7);cprintf("JAVA");
   //Reading mouse click
if(regs.x.bx==1){
   gotoxy(2,2);textcolor(2);
   cprintf("Left Button Clicked!");gotoxy(2,3);cprintf("Menu 1 Selected !");
   gotoxy(2,4);cprintf("JAVA !");
   }
if(regs.x.bx==2){
   gotoxy(2,2);textcolor(2);
   cprintf("Right Button Clicked!");gotoxy(2,3);cprintf("Menu 1 Selected !");
   gotoxy(2,4);cprintf("JAVA !");
   }
       while(kbhit()){exit(0);}
  }
  else{textcolor(13);
   gotoxy(37,6);cprintf("MENU 1");
   textcolor(12);
   gotoxy(38,7);cprintf("JAVA");
      }

   ////////////////////////////////////////

   if(regs.x.cx>=270&&regs.x.cx<=365&&regs.x.dx>=70&&regs.x.dx<=101)
  {
   textcolor(14);
   gotoxy(37,11);cprintf("MENU 2");
   textcolor(14);
   gotoxy(38,12);cprintf("C++");
   //Reading mouse click
if(regs.x.bx==1){
   gotoxy(2,2);textcolor(2);
   cprintf("Left Button Clicked!"); gotoxy(2,3);cprintf("Menu 2 Selected !");
   gotoxy(2,4);cprintf("C++ !");
   }
if(regs.x.bx==2){
   gotoxy(2,2);textcolor(2);
   cprintf("Right Button Clicked!");gotoxy(2,3);cprintf("Menu 2 Selected !");
   gotoxy(2,4);cprintf("C++ !");
   }
       while(kbhit()){exit(0);}
  }
  else{textcolor(13);
   gotoxy(37,11);cprintf("MENU 2");
   textcolor(12);
   gotoxy(38,12);cprintf("C++");
      }

      //////////////////////////////////////

      if(regs.x.cx>=270&&regs.x.cx<=365&&regs.x.dx>=110&&regs.x.dx<=141)
  {
   textcolor(14);
   gotoxy(37,16);cprintf("MENU 3");
   textcolor(14);
   gotoxy(38,17);cprintf("PHP");
   //Reading mouse click
if(regs.x.bx==1){
   gotoxy(2,2);textcolor(2);
   cprintf("Left Button Clicked!"); gotoxy(2,3);cprintf("Menu 3 Selected !");
   gotoxy(2,4);cprintf("PHP !");
   }
if(regs.x.bx==2){
   gotoxy(2,2);textcolor(2);
   cprintf("Right Button Clicked!");gotoxy(2,3);cprintf("Menu 3 Selected !");
   gotoxy(2,4);cprintf("PHP !");
   }
       while(kbhit()){exit(0);}
  }
  else{textcolor(13);
   gotoxy(37,16);cprintf("MENU 3");
   textcolor(12);
   gotoxy(38,17);cprintf("PHP");
      }

      /////////////////////////////////////
     if(regs.x.cx>=270&&regs.x.cx<=365&&regs.x.dx>=150&&regs.x.dx<=182)
  {
   textcolor(14);
   gotoxy(37,21);cprintf("MENU 4");
   textcolor(14);
   gotoxy(37,22);cprintf("ANDROID");
   //Reading mouse click
if(regs.x.bx==1){
   gotoxy(2,2);textcolor(2);
   cprintf("Left Button Clicked!"); gotoxy(2,3);cprintf("Menu 4 Selected !");
   gotoxy(2,4);cprintf("ANDROID !");
   }
if(regs.x.bx==2){
   gotoxy(2,2);textcolor(2);
   cprintf("Right Button Clicked!");gotoxy(2,3);cprintf("Menu 4 Selected !");
   gotoxy(2,4);cprintf("ANDROID !");
   }
       while(kbhit()){exit(0);}
  }
  else{textcolor(13);
   gotoxy(37,21);cprintf("MENU 4");
   textcolor(12);
   gotoxy(37,22);cprintf("ANDROID");
      }
while(kbhit()){exit(0);}
  }
}
/* Codetechie.blogspot.com */
/* END */

Download Source Code (CPP)

Monday 17 June 2013

SOLAR SYSTEM ( GRAPHICS IN C/C++ )

SOLAR SYSTEM
T
his is a program which uses simple C/C++ Graphics Function to show our SOLAR SYSTEM.

View or Download Cpp

/* Praogram Starts Here */

#include"stdio.h"
#include"graphics.h"
#include"conio.h"
#include"dos.h"
#include"math.h"
#include"stdlib.h"


void main()
{
    int gd=DETECT,gm;
    float i=0,j=100,me=75,ve=23,ma=105,ju=175,sa=10,ur=300,ne=200,pl=175,s=0;
    int x,y,k,tri[8],si,sx=random(300),sy=random(400),X,Y,ss;
    unsigned int earth,moon,mercury,venus,mars,jupiter,saturn,uranus,neptune,pluto,
    sunsize,ship,ship2;
    void *ear,*moo,*mer,*ven,*mar,*jup,*sat,*ura,*nep,*plu,*sun,*ships,*ships2;
    x=300;
    y=210;
    initgraph(&gd,&gm,"c:\\tc\\bgi");/*Set the BGI path*/
    setfillstyle(1,10);
    setcolor(2);
    fillellipse(50,50,13,13);
    earth=imagesize(35,35,65,65);
    ear=malloc(earth);
    getimage(35,35,65,65,ear);
    cleardevice();

    setfillstyle(1,15);
    setcolor(15);
    fillellipse(25,25,5,5);
    moon=imagesize(15,15,35,35);
    moo=malloc(moon);
    getimage(15,15,35,35,moo);
    cleardevice();

    setfillstyle(1,4);
    setcolor(4);
    fillellipse(15,15,4,4);
    mercury=imagesize(10,10,20,20);
    mer=malloc(mercury);
    getimage(10,10,20,20,mer);
    cleardevice();


    setfillstyle(1,11);
    setcolor(11);
    fillellipse(15,15,7,7);
    venus=imagesize(7,7,23,23);
    ven=malloc(venus);
    getimage(7,7,23,23,ven);
    cleardevice();


    setfillstyle(1,6);
    setcolor(6);
    fillellipse(20,20,14,14);
    mars=imagesize(5,5,35,35);
    mar=malloc(mars);
    getimage(5,5,35,35,mar);
    cleardevice();


    setfillstyle(1,7);
    setcolor(7);
    fillellipse(25,25,18,18);
    jupiter=imagesize(5,5,45,45);
    jup=malloc(jupiter);
    getimage(5,5,45,45,jup);
    cleardevice();


    setfillstyle(1,8);
    setcolor(8);
    fillellipse(50,50,12,12);
    uranus=imagesize(35,35,65,65);
    ura=malloc(uranus);
    getimage(35,35,65,65,ura);
    cleardevice();

    setfillstyle(1,12);
    setcolor(12);
    fillellipse(50,50,11,11);
    neptune=imagesize(35,35,65,65);
    nep=malloc(neptune);
    getimage(35,35,65,65,nep);
    cleardevice();

    setfillstyle(1,1);
    setcolor(1);
    fillellipse(50,50,8,8);
    pluto=imagesize(35,35,65,65);
    plu=malloc(pluto);
    getimage(35,35,65,65,plu);
    cleardevice();


    setcolor(14);
    setfillstyle(1,14);
    fillellipse(40,40,25,25);
    for(si=0; si<25; si++)
    {
    tri[0]=(40+25*cos(s));
    tri[1]=(40+25*sin(s));
    s=s+0.3;
    tri[2]=(40+25*cos(s));
    tri[3]=(40+25*sin(s));

    tri[4]=(40+40*cos((2*s-0.3)/2));
    tri[5]=(40+40*sin((2*s-0.3)/2));

    tri[6]=tri[0];
    tri[7]=tri[1];

    fillpoly(4,tri);

    }

    sunsize=imagesize(0,0,80,80);
    sun=malloc(sunsize);
    getimage(0,0,80,80,sun);
    cleardevice();

    setfillstyle(1,15);
    setcolor(15);
    fillellipse(40,40,33,16);
    fillellipse(40,25,15,10);
    setfillstyle(1,2);
    fillellipse(14,37,5,5);
    fillellipse(35,40,5,5);
    fillellipse(55,39,5,5);
    setfillstyle(1,4);
    fillellipse(25,39,5,5);
    fillellipse(46,40,5,5);
    fillellipse(65,37,5,5);
    setfillstyle(1,0);
    fillellipse(30,20,2,2);
    fillellipse(35,20,2,2);
    fillellipse(40,20,2,2);
    fillellipse(45,20,2,2);
    fillellipse(50,20,2,2);
    ship=imagesize(0,0,80,80);
    ships=malloc(ship);
    getimage(0,0,80,80,ships);
    cleardevice();

    setfillstyle(1,15);
    setcolor(15);
    fillellipse(40,40,33,16);
    fillellipse(40,25,15,10);
    setfillstyle(1,4);
    fillellipse(14,37,5,5);
    fillellipse(35,40,5,5);
    fillellipse(55,39,5,5);
    setfillstyle(1,2);
    fillellipse(25,39,5,5);
    fillellipse(46,40,5,5);
    fillellipse(65,37,5,5);
    setfillstyle(1,0);
    fillellipse(30,20,2,2);
    fillellipse(35,20,2,2);
    fillellipse(40,20,2,2);
    fillellipse(45,20,2,2);
    fillellipse(50,20,2,2);
    ship2=imagesize(0,0,80,80);
    ships2=malloc(ship2);
    getimage(0,0,80,80,ships2);
    cleardevice();



    setfillstyle(1,9);
    setcolor(9);
    fillellipse(45,45,16,16);
    setcolor(8);
    ellipse(45,45,125,390,20,7);
    setcolor(1);
    ellipse(45,45,120,400,23,8);
    setcolor(4);
    ellipse(45,45,120,400,25,9);
    setcolor(5);
    ellipse(45,45,120,424,28,10);
    setcolor(6);
    ellipse(45,45,115,425,30,11);
    saturn=imagesize(0,0,50,50);
    sat=malloc(saturn);
    getimage(0,0,75,75,sat);
    cleardevice();
    setcolor(15);


    for(i=0; i<1000 && !kbhit(); i++)
    {
        moveto(getmaxx()/2,getmaxy()/2);

lineto(random(600)+random(600)*cos(i),random(600)+random(600)*sin(i));
        delay(10);
    }
    cleardevice();

    delay(300);
    setlinestyle(0,0,3);
    rectangle(0,0,getmaxx(),getmaxy());
    delay(700);
    for(i=0; i<1000; i++)
    {
        putpixel(random(630),random(530),15);
        putpixel(random(630),random(530),11);
        delay(5);
    }
    setlinestyle(3,0,1);
    setlinestyle(0,0,1);
    for(k=0; k<200; k++)
    {
        i=i+0.2;
        j=j+0.7;
        me=me+0.1;
        ve=ve+0.3;
        ma=ma+0.1;
        ju=ju+0.08;
        sa=sa+0.07;
        ur=ur+0.06;
        ne=ne+0.05;
        pl=pl+0.04;
        putpixel(x+100*cos(i)+13,y+80*sin(i)+13,10);
        putpixel(x+(100*cos(i))+(30*cos(j))+5,y+(80*sin(i))+(25*sin(j))+5,1);
        putpixel(x+60*cos(me)+4,y+40*sin(me)+4,4);
        putpixel(x+80*cos(ve)+7,y+60*sin(ve)+7,3);
        putpixel(x+125*cos(ma)+14,y+110*sin(ma)+14,6);
        putpixel(x+165*cos(ju)+18,y+130*sin(ju)+18,7);
        putpixel(x+220*cos(sa)+30+16,y+170*sin(sa)+30+16,9);
        putpixel(x+250*cos(ur)+12,y+200*sin(ur)+12,8);
        putpixel(x+280*cos(ne)+11,y+230*sin(ne)+11,12);
        putpixel(x+310*cos(pl)+8,y+250*sin(pl)+8,1);
    }
        setfillstyle(1,14);
        setcolor(14);
        fillellipse(x,y,25,25);
        delay(250);
        putimage(x-40,y-40,sun,XOR_PUT);
        setlinestyle(0,0,1);
        setfillstyle(1,14);
        setcolor(14);
        fillellipse(x,y,25,25);
        delay(250);
        putimage(x+100*cos(i),y+80*sin(i),ear,XOR_PUT);
        delay(250);
        putimage(x+(100*cos(i))+(30*cos(j)),y+(80*sin(i))+(25*sin(j)),moo,XOR_PUT);
        delay(250);
        putimage(x+60*cos(me),y+40*sin(me),mer,XOR_PUT);
        delay(250);
        putimage(x+80*cos(ve),y+60*sin(ve),ven,XOR_PUT);
        delay(250);
        putimage(x+125*cos(ma),y+110*sin(ma),mar,XOR_PUT);
        delay(250);
        putimage(x+165*cos(ju),y+130*sin(ju),jup,XOR_PUT);
        delay(250);
        putimage(x+220*cos(sa),y+170*sin(sa),sat,XOR_PUT);
        delay(250);
        putimage(x+250*cos(ur),y+200*sin(ur),ura,XOR_PUT);
        delay(250);
        putimage(x+280*cos(ne),y+230*sin(ne),nep,XOR_PUT);
        delay(250);
        putimage(x+310*cos(pl),y+250*sin(pl),plu,XOR_PUT);


        putimage(x-40,y-40,sun,XOR_PUT);
        setlinestyle(0,0,1);
        setfillstyle(1,14);
        setcolor(14);
        fillellipse(x,y,25,25);

        putimage(x+100*cos(i),y+80*sin(i),ear,XOR_PUT);
        putimage(x+(100*cos(i))+(30*cos(j)),y+(80*sin(i))+(25*sin(j)),moo,XOR_PUT);
        putimage(x+60*cos(me),y+40*sin(me),mer,XOR_PUT);
        putimage(x+80*cos(ve),y+60*sin(ve),ven,XOR_PUT);
        putimage(x+125*cos(ma),y+110*sin(ma),mar,XOR_PUT);
        putimage(x+165*cos(ju),y+130*sin(ju),jup,XOR_PUT);
        putimage(x+220*cos(sa),y+170*sin(sa),sat,XOR_PUT);
        putimage(x+250*cos(ur),y+200*sin(ur),ura,XOR_PUT);
        putimage(x+280*cos(ne),y+230*sin(ne),nep,XOR_PUT);
        putimage(x+310*cos(pl),y+250*sin(pl),plu,XOR_PUT);

    for(k=0; k<200; k++)
    {
        i=i+0.2;
        j=j+0.7;
        me=me+0.1;
        ve=ve+0.3;
        ma=ma+0.1;
        ju=ju+0.08;
        sa=sa+0.07;
        ur=ur+0.06;
        ne=ne+0.05;
        pl=pl+0.04;
        putpixel(x+100*cos(i)+13,y+80*sin(i)+13,10);
        putpixel(x+(100*cos(i))+(30*cos(j))+5,y+(80*sin(i))+(25*sin(j))+5,1);
        putpixel(x+60*cos(me)+4,y+40*sin(me)+4,4);
        putpixel(x+80*cos(ve)+7,y+60*sin(ve)+7,3);
        putpixel(x+125*cos(ma)+14,y+110*sin(ma)+14,6);
        putpixel(x+165*cos(ju)+18,y+130*sin(ju)+18,7);
        putpixel(x+220*cos(sa)+30+16,y+170*sin(sa)+30+16,9);
        putpixel(x+250*cos(ur)+12,y+200*sin(ur)+12,8);
        putpixel(x+280*cos(ne)+11,y+230*sin(ne)+11,12);
        putpixel(x+310*cos(pl)+8,y+250*sin(pl)+8,1);
    }
    i=0;j=100;me=75;ve=23;ma=105;ju=175;sa=10;ur=300;ne=200;pl=175;
    while(!kbhit())
    {
        i=i+0.2;
        j=j+0.7;
        me=me+0.1;
        ve=ve+0.3;
        ma=ma+0.1;
        ju=ju+0.08;
        sa=sa+0.07;
        ur=ur+0.06;
        ne=ne+0.05;
        pl=pl+0.04;
        putimage(x-40,y-40,sun,XOR_PUT);
        setlinestyle(0,0,1);
        setfillstyle(1,14);
        setcolor(14);
        fillellipse(x,y,25,25);
        putimage(x+100*cos(i),y+80*sin(i),ear,XOR_PUT);
        putimage(x+(100*cos(i))+(30*cos(j)),y+(80*sin(i))+(25*sin(j)),moo,XOR_PUT);
        putimage(x+60*cos(me),y+40*sin(me),mer,XOR_PUT);
        putimage(x+80*cos(ve),y+60*sin(ve),ven,XOR_PUT);
        putimage(x+125*cos(ma),y+110*sin(ma),mar,XOR_PUT);
        putimage(x+165*cos(ju),y+130*sin(ju),jup,XOR_PUT);
        putimage(x+220*cos(sa),y+170*sin(sa),sat,XOR_PUT);
        putimage(x+250*cos(ur),y+200*sin(ur),ura,XOR_PUT);
        putimage(x+280*cos(ne),y+230*sin(ne),nep,XOR_PUT);
        putimage(x+310*cos(pl),y+250*sin(pl),plu,XOR_PUT);
        for(ss=0; ss<7; ss++)
        {
            X=random(10);
            Y=random(10);

            if(X>3)
                sx=sx+5;
            else
                sx=sx-5;

            if(Y>3)
                sy=sy+5;
            else
                sy=sy-5;

            if(ss%2==0)
            {
                putimage(sx,sy,ships,XOR_PUT);
                delay(100);
                putimage(sx,sy,ships,XOR_PUT);
            }
            else
            {
                putimage(sx,sy,ships2,XOR_PUT);
                delay(100);
                putimage(sx,sy,ships2,XOR_PUT);
            }

        }
        if(sx>getmaxx() || sx<=0)
            sx=random(300);

        if(sy>getmaxy() || sy<=0)
            sy=random(300);
        putimage(x+100*cos(i),y+80*sin(i),ear,XOR_PUT);
        putimage(x+(100*cos(i))+(30*cos(j)),y+(80*sin(i))+(25*sin(j)),moo,XOR_PUT);
        putimage(x+60*cos(me),y+40*sin(me),mer,XOR_PUT);
        putimage(x+80*cos(ve),y+60*sin(ve),ven,XOR_PUT);
        putimage(x+125*cos(ma),y+110*sin(ma),mar,XOR_PUT);
        putimage(x+165*cos(ju),y+130*sin(ju),jup,XOR_PUT);
        putimage(x+220*cos(sa),y+170*sin(sa),sat,XOR_PUT);
        putimage(x+250*cos(ur),y+200*sin(ur),ura,XOR_PUT);
        putimage(x+280*cos(ne),y+230*sin(ne),nep,XOR_PUT);
        putimage(x+310*cos(pl),y+250*sin(pl),plu,XOR_PUT);
    }
    getch();
    closegraph();
}
/* Codetechie.blogspot.com */
/* END */

Saturday 15 June 2013

ANALOG CLOCK IN C++

MAKE ANALOG CLOCK IN C/C++ .............

Copy the following code and then Run it in C/C++ IDE's...........!!

/* Program Begins Here */
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>

void main()
{
 struct  time t;
 void drawclock(void);
 void intro(void);
 void sound(void);
 int gdriver=DETECT,gmode;
 initgraph(&gdriver,&gmode,"C:\\tc\\bgi");/* path of bgi*/
 int i,j,k,s,m,h;
 intro();
 settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);
 drawclock();
 gettime(&t);
 if(t.ti_sec>15)
   s=360-((t.ti_sec-15)*6);
 else
   s=90-(t.ti_sec*6);
 if(t.ti_min>15)
   m=360-((t.ti_min-15)*6);
 else
   m=90-(t.ti_min*6);
 if( (t.ti_hour==0)||(t.ti_hour==1)||(t.ti_hour==2)||(t.ti_hour==3))
    h=90-(t.ti_hour*30)-((t.ti_min/12)*6);
 else if((t.ti_hour>=4)&&(t.ti_hour<=12))
   h=360-((t.ti_hour-3)*30)-((t.ti_min/12)*6);
 else if((t.ti_hour>=13)&&(t.ti_hour<=23))
   h=360-((t.ti_hour-15)*30)-((t.ti_min/12)*6);
 else// if(t.ti_hour==12)
   h=90-((t.ti_hour-12)*30)-((t.ti_min/12)*6);
 for(k=0;k<=12;k++)
 {
  if(h==0)
   h=360;
   delay(1000);
   drawclock(); /* Draws clock for every one second */
   for(j=0;j<=60;j++)
   {
     if(m==0)
       m=360;
     setcolor(4);
     sector(320,150,m,m+1,75,75);
     m=m-6;
     delay(1000);
     drawclock();/* Draws clock for every one second */
     for(i=0;i<=60;i++)
     {
     setcolor(4);
     sector(320,150,h,h+3,60,60);
       setcolor(4);
       sector(320,150,m,m+1,75,75);
    if(s==0)
      s=360;
      setcolor(1);
      sector(320,150,s,s+1,80,80);
    sound();
    s=s-6;
    delay(1000);
    drawclock();/* Draws clock for every one second */
      if(kbhit())
    exit(0);
     }
      setcolor(6);
      sector(320,150,h,h+3,60,60);
   }
 }
 getch();
}
////////////////////////////////////////////////////
////////////////////////////////////////////////////
void drawclock()
{
 cleardevice();
 setbkcolor(14);
 setcolor(13);
 setfillstyle(1,15);
 bar(200,30,440,270);
 setcolor(1);
 for(int i=0;i<5;i++){circle(320,150,100+i);}/* Draws circles around clock*/
 setcolor(4);
 for(i=0;i<10;i++){
 rectangle(200+i,30+i,440-i,270-i);}/* Draws hollow bar */
 outtextxy(314,58,"12");
 outtextxy(268,70,"11");
 outtextxy(235,105,"10");
 outtextxy(233,147,"9");
 outtextxy(241,190,"8");
 outtextxy(273,225,"7");
 outtextxy(318,238,"6");
 outtextxy(362,225,"5");
 outtextxy(392,190,"4");
 outtextxy(403,147,"3");
 outtextxy(393,105,"2");
 outtextxy(361,70,"1");
}
/////////////////////////////////////////////////
/////////////////////////////////////////////////
void intro()
{
 int i;
 int u=installuserfont("TSCR.CHR");
 settextstyle(u,0,7);
 outtextxy(200,170,"CLOCK");
 settextstyle(TRIPLEX_FONT, HORIZ_DIR, 1);
 outtextxy(380,400,"Loading..");
 for(i=0;i<510;i++)
 {
   setcolor(15);
   rectangle(50,100,50+i,110);
   delay(5);
 }
 settextstyle(TRIPLEX_FONT, HORIZ_DIR, 1);
 outtextxy(380,400,"Loading....");
 for( i=0;i<510;i++)
 {
   setcolor(4);
   rectangle(50,100,50+i,110);
   delay(5);
 }
 settextstyle(TRIPLEX_FONT, HORIZ_DIR, 1);
 outtextxy(380,400,"Loading........");
 setfillstyle(SOLID_FILL,1);
 settextstyle(TRIPLEX_FONT, HORIZ_DIR, 1);
 outtextxy(380,400,"Loading..........");
 for(i=0;i<510;i++)
 {
   setcolor(15);
   rectangle(50,300,50+i,310);
   delay(5);
 }
 settextstyle(TRIPLEX_FONT, HORIZ_DIR, 1);
 outtextxy(380,400,"Loading............");
 for( i=0;i<510;i++)
 {
   setcolor(2);
   rectangle(50,300,50+i,310);
   delay(5);
 }
 settextstyle(TRIPLEX_FONT, HORIZ_DIR, 1);
 outtextxy(380,400,"Loading..............");
 delay(1000);
}
///////////////////////////////////////////////
///////////////////////////////////////////////
void sound()
{
 sound(2000); /* Sound for every Display */
 delay(100);
 nosound();
}
///////////////////////////////////////////
//////////////////////////////////////
/* Codetechie.blogspot.com */
/* END */

DOWNLOAD CPP

Monday 10 June 2013

Make your own Header Files in C/C++

Step 1 : Open C/C++ IDE or Notepad
Step 2 : Make Your own Function without "MAIN( )"
 Example : SUM.CPP / SUM.TXT
                 int sum(int,int);
                 int sum(int a, int b)
                {
                  return (a+b);
                }
Step 3 : Save the made function with extension ".H" and place the file in INCLUDE folder

Step 4 : Open any C/C++ program , INCLUDE your Header file and use your FUNCTION
           
#include<iostream.h>
 #include<sum.h>
 int main()
{ int a,b,c;
cin>>a>>b;
c=sum(a,b);
cout<<"\nSum of two numbers is "<<c;
return 0;
}