Tuesday, 1 November 2011

Find us on Facebook





Monday, 31 October 2011

Learn C++ Graphics





C++ Graphics

Graphics are used in C++ and C programming to make a user friendly software.
Here I will discuss all graphics that I know well. S let's begin

Graphics  in C and C++ languages:
                                                        Let's start with graphics header file

#include<graphics.h>


                                       
Use cleardevice();  instead of clrscr();                                


void main()
 { 
    cleardevice();

int gd=DETECT,gm;                 //gd mean graphics detection 
                                                  //gm mean graphics mode

initgraphics(&gd, &gm,"c:\\tc\\bgi");
      
/*Above 2 lines are used to get graphics supported files thst may be in c or d derive where you have installed turbo c++ 3.0.
You just have to memorize above 4 lines commands then graphics will become much easy for you.*/

//To draw a circle use following command

 circle(x-coordinate,y-coordinate,radius);
for example
circle(250,150,10);

this command will draw circle on 250 and 150 coordinate.
Our computer screen contain 800 columns and 250 rows so adjust according to requirement.

Now to draw rectangle, write

rectangle(x1 coordinate, y1 coordinate, x2 coordinate, y2 coordinate);

for example:
rectangle(120,250,450,100);
similarly 
pyramid(120,250,450,100);
and 
line(120,250,450,100);
setfillstyle(SOLIDFILL,XFILL); //to fill rectangle r circle with x's 

Set color and text styles:

                                       When we use a colour in our program then we use upper case letters for example, RED, BLUE.
We can also colour code for this purpose that's start from 0 and end at 15.

Now to change your background colour write
setbkcolor(RED);
    or
setbkcolor(3);

To change text or shapes colours use
setcolor(RED);
  or
setcolor(2);  //there can be any number instead of 2

To change text style:

settextstyle(horizontal or vertical, style, size);
settextstyle(1,5,8);
    
and then
outtextxy(x-coordinate,y-coordinate,"any text");
outtextxy(25,100,"My name is waqas");

        
and at the end 
closegraph();

Now let's review the whole commands:

#include<graphics.h>

void main()
{
   cleardevice();

int gd=DETECT,gm;
initgraphics(&gd, &gm,"c:\\tc\\bgi");

setbkcolor(ORANGE);
setcolor(RED);

rectangle(25,45,100,150);                                      
line((25,45,100,150);                                      
pyramid((25,45,100,150);                                      

circle(25,100,8);

settextstyle(2,5,10);
outtextxy(100,25,"Welcome");

closegraph();

getch();
}
                                        Thanks

For more graphics exemples and projects Click Here

Written by M. Waqas
For more C and C++ contents Click here

What is C language?




C language is a computer low high level language.This language is used to develop several software.And also this language is called the mother of all other languages.C and C++ are same but there is little difference in them.And now several version are available.But when you will be expert in this language and able to use all operation of C language than you can use any language the difference will be only its syntax.
Compiler is used in C language to translate the source code into machine code that generate the result and show to the user.The most important and simple operations are following.
1. simple conditioin
2.Use of IF and Else
3. Use of  Loop
4.Use of Array
5. Use of Function
6. Use of String
7.Use of Stream
8.Use of pointer
9. Use of Structure
10. Use of Graphices


C++ language exercises and examples

Friends counter




best online casino, CHATBOX, GAMBLING IN AUSTRALIA, WILL HILL CASINO, Online casino in South Africa

Sunday, 30 October 2011

Table writer C++ code

Table writer C++ code


#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<stdio.h>
#include<time.h>




  int xf1=170,xf2=190,chf1=0,chf2=0,ex1=0,ex2=0;


  void tblshp();


  void main()
  {
  int gdriver = DETECT, gmode, errorcode;
  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<<tn<<"   *   "<<i<<"   =   "<<tn*i<<endl<<endl;
   }


  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,xf1,430,xf2+300);
  settextstyle(4,0,16);
  outtextxy(30,180,"T      T");




  }




Temperature converter c++ code






Temperature converter c++ code 


#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<stdio.h>
#include<time.h>

   int xf1=200,xf2=230,chf1=0,chf2=0,ex1=0,ex2=0;

  void calshp();

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

 clrscr();
 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,xf1+chf1,430-ex2,xf2+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<<temp<<" F";
   gotoxy(40,10);
   cout<<cel<<" C";
    break;

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

  break;

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

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

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


  break;

  case 6:
cel=273-temp;
f=9*(cel+32)/5;
gotoxy(23,10);
    cout<<temp<<" K";
    gotoxy(40,10);
    cout<<f<<" F";
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,xf1,430,xf2);
  rectangle(160,xf1+30,430,xf2+30);
  rectangle(160,xf1+60,430,xf2+60);
  rectangle(160,xf1+90,430,xf2+90);
  rectangle(160,xf1+120,430,xf2+120);
  rectangle(160,xf1+150,430,xf2+150);
  rectangle(230,xf1+180,350,xf2+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");


  }