Showing posts with label learn c. Show all posts
Showing posts with label learn c. Show all posts

Saturday, 17 December 2011

Graphical Table writer with C & C++ graphics


Friends this is a code for graphical calculator. You can run this c++ code with your compiler and enjoy it. This is a so simple and beautiful project code for you. So, Run it and give me your feedbacks. Thanks

#include
#include
#include
#include
#include
#include
#include

 ///////////////////////
  int xft1=170,xft2=190,chf1=0,chf2=0,ex1=0,ex2=0;

  void tblshp();

  void main()
  {
  int gdriver = DETECT, gmode;
  initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
  int tn,ts,te,i,ps=0;
  char ch;
  tblshp();
 gotoxy(23,9);
 cin>>tn;
 gotoxy(37,9);
 cin>>ts;
 gotoxy(50,9);
 cin>>te;
    for(i=ts; i<=te; i++)
 {  ps++;
   gotoxy(29,11+ps);
   cout<
   }

  getche();

  }

void tblshp()
{

  setcolor(RED);
  settextstyle(4,0,6);
  outtextxy(160,4,"T A B L E");
  rectangle(90,10,530,70);
/////////////////////////////////////////////////////////////////////
  settextstyle(0,0,0);
  rectangle(130,120,460,155);
  rectangle(130,120,240,155);
  rectangle(240,120,350,155);
  outtextxy(145,110,"Table no");
  outtextxy(255,110,"First limit");
  outtextxy(370,110,"Last limit");
  rectangle(180,xft1,430,xft2+300);
  settextstyle(4,0,16);
  outtextxy(30,180,"T      T");

  }



Friday, 16 December 2011

Graphical Temperature Converter C & C++ code

Friends here I am introducing a new code for temperature converter. This is a graphical converter that you can use and run with your converter. Hope you like this thanks.   



#include
#include
#include
#include
#include
#include
#include
   //////////////////////
   int xfm1=200,xfm2=230,chf1=0,chf2=0,ex1=0,ex2=0;

  void calshp();

  void main()
  {
  int gdriver = DETECT, gmode;
  initgraph(&gdriver, &gmode, "c:\\tc\\bgi");

 char ch,mv;
 float cel,f,k,temp;
 calshp();

/////////////////////////////////////////////////////////////////////////////
gotoxy(23,10);
cin>>temp;


    do
{   calshp();

if(mv==72)
   {   chf1-=30;
chf2-=30;
}
   if(mv==80)

    {chf1+=30;
     chf2+=30;
    }
    if(chf1>180)
    {
      chf1=0;
      chf2=0;
      }
    if(chf1<0)
    {  chf1=180,chf2=180;}

    if(chf1==180)
    {ex1=70,ex2=80;}
    if(chf1!=180)
    {ex1=0,ex2=0;}

  setcolor(BLUE);
  rectangle(160+ex1,xfm1+chf1,430-ex2,xfm2+chf2);
     mv=getche();
     }
     while(mv!=13);

if(chf1==0)
{
ch=1; }
else if(chf1==30)
{
ch=2;
}
else if(chf1==60)
{
ch=3;
}
else if(chf1==90)
{
ch=4;
}
else if(chf1==120)
{
ch=5;
}
else if(chf1==150)
{
ch=6;
}

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

   switch(ch)
   {

  case 1:
    cel=5*(temp-32)/9;
    gotoxy(23,10);
    cout<
   gotoxy(40,10);
   cout<
    break;

  case 2:
    f=9*(temp+32)/5;
    gotoxy(23,10);
    cout<
    gotoxy(40,10);
    cout<

  break;

  case 3:
    k=temp+273;
    gotoxy(23,10);
    cout<
    gotoxy(40,10);
    cout<
  break;

  case 4:
    cel=273-temp;
    gotoxy(23,10);
    cout<
    gotoxy(40,10);
    cout<
  break;

  case 5:
    cel=5*(temp-32)/9;
    k=cel+273;
    gotoxy(23,10);
    cout<
    gotoxy(40,10);
    cout<


  break;

  case 6:
cel=273-temp;
f=9*(cel+32)/5;
gotoxy(23,10);
    cout<
    gotoxy(40,10);
    cout<
break;

 }



 getche();
 }



void calshp()
{

  setcolor(RED);
  settextstyle(4,0,6);
  outtextxy(90,4,"Temprature Converter");
  rectangle(70,10,580,70);
/////////////////////////////////////////////////////////////////////
  settextstyle(0,0,0);
  rectangle(130,135,460,165);
  rectangle(130,135,290,165);
  outtextxy(180,125,"Input");
  outtextxy(340,125,"Output");
  rectangle(160,xfm1,430,xfm2);
  rectangle(160,xfm1+30,430,xfm2+30);
  rectangle(160,xfm1+60,430,xfm2+60);
  rectangle(160,xfm1+90,430,xfm2+90);
  rectangle(160,xfm1+120,430,xfm2+120);
  rectangle(160,xfm1+150,430,xfm2+150);
  rectangle(230,xfm1+180,350,xfm2+180);
  outtextxy(190,210,"Fahrenheit   To   Celsius");
  outtextxy(190,240,"Celsius   To   Fahrenheit");
  outtextxy(190,270,"Celsius   To   Kalvin");
  outtextxy(190,300,"Kalvin    To   Celsius");
  outtextxy(190,330," Fahrenheit  To  Kalvin");
  outtextxy(190,360," Kalvin  To  Fahrenheit");
  outtextxy(270,390,"Exit");
  setcolor(BLUE);
  rectangle(10,425 ,620,477);
  settextstyle(0,0,1);
  outtextxy(16,430,"NAME: Muhammad Waqas");
  outtextxy(16,445,"Roll # 9275");
  outtextxy(16,460,"Class : BCs-A(2011 - 2014)");
  outtextxy(400,430,"S u b m e t t e d  T o");
  outtextxy(380,460,"S i r .  U m e r  H a y a t");
  settextstyle(4,0,16);
  outtextxy(30,180,"T      T");
  }


More C++ and C codes:


C and C++ classes

Hope you like theses codes. Thanks





Thursday, 15 December 2011

How to make a graphical stopwatch with C & C++ graphics

How to make a graphical stopwatch with C & C++ graphics
You can make your own stopwatch if you know about C & C++ language. Following is an easy and simple stopwatc code and some links. You can select one of them and run it into your compiler.






#include
#include
#include
#include
#include
#include
#include

  void stpshp();

  void main()
  {clrscr();
  int gdriver = DETECT, gmode;
  initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
  stpshp();
  int h=1,mm=2,ss=3,ms=4;


      for(h=0; h<60; h++)
      {
for(mm=0;mm<60; mm+=1)
{ for(ss=0; ss<60; ss+=1)
  { for(ms=0; ms<60; ms+=1)
     {
      gotoxy(22,9);
      cout<
      gotoxy(37,9);
      cout<
      gotoxy(51,9);
      cout<
      gotoxy(37,11);
      cout<
      delay(16.9);
      if(kbhit())
      {break;}
    }
      if(kbhit())
      {break;}
     }
if(kbhit())
      {break;}
     }
if(kbhit())
      {break; }
     }
 getche();
 }

void stpshp()
 {
  setcolor(RED);
  settextstyle(4,0,6);
  outtextxy(160,4,"Stop Watch");
  rectangle(90,10,530,70);
/////////////////////////////////////////////////////////////////////
  settextstyle(0,0,0);
  rectangle(130,120,460,155);
  rectangle(130,120,240,155);
  rectangle(240,120,350,155);
  rectangle(240,155,350,190);

  outtextxy(145,110,"Hours");
  outtextxy(255,110,"Minuts");
  outtextxy(370,110,"Seconds");
  setcolor(RED);
  rectangle(10,425 ,620,477);
  settextstyle(0,0,1);
  outtextxy(16,430,"NAME: Muhammad Waqas");
  outtextxy(16,445,"Roll # 9275");
  outtextxy(16,460,"Class : BCs-A(2011 - 2014)");
  outtextxy(400,430,"S u b m e t t e d  T o");
  outtextxy(380,460,"S i r .  U m e r  H a y a t");
  settextstyle(4,0,16);
  outtextxy(30,90,"V      V");

   }





Hope you like it. Thanks cpptechnology will upload more easy and interesting  C & C++ programs for you. So keep visiting and learning.

Wednesday, 23 November 2011

Sound and Delay Functions in C & C++

Sound functions is used to make a sound or a sequence of sound in program. For example a piano C++ project use different sequences to get different sounds. Let start now:

#include<dos.h>
void main()
{

sound(any number);  //any sound number or name
sound(1200);

Different numbers contain different sounds and always remember that there should be a nosound();
function that end the sound. Use delay function to increase or decrease the timing of the sound.
delay(1000); // 1000=1 second

Review:

#include<dos.h>

void main()
{
clrscr();
sound(250);
delay(9000); // 9 second
nosound();

getche();
}

Hope you like this post. Thanks

Link:Sound in C++