Change value of a variable with out using pointer

Ques: Change value of a variable with out using pointer.
Boundary conditions
can only initalise the variable (variable whose value we want to change)and address operation can only be performed (&variable_name)
cannot use pointers variable.

here is an simple program

 #include<conio.h>
 #include<stdio.h>
 int main(int argc, char *argv[])
 {
 int var=5,vptr;/*virtual pointer vptr*/
 clrscr();
 printf("value before operation:%d",var);
 vptr=(int)&var;
 *(int *)vptr=10;
 printf("value after operation:%d",var);
 getchar();
 return 0;
 }

its simple just use the type conversion trick.
thank you.bye.

how to add two pointers

hye, after a long time im writing a post.
todays topic is how to add two pointers.
its very simple and easy.
my college C teacher told me that you cannot add two pointers but after a while i got an idea how to do it.
before reading further i expect that you know type conversion.

 #include
#include
int main(int argc, char *argv[])
{
int *a,*b;
float c =(float)( (unsigned int)a + (unsigned int)b );/*address are unsigned integers( location are positive )*/
clrscr();
printf("%u + %u = %f",&a,&b,c);
getchar();
return 0;
}

now if your teacher says that you cannot add two pointer,let him see the above code.:)
thank you bye.see you soon.

mouse tail effect in cplusplus

hello everyone.
today i have a great,interesting and easy thing to do with cursor in c++ using graphics.
seen many animation in flash or JavaScript but today i will do something amazing in c++.
many people think that c++ is boring and is only black and white to see.
but today i will use colors to make effect in c++.
there a screenshot of the program.
before reading this post further i would like to suggest you that you read my post on cursor here

download program + source-code
/*
example of cursor tail in turbo c++ 3.0
written by kuldeep dhaka [kuldeepdhaka9@gmail.com]
*/

#include
#include
#include
#include
#include
#include
union REGS in,out;
/*-------------------------------------------------------*/
struct mouse {int x,y,b;};
void mouse_ini();
int mouse_show();
int mouse_hide();
void mouse_get(mouse *);
void mouse_set(int,int);
void mouse_restrict(int,int,int,int);
/*--------------------------------------------------------*/
//function to be added to main for> mouse when application loads
void mouse_ini()
{
if(!mouse_show())
{
printf("error in initializing mouse");
printf("Press any key to halt:");
getch();
exit(1);
}
else mouse_restrict(0,0,getmaxx(),getmaxy());
}
/*--------------------------------------------------------*/
/*to enable cursor or show cursor to user*/
int mouse_show()
{
in.x.ax=1;
return int86(51,&in,&out);
}
/*--------------------------------------------------------*/
/*to disable cursor or hide cursor to user*/
int mouse_hide()
{
in.x.ax=2;
return int86(51,&in,&out);
}
/*--------------------------------------------------------*/
/*get current mouse information
b for> button
x for> x-axis
u for> y-axis
*/

void mouse_get(mouse *mus)
{
in.x.ax=3;
int86(51,&in,&out);
mus->b=out.x.bx;
/*
0:-button not pressed
1:-left button is pressed
2:-right button is pressed
3:-center button is pressed
*/

mus->x=out.x.cx;
mus->y=out.x.dx;
}
/*--------------------------------------------------------*/
/*set new position for> the cursor*/
void mouse_set(int x,int y)
{
in.x.ax=4;
in.x.cx=x;
in.x.dx=y;
int86(51,&in,&out);
}
/*--------------------------------------------------------*/
/*restrict the mouse pointer between the specific positions*/
void mouse_restrict(int x_left,int y_top,int x_right,int y_bottom)
{
in.x.ax=7;
in.x.cx=x_left;
in.x.dx=x_right;
int86(51,&in,&out);
in.x.ax=8;
in.x.cx=y_top;
in.x.dx=y_bottom;
int86(51,&in,&out);
}
void main()
{
/* graphics initalisation*/
int gdriver = DETECT, gmode, errorcode;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "bgi");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
/*---------*/
setbkcolor(7);
mouse mus;
mouse_ini();
/*--------------circle effect----------*/
struct {
int x,y,c;
}tail[5];
int i,rad[]={5,10,15,20,25},max_avail_color=getmaxcolor();
while(!kbhit())
{
mouse_get(&mus);
cleardevice();
mouse_hide();
setcolor(4);
outtextxy(5,5,"move the cursor to see full effect...press any key to exit...");
for>(i=0;i<5;i++)
{
setcolor(tail[i].c);
circle(tail[i].x,tail[i].y,rad[i]);

}
mouse_show();
for>(i=0;i<4;i++)
{
tail[i]=tail[i+1];
}
tail[4].x=mus.x;
tail[4].y=mus.y;
tail[4].c=rand()%max_avail_color;
delay(50);

}
}

