Source code of Digital clock

Discussion in 'C' started by skp819, Dec 16, 2008.

  1. skp819

    skp819 New Member

    Joined:
    Dec 8, 2008
    Messages:
    89
    Likes Received:
    3
    Trophy Points:
    0
    Hello friends
    I am harish kumar.
    I am going to post the source code of Digital clock.
    Give your views about that.
    Code:
    #include<stdio.h>
    #include<process.h>
    #include<iostream.h>
    #include<dos.h>
    #include<graphics.h>
    #include<conio.h>
    #include<math.h>
    void draw()
    {
    setbkcolor(0);
    setlinestyle(0,0,0);
    setcolor(9);
    circle(320,240,3);
    setcolor(11);
    setfillstyle(6,13);
    circle(320,240,150);
    circle(320,240,165);
    floodfill(156,242,11);
    settextstyle(2,0,5);
    setcolor(14);
    outtextxy(314,98,"12");
    outtextxy(384,114,"1");
    outtextxy(434,163,"2");
    outtextxy(454,230,"3");
    outtextxy(317,369,"6");
    outtextxy(177,230,"9");
    outtextxy(436,300,"4");
    outtextxy(195,302,"8");
    outtextxy(195,163,"10");
    outtextxy(244,112,"11");
    outtextxy(388,353,"5");
    outtextxy(248,353,"7");
    }
    main()
    {
    
    int gd=0,gm;
    initgraph(&gd,&gm,"c:\tc\bgi");
    
    draw();
    //line(320,240,320,130);
    //line(320,240,320,150);
    //getch();
    float s;
    float df;
    //s=282*M_PI/180;
    //float angle=4.712389;
    //float an=4.712389;
    float anf=4.712389;
    
    //float angle=0;
    int x,y;
    int q,w;
    int ta,d;
    
    float as;
    as=6*M_PI/180;
    
    int c2=0;
    int count=0;
    struct  time t;
    gettime(&t);
    float angle=4.712389+t.ti_sec*.1047198;
    float an=4.712389+t.ti_min*.1047198;
    while(!kbhit())
    {
    draw();
    gettime(&t);
    gotoxy(5,5);
    angle=4.712389+t.ti_sec*.1047198;
    an=4.712389+t.ti_min*.1047198;
    anf=4.712389+t.ti_hour*5*.1047198 ;
    if(t.ti_min>=12&&t.ti_min<24)
    {
    anf=anf+2*.1047198;
    }
    if(t.ti_min>=24&&t.ti_min<36)
    {
    anf=anf+(3*.1047198);
    }
    if(t.ti_min>=36&&t.ti_min<48)
    {
    anf=anf+(4*.1047198);
    }
    if(t.ti_min>=48&&t.ti_min<60)
    {
    anf=anf+(5*.1047198);
    }
    
    
    gotoxy(2,2);
    printf("The current time is: %d: %d: %d
    ",
           t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
    
    cout<<"   ";
    setlinestyle(0,0,0);
    setcolor(0);
    line(320,240,x,y);
    line(320,240,q,w);
    line(320,240,ta,d);
    
    x=320+140*cos(angle);
    y=240+140*sin(angle);
    q=320+122*cos(an);
    w=240+122*sin(an);
    ta=320+86*cos(anf);
    d=240+86*sin(anf);
    setcolor(10);
    setlinestyle(0,0,0);
    line(320,240,x,y);
    setlinestyle(0,0,2);
    setcolor(9);
    line(320,240,q,w);
    setlinestyle(0,0,3);
    setcolor(4);
    line(320,240,ta,d);
    angle+=.1047198;
    delay(1000);
    count++;
    
    /*if(c2==12)
    {
    setlinestyle(0,0,3);
    c2=0;
    anf+=.1047198;
    } */
    setcolor(count);
    outtextxy(370,440,"MADE BY :- AAYUSH AWASTHI");
    outtextxy(390,460,"BCA IIIrd YEAR");
    
    }
    
    
    getch();
    }
     
    Last edited by a moderator: Dec 16, 2008
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    You've been around plenty long enough to use code blocks. Look them up, and start using them. It's not fair on shabbir to keep expecting him to add them for you.

    Also consider (a) posting it as an article, (b) commenting the code and (c) explaining how it works.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    I would add one more thing. Indent the code so that it can go into Articles as well.
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Yeah but probably the site stripped the indents. cf:

    void test()
    {
    int x=1;
    if (x=1)
    printf("x=1\n");
    }

    Code:
    void test()
    {
    	int x=1;
    	if (x=1)
    		printf("x=1\n");
    }
    
     
  5. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Enhancement suggestion for the site: can it spot more than a couple of lines of code and (a) reject the code if a code block isn't used or (b) warn the user with details of how to do it properly?

    In the above post I Ctrl-V'd exactly the same stuff, one in a code block and one not.
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Yeah but only when it does not have code blocks. If you edit the post you would see the original one and then adding the code would restore your indents.
     
  7. skp819

    skp819 New Member

    Joined:
    Dec 8, 2008
    Messages:
    89
    Likes Received:
    3
    Trophy Points:
    0
    thanks for the reply
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice