Program To Overlead Operator, Using Two Data Members, And Member Functions.




class distance
{
float point;
public:
distance()
{
point=0.0;
}
distance(float p)
{
point =p;
}

distance operator+(distance x)
{
distance temp;
temp.point=point+x.point;
return temp;
}

distance operator-(distance x)
{
distance temp;
temp.point=point-x.point;
if(temp.point<0)
return distance(0);
else
return temp;
}
void show(){
cout<}
};

void main()
{
clrscr();
distance d1(5),d2(2),d3;
d3= d2.operator +(d1);
d3.show();

d3= d2.operator -(d1);
d3.show();
getch();
}

Program to create Analog Clock in c




# include
# include
# include
# include
# include <.h>
# include

void frame();
void star_in(int, int, int, int, int, float, float);
void line_at_angle(int, float, int);
void beep(int, int);
void clear (int, int, int, int, int);

void main()
{
int gdriver=DETECT,gmode,errorcode;
initgraph(&gdriver,&gmode,"c:\tc\bgi");
errorcode=graphresult();
if(errorcode!=grOk)
{
printf("Opps!! Graphics error %s",grapherrormsg(errorcode));
printf("press any key to halt.");
exit(1);
}
struct time t;
gettime(&t);
int key,k=0;
int midx,midy;
float hour;
midx=getmaxx()/2;
midy=getmaxy()/2;

frame();

while(1)
{
if(kbhit())
{
key=getch();
if(key==27)
break;
}
gettime(&t);

if(t.ti_hour>=12)
hour=t.ti_hour-12;

float ang_sec=t.ti_sec*6;
float ang_min=(t.ti_min*6)+(ang_sec/60);
float ang_hour=(hour*30)+(ang_min/12);

setcolor(4);
setfillstyle(1,9);
line_at_angle(150,ang_min,2); //min
setcolor(12);
setfillstyle(1,4);
line_at_angle(130,ang_hour,3); //hour
setcolor(14);
line_at_angle(170,ang_sec,1); //sec
line_at_angle(20,180+ang_sec,1); //sec

setfillstyle(1,4);
setcolor(13);
// fillellipse(midx,midy,2,2);
star_in(midx, midy+1, 6, 2, 4, 0, 0);
char tim[5];
struct time t;
int t_sec,t_min;
int x=520,y=460;
gettime(&t);
if(t.ti_hour>12)
{
outtextxy(x+80,y,"PM");
sprintf(tim,"%d",t.ti_hour-12);
}
else
{
outtextxy(x+80,y,"AM");
sprintf(tim,"%d",t.ti_hour);
}
outtextxy(x,y,tim);
outtextxy(x+16,y,":");
outtextxy(x+42,y,":");
sprintf(tim,"%d",t.ti_min);
outtextxy(x+26,y,tim);
sprintf(tim,"%d",t.ti_sec);
outtextxy(x+50,y,tim);

k++;
if(k==10)
{
k=0;
beep(100,50);
}
else
delay(100);
t_sec = t.ti_sec;
t_min = t.ti_min;
clear(x+50,y,x+70,y+8,0);
if(t_sec >= 59)
clear(x+26,y,x+46,y+8,0);
if(t_min >= 59)
clear(x,y,x+20,y+8,0);

setcolor(0);
setfillstyle(1,0);
line_at_angle(130,ang_hour-6,1);
line_at_angle(150,ang_min-4,1);
line_at_angle(170,ang_sec,1);
line_at_angle(20,180+ang_sec,1);
ang_sec++;
}

closegraph();
}
void frame()
{
int midx,midy;
float angle=0;
float x,y;
midx=getmaxx()/2;
midy=getmaxy()/2;

setlinestyle(1,1,3);
setcolor(2);
circle(midx,midy,223);
setcolor(15);
circle(midx,midy,220);
setcolor(12);
circle(midx,midy,217);
setlinestyle(1,1,3);
setfillstyle(1,2);
setcolor(4);
for(int i=0;i<=60;i++)
{
x=cos((angle/180)*M_PI)*190;
y=sin((angle/180)*M_PI)*190;
if(int(angle)%30!=0)
circle(midx+x,midy+y,2);
angle+=6;
}
angle=0;
setfillstyle(1,4);
setlinestyle(0,1,2);
for(i=0;i<12;i++)
{
setcolor(13);
x=cos((angle/180)*M_PI)*190;
y=sin((angle/180)*M_PI)*190;
if(i%3==0)
{
// fillellipse(midx+x,midy+y,6,6);
setcolor(10);
star_in(midx+x, midy+y, 12, 6, 5, 18, 0);
setcolor(14);
star_in(midx+x, midy+y, 6, 3, 5, 18, 0);
}
else
// fillellipse(midx+x,midy+y,4,4);
star_in(midx+x, midy+y, 8, 3, 5, 18, 0);
angle+=30;
}
}