thats all for now.good bye folks.

build your own screen saver in c++

today i will show you something interesting,its not hard to code but i am just building it for fun.
today i will code a screensaver in c++ using graphics.
it simple and easy to understand

demo executable+ source-code
#include
#include
#include
#include
#include
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int maxx,maxy,x,y,color,maxcolor;

/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "bgi");

/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
maxcolor=getmaxcolor()+1;
maxx=getmaxx()+1;
maxy=getmaxy()+1;
randomize();
while(!kbhit())
{
color=random(maxcolor);
x=random(maxx);
y=random(maxy);
putpixel(x,y,color);
}
/* clean up */
closegraph();
return 0;
}

please leave comment..
please give me new ideas.you ideas will be appreciated.
soon i will return with a new art.till then,good bye.

build an analog clock in c++ using graphics

today,i am going to show you some thing amazing and adventurous.
you have a clock on your wall.but today im going to show how to make a similar clock in c++ using graphics.
before continuing i would expect that you have a little knowledge of vector algebra.without vector algebra this would be nothing.

please ensure that you know how to run graphics mode and must be able to do simple thing’s in graphics.if you want to learn please go here onecore-Turbo C++ graphics programming

download sourcecode+exe program
/*=======================
require header files
=========================*/

#include
#include
#include
#include
#include
#include
int clock_x;
int clock_y;
int clock_radius;
void hand(int color,int thickness,float angle,int radius);
void main(void)
{
/*======================request auto detection=============================*/
int gdriver = DETECT, gmode, errorcode;
int midx, midy;
/*==================initialize graphics and local variables================*/
initgraph(&gdriver, &gmode, "bgi");
/*==================read result of initialization==========================*/
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
/*====================initializing settings==============================*/
clock_x=getmaxx()/2;
clock_y=getmaxy()/2;
clock_radius=(getmaxx()+getmaxy())/6;
while(!kbhit())
{
/*============clear the device===============*/
cleardevice();
/*===============set backcolor============-*/
setbkcolor(7);
/*=========--print message============--*/
setcolor(4);
settextstyle(0,0,1);
outtextxy(10,10,"press any key to exit....");
/*=========-printing the clock numbers=========*/
float angle=-M_PI_2;
char *num[]={"1","2","3","4","5","6","7","8","9","10","11","12"};
setcolor(1);
for(int i=0;i<12;i++)
{
angle+=M_PI/6;
outtextxy(clock_x+(clock_radius*cos(angle)),clock_y+(clock_radius*sin(angle)),num[i]);
}
/*===============-retrieving time from system===============-*/
struct time t;
gettime(&t);
/*--------print the am/pm---------*/
setcolor(8);
settextstyle(0,0,4);
if(t.ti_hour>12) outtextxy(clock_x-(textwidth("PM")/2),clock_y+textheight("PM"),"PM");
else outtextxy(clock_x-(textwidth("AM")/2),clock_y+textheight("AM"),"AM");
/*=====================printing the hour hand==================*/
angle=(M_PI/6)*(t.ti_hour);
/*hour are in 24 system*/
hand(4,3,angle,clock_radius-50);
/*===-printing the min hand===--*/
angle=(M_PI/30)*(t.ti_min);
hand(5,2,angle,clock_radius-10);
/*===-printing the second hand===--*/
angle=(M_PI/30)*(t.ti_sec);
hand(15,1,angle,clock_radius-10);
/*print tail of second hand*/
hand(15,1,angle-M_PI,20);
/*print head circle of second*/
setlinestyle(SOLID_LINE,SOLID_FILL,1);
setcolor(15);
pieslice(clock_x,clock_y,0,360,3);
sound(700); /*make a 700 hz tone that resembles the tik-tik sound*/
delay(50); /*delay for 50 Milli-seconds*/
nosound(); /*stop tone*/
delay(950); /*delay for 950 milliseconds*/
}
/*=========-clear the device===============--*/
cleardevice();
}
void hand(int color,int thickness,float angle,int radius)
{
/*set the thickness of hand*/
setlinestyle(SOLID_LINE,SOLID_FILL,thickness);
/*set hand color*/
setcolor(color);
/*calculate the x position of the hand using vector algebra*/
int num_x=clock_x+(radius*cos(angle-M_PI_2));
/*calculate the y position of the hand using vector algebra*/
int num_y=clock_y+(radius*sin(angle-M_PI_2));
line(clock_x,clock_y,num_x,num_y);
/*note that M_PI_2 is for making the line 90 degree backward*/
}

that’s all folk,i will return again with a new and exiting project.
please leave comment.report any bugs.

drag and drop a box in c++ using cursor

hello everyone,today im going to show you something you never expected from c++.
this is just a prototype which can be use in many projects to make them more interactive

but,before reading this post please read me as this post use cursor example.without cursor knowledge you will not understand the program.

gif animation of drag and drop
download exe + sourcecode
so the program is like this
there is a while loop running and will only break if any key is pressed using kbhit()

when a user right clicks and the position of the cursor is inside the box then the variable “move” is set to “yes”

and another condition after that check if the variable “move” is set to “yes” or not
if “yes” then the program checks that has the mouse moved or not
if the mouse also moved then it calculates and moves the box accordingly

this is done by taking a difference in position of cursor and box and if cursor has moved the difference is added to the cursor position and set to the box position.

that’s all going on inside the program.

#include
#include
#include
#include
#include
#include
union REGS in,out;
struct mouse{int x,y,b;};
void mouse_ini();
int mouse_show();
int mouse_hide();
void mouse_get(mouse *);
void mouse_set(int,int);
void mouse_restrict(int,int,int,int);
void main()
{
/*---graphics initialization
request auto detection */
int gdriver=DETECT, gmode, errorcode;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "path to bgi folder on computer");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error-occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
mouse_ini();
/*-actual program from here--*/
setbkcolor(56);
setfillstyle(SOLID_FILL,2);
setcolor(63);
/*setting for initial position and width,height*/
int x=50,y=50,w=50,h=50,xdiff,ydiff,tmpx,tmpy;
mouse_hide();
bar(x,y,x + w,y + h);
mouse_show();
char move;
mouse mus;
do{
mouse_get(&mus);
if(move == 'n' && mus.b == 1 && mus.x > x && mus.x y && mus.y < y + h)
{
xdiff = mus.x - x;
ydiff = mus.y - y;
move = 'y';
}
else if(mus.b == 0) move = 'n';
mouse_get(&mus);
if(move == 'y')
{
tmpx = x;
tmpy = y;
x = mus.x - xdiff;
y = mus.y - ydiff;
if(tmpx != x || tmpy != y)
{
mouse_hide();
cleardevice();
bar(x,y,x + w,y + h);
mouse_show();
}
}
else outtextxy(10,10,"click the rectangle and drag it,press any key from keyboard to exit");
}while(!kbhit()); //while keyboard is not hit
}
/*to initialize the mouse when program starts*/
void mouse_ini()
{
if(!mouse_show())
{
printf("error in initializing mouse");
printf("Press any key to halt:");
getch();
exit(1);
}
else mouse_restrict(0,0,getmaxx(),getmaxy());
}
/*to enable cursor or show cursor to user*/
int mouse_show()
{
in.x.ax=1;
return int86(51,&in,&out);
}
/*to disable cursor or hide cursor to user*/
int mouse_hide()
{
in.x.ax=2;
return int86(51,&in,&out);
}
/*get current mouse information
b for button
x for x-axis
u for y-axis
*/
void mouse_get(mouse *mus)
{
in.x.ax=3;
int86(51,&in,&out);
mus->b=out.x.bx;
mus->x=out.x.cx;
mus->y=out.x.dx;
}
/*when you want to get the mouse position and button use this method
mouse mus;
mouse_get(&mus); */
/*set new position for the cursor*/
void mouse_set(int x,int y)
{
in.x.ax=4;
in.x.cx=x;
in.x.dx=y;
int86(51,&in,&out);
}
/*restrict the mouse pointer between the specific positions*/
void mouse_restrict(int x_left,int y_top,int x_right,int y_bottom)
{
in.x.ax=7;
in.x.cx=x_left;
in.x.dx=x_right;
int86(51,&in,&out);
in.x.ax=8;
in.x.cx=y_top;
in.x.dx=y_bottom;
int86(51,&in,&out);
}