void line_at_angle(int radius, float angle, int flag)
{
float x,y,x1,y1,x2,y2,x3,y3;
int midx,midy;
angle-=90;

midx=getmaxx()/2;
midy=getmaxy()/2;

x=cos((angle/180)*M_PI)*radius;
y=sin((angle/180)*M_PI)*radius;

setlinestyle(0,1,3);
if(flag==1)
line(midx,midy,midx+x,midy+y);
if(flag==2)
{
setlinestyle(0,1,1);
x2=cos(((angle+3)/180)*M_PI)*(radius-25);
y2=sin(((angle+3)/180)*M_PI)*(radius-25);
x3=cos(((angle-3)/180)*M_PI)*(radius-25);
y3=sin(((angle-3)/180)*M_PI)*(radius-25);
int
poly1[10]={midx,midy,midx+x2,midy+y2,midx+x,midy+y,midx+x3,midy+y3,midx,mi
dy};
fillpoly(5,poly1);
setcolor(0);
x2=cos(((angle)/180)*M_PI)*(radius+1);
y2=sin(((angle)/180)*M_PI)*(radius+1);
x3=cos(((angle-4)/180)*M_PI)*(radius-25);
y3=sin(((angle-4)/180)*M_PI)*(radius-25);
line(midx+x2,midy+y2,midx+x3,midy+y3);
line(midx+x,midy+y,midx+x3,midy+y3);
}
else if(flag==3)
{
setlinestyle(0,1,1);
x2=cos(((angle+5)/180)*M_PI)*(radius-30);
y2=sin(((angle+5)/180)*M_PI)*(radius-30);
x3=cos(((angle-5)/180)*M_PI)*(radius-30);
y3=sin(((angle-5)/180)*M_PI)*(radius-30);
int
poly1[10]={midx,midy,midx+x2,midy+y2,midx+x,midy+y,midx+x3,midy+y3,midx,mi
dy};
fillpoly(5,poly1);
setcolor(0);
x2=cos(((angle)/180)*M_PI)*(radius+1);
y2=sin(((angle)/180)*M_PI)*(radius+1);
x3=cos(((angle-6)/180)*M_PI)*(radius-30);
y3=sin(((angle-6)/180)*M_PI)*(radius-30);
line(midx+x2,midy+y2,midx+x3,midy+y3);
line(midx+x,midy+y,midx+x3,midy+y3);
}
}
void beep(int fre,int wait)
{
sound(fre);
delay(wait);
nosound();
}
void star_in(int x, int y, int r1, int r2, int points, float
angle_intial1, float offset)
{
float angle, theta;
int number = 0;
float xi1, yi1, xf1, yf1, xc1, yc1;
float xi2, yi2, xf2, yf2, xc2, yc2;
float angle_intial2;
float xt,yt;

theta = 360 / points;
angle_intial2 = angle_intial1 + (theta / 2) + offset;
angle_intial1 = (angle_intial1 * M_PI) / 180;
angle_intial2 = (angle_intial2 * M_PI) / 180;

angle = theta;

xc1 = x + (r1 * cos(angle_intial1)),
yc1 = y - (r1 * sin(angle_intial1));
xc2 = x + (r2 * cos(angle_intial2)),
yc2 = y - (r2 * sin(angle_intial2));

xi1 = xc1,
yi1 = yc1;
xi2 = xc2,
yi2 = yc2;

xt = xc1;
yt = yc1;

while(number <= points + 1)
{
angle = (angle * M_PI) / 180;

xc1 = xc1 - x;
yc1 = yc1 - y;
xc2 = xc2 - x;
yc2 = yc2 - y;

xf1 = ( xc1 * cos(angle) ) - ( yc1 * sin( angle ) );
yf1 = ( xc1 * sin(angle) ) + ( yc1 * cos( angle ) );
xf2 = ( xc2 * cos(angle) ) - ( yc2 * sin( angle ) );
yf2 = ( xc2 * sin(angle) ) + ( yc2 * cos( angle ) );

xc1 = xc1 + x;
yc1 = yc1 + y;
xc2 = xc2 + x;
yc2 = yc2 + y;

xf1 = xf1 + x;
yf1 = yf1 + y;
xf2 = xf2 + x;
yf2 = yf2 + y;

if(number != points + 1)
line(xi1, yi1, xi2, yi2);
line(xt, yt, xi2, yi2);

xt = xi1;
yt = yi1;

xi1 = xf1,
yi1 = yf1;
xi2 = xf2,
yi2 = yf2;

number++;
angle = theta * number;
}
}

void clear(int x1, int y1, int x2, int y2, int col)
{
int x,y;
for(x=x1;x<=x2;x++)
for(y=y1;y<=y2;y++)
putpixel(x,y,col);
}

xstrcmp() - compares strings using DOS wildcards ** 'mask' may contain '*' and '?'


int xstrcmp (char *mask, char *s)
{
while (*mask)
{
switch (*mask)
{
case '?':
if (!*s)
return (0);
s++;
mask++;
break;

case '*':
while (*mask == '*')
mask++;
if (!*mask)
return ( 1 );
if (*mask == '?')
break;
while (*s != *mask)
{
if (!*s)
return (0);
s++;
}
s++;
mask++;
break;

default:
if (*s != *mask)
return (0);
s++;
mask++;
}
}

if (!*s && *mask)
return (0);
return ( 1 );
}

#ifdef TEST

#include
void main(int argc, char *argv[])
{
if (3 != argc)
{
puts("Usage: XSTRCMP string_1 string_2");
return;
}
printf("xstrcmp(\"%s\", \"%s\") returned %d\n", argv[1], argv[2],
xstrcmp(argv[1], argv[2]));
}

#endif /* TEST */

Program to Infix To Prefix Conversion in C


#include
#include
#include
#define MAX 15
#define true 1
#define false 0


typedef struct
{
char data[MAX];
char top;
}STK;

void input(char str[]);
void intopre(char str1[],char pre[]);
void intopost(char str1[],char post[]);
int isoperand(char sym);
int prcd(char sym);
void push(STK *s1,char elem);
int pop(STK *s1);
int empty(STK *s2);
int full(STK *s2);
void dis(char str[]);

void main()
{
STK s;
int cs,ans;
char str[MAX],pre[MAX],post[MAX];
clrscr();
do /*Using Do-while Loop*/
{
clrscr();
printf("
-----Program for Expressions-----");
printf("
Input The String:");
printf("
MENU:
");
printf("1.Infix to Prefix
");
printf("2.Infix to Postfix");
printf("
3.Exit");
cs=getche();

switch(cs) /*Using Switch Case*/
{
case 1:
intopre(str,pre);
break;
case 2:
intopost(str,post);
break;
case 3:
break;
default:
printf("
Enter a Valid Choise!"); /*Default Case*/
break;
}
printf("
Do you wish to Continue?(y/n)");
ans=getche();
}while(ans=='y'||ans=='Y'); /*Condition for Do-while loop*/

getch();
}

/**************************************************/
/*To Input String*/
/**************************************************/
void input(char str)
{
printf("Enter the Infix String:");
scanf("%s",str);
}

/**************************************************/
/*To Covert Infix To Prefix*/
/**************************************************/
void intopre(STK s1,char str1[],char pre[])
{
int len,flag;
len=strlen(str1);
int check=0,cnt=len-1,pos=0;
char elem;

while(cnt>=0) /*while condition*/
{
flag=0;
if(isoperand(str1[cnt])) /*Checking for Operand*/
{
printf("%c",str1[cnt]);
cnt--;
pos++;
}
else
{
check=prcd(str1[cnt]);
while(check==false)
{
pre[pos]=str1[cnt];
flag=1;
pos++;
cnt--;
}
if(flag==0)
{
elem=pop(&s1);
printf("%c",elem);
}
}

}
}

/**************************************************/
/*To Convert Infix To Postfix*/
/**************************************************/
void intopost(STK s1,char str1[],char post[])
{
int len;
len=strlen(str1);
int check=0,cnt=len-1,pos=0;

}

/**************************************************/
/*To Check For Operand*/
/**************************************************/
int isoperand(char sym)
{
if('A'return(true);
return(false);
}

/**************************************************/
/*To Check The Precedence*/
/**************************************************/
int prcd(char sym)
{

}

/**************************************************/
/*To Display String*/
/**************************************************/
void dis(char str[])
{


}

/******************************************/
/*Push Function Definition*/
/******************************************/
void push(STK *s1,char elem)
{
if(!full(s1))
{
s1->top++; /*Incrementing top*/
s1->data[s1->top]=elem; /*Storing element*/
}
else
printf("
Stack is Full!");
}

/******************************************/
/*Full Function Definition*/
/******************************************/
int full(STK *s2)
{
if(s2->top==MAX) /*Condition for Full*/
return(true);
return(false);
}

/******************************************/
/*Pop Function Definition*/
/******************************************/
int pop(STK *s1)
{
char elem;
if(!empty(s1))
{
elem=s1->data[s1->top]; /*Storing top stack element in elem*/
s1->top--; /*Decrementing top*/
return(elem);
}
return(false);
}

/******************************************/
/*Empty Function Definition*/
/******************************************/
int empty(STK *s2)
{
if(s2->top==-1) /*Condition For Empty*/
return(true);
return(false);
}

Program to Blinking Lights on Keyboard in c


#include
void interrupt mytimer();
void interrupt (*prev)();
int run=0,lt=0,ticks=0;
char far *mode;
int temp;
void main()
{
mode=(char far*)0x417;
prev=getvect(0x8);
setvect(0x8,mytimer);
keep(0,100);
getch();
}
void interrupt mytimer()
{
if(run==0)
{
ticks++;
if(ticks==5)
{
ticks=0;
run=1;
lt++;
if(lt==1)
{
temp=*mode;
temp=temp&0x8f;
temp=temp|0x40;
*mode=temp;
}
else if(lt==2)
{
temp=*mode;
temp=temp&0x8f;
temp=temp|0x20;
*mode=temp;
}
else if(lt==3)
{
temp=*mode;
temp=temp&0x8f;
temp=temp|0x10;
*mode=temp;
lt=0;
}
}
run=0;
}
(*prev)();
}