Sunday 12 May 2013

School Management System


#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
int i=1,j=1;
long start_std_id=110000;
long start_stf_id=120000;
void student_available_seat(int);
void student_admit_particular_id(int);
class staff
{
protected:
long stf_id;
char name[10];
int  salary;
int  class_name;
public :
void staff_data();
void staff_display();
}stf[10];
void staff::staff_data()
{
//staff_id=stf_id+j;
stf_id=++start_stf_id;

cout<<"enter staff_name:";
cin>>name;
cout<<"enter salary:";
cin>>salary;
cout<<"enter class_name in integer:";
cin>>class_name;
}
void staff::staff_display()
{
cout<<endl<<"staff_id:";
cout<<stf_id<<endl;
cout<<"staff_name:";
cout<<name<<endl;
cout<<"salary:";
cout<<salary<<endl;
cout<<"class_name:";
cout<<class_name<<endl;
}

class fees
{
public:
int fees_status;
int month_num;
int tution_fees;
int exam_fees;
int transport_fees;
}fees_month[12][4];

class student:public fees
{
public:
long std_id;
char student_name[20];
char parent_name[20];
int  class_name;
char address[50];
char  mobile_num[11];
char addmission_date[10];
public:
void student_data();
void student_display();
void student_fees_pay(int );
void student_fees_status(int);
void student_delete();
void student_fees_delete(int);
void student_data_particular_id(int);
void student_upgrade(int);

}std[10];
void student::student_upgrade(int m)
{

if(std[m].student_name[0]!='\0')
std[m].class_name+=1;
}

void student::student_data()
{
int cname;
std_id=++start_std_id;
int m=std_id-110000;
if(std[m].student_name[0]=='\0')
{
cout<<"enter student_name(length[20]):";
cin>>std[m].student_name;

cout<<"enter class_name in integer(0-12):";
cin>>cname;
if(cname>=0&&cname<=12)
std[m].class_name=cname;
else
cout<<"error in class_name"<<endl;


cout<<"enter parent_name(length[20]):";
cin>>std[m].parent_name;
cout<<"enter mobile_number(length[10]):";
cin>>std[m].mobile_num;
cout<<"enter addmission_date(format[dd/mm/yy]):";
cin>>std[m].addmission_date;
cout<<"enter address(length[50]):";
cin>>std[m].address;
}
}
void student::student_display()
{

cout<<endl<<"student_id:";
cout<<std_id<<endl;
cout<<"student_name:";
cout<<student_name<<endl;
cout<<"class_name:";
cout<<class_name<<endl;
cout<<"parent_name(length[20]):";
cout<<parent_name<<endl;
cout<<"mobile_number(length[10]):";
cout<<mobile_num<<endl;
cout<<"addmission_date(format[dd/mm/yy]):";
cout<<addmission_date<<endl;
cout<<"address(length[50]):";
cout<<address<<endl;
}


void student::student_fees_pay(int a)
{
if(std[a].student_name[0]!='\0')
{
cout<<"jan-dec is equivalent to 1-12:"<<endl;
cout<<"enter digit(1-12):";
cin>>month_num;
cout<<"tution_fees:";
cin>>fees_month[month_num][a].tution_fees;
fees_month[month_num][a].fees_status=1;
student_fees_status(a);
}
else
cout<<"student is not admitted at:"<<a+110000<<endl;
}

void student::student_fees_status(int a)
{
for(int m=1;m<=12;m++)
{
if(fees_month[m][a].fees_status==1)
cout<<"fees of month "<<m<<" is paid......"<<endl;
else
cout<<"fees of month "<<m<<" is due"<<endl;
}
}
void student::student_delete()
{
//std_id=NULL;
for(int m=0;m<20;m++)
{
student_name[m]='\0';
parent_name[m]='\0';
}
class_name=NULL;
for(m=0;m<50;m++)
address[i]='\0';
for(m=0;m<11;m++)
mobile_num[m]='\0';
for(m=0;m<10;m++)
addmission_date[m]='\0';
}
void student::student_fees_delete(int a)
{
for(int i=1;i<=12;i++)
{
fees_month[i][a].fees_status=NULL;
fees_month[i][a].tution_fees=NULL;
fees_month[i][a].exam_fees=NULL;
fees_month[i][a].transport_fees=NULL;
}
}
void student_available_seat(int a)
{
for(int m=1;m<=a;m++)
{
if(std[m].student_name[0]=='\0')
cout<<"std_id: "<<m+110000<<endl;
}
}
void student_admit_particular_id(int a)
{
if(std[a].student_name[0]=='\0')
{
std[a].student_data_particular_id(a);
std[a].student_display();
}
else
cout<<"student is already admitted at this std_id"<<endl;
}
void student::student_data_particular_id(int a)
{
int cname;
std_id=110000+a;
cout<<"enter student_name(length[20]):";
cin>>student_name;

cout<<"enter class_name in integer(0-12):";
cin>>cname;
if(cname>=0&&cname<=12)
std[a].class_name=cname;
else
cout<<"error in class name"<<endl;

cout<<"enter parent_name(length[20]):";
cin>>parent_name;
cout<<"enter mobile_number(length[10]):";
cin>>mobile_num;
cout<<"enter addmission_date(format[dd/mm/yy]):";
cin>>addmission_date;
cout<<"enter address(length[50]):";
cin>>address;
}

void main()
{
int gd=DETECT,gm;
long n,std_id,stf_id;
int m;
long id;
initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
setbkcolor(3);
x:
cleardevice();
cout<<"=============================================="<<endl;
cout<<"                  MENU                        "<<endl;
cout<<"=============================================="<<endl;
cout<<"          Made by saurabh_gupta               "<<endl;
cout<<"     enter [1] for adding new student         "<<endl;
cout<<"     enter [2] for staff                      "<<endl;
cout<<"     enter [3] to get information             "<<endl;
cout<<"     enter [4] for fees payment               "<<endl;
cout<<"     enter [5] for fees status                "<<endl;
cout<<"=============================================="<<endl;
cout<<"     enter [-1] for deleting student          "<<endl;
cout<<"     enter [-2] to see available seat         "<<endl;
cout<<"     enter [-3] to admit student at a particular std_id:"<<endl;
cout<<"     enter [-4] to upgrade students in next class:    "<<endl;
cout<<"     enter [0]  to exit                       "<<endl;
cout<<"=============================================="<<endl;
cout<<"     start_std_id:"<<start_std_id+1<<" start_staff_id"<<start_stf_id+1<<endl;
cout<<"==============================================="<<endl<<"::";
cin>>n;

switch(n)
{
case 1:

std[i].student_data();
//cleardevice();
std[i].student_display();
i++;
cout<<"enter [0] to go back:";
cin>>m;
if(m==0)
goto x;
break;


case 2:

stf[j].staff_data();
cleardevice();
stf[j].staff_display();
j++;
cout<<endl<<"enter [0] to go back:";
cin>>m;
if(m==0)
goto x;
break;

case 3:

cout<<"enter id:";
cin>>id;
if(id>110000&&id<120000)
{
m=id-110000;
std[m].student_display();
}
else
{
m=id-120000;
stf[m].staff_display();
}
cout<<endl<<"enter [0] to go back:";
cin>>m;
if(m==0)
goto x;

case 4:

cout<<"enter id:";
cin>>id;
if(id>110000&&id<120000)
{
m=id-110000;
cout<<"student_name:"<<std[m].student_name<<endl;
cout<<"class_name:"<<std[m].class_name<<endl;
cout<<"parent_name:"<<std[m].parent_name<<endl;
std[m].student_fees_pay(m);
}

cout<<endl<<"enter [0] to go back:";
cin>>m;
if(m==0)
goto x;

case 5:

cout<<"enter id:";
cin>>id;
if(id>110000&&id<120000)
{
m=id-110000;
cout<<"student_name:"<<std[m].student_name<<endl;
cout<<"class_name:"<<std[m].class_name<<endl;
cout<<"parent_name:"<<std[m].parent_name<<endl;
std[m].student_fees_status(m);

cout<<endl<<"enter [0] to go back:";
cin>>m;
if(m==0)
goto x;
case -1:

cout<<"enter std_id:";
cin>>id;
if(id>110000&&id<120000)
{
m=id-110000;
std[m].student_delete();
std[m].student_fees_delete(m);
cout<<"student std_id:"<<m+110000<<" is deleted"<<endl;
cout<<"std_id:"<<m+110000<<" is now available for another student"<<endl;
cout<<"student availabel seat is updated:"<<endl;

std[m].student_display();
std[m].student_fees_status(i);
}
cout<<endl<<"enter [0] to go back:";
cin>>m;
if(m==0)
goto x;


case -2:

cout<<"enter number of seats to see availability:";
cin>>m;
student_available_seat(m);

cout<<endl<<"enter [0] to go back:";
cin>>m;
if(m==0)
goto x;

case -3:

cout<<"enter std_id:";
cin>>id;
m=id-110000;
student_admit_particular_id(m);
cout<<endl<<"enter [0] to go back:";
cin>>m;
if(m==0)
goto x;

case -4:

for(m=1;m<400;m++)
std[m].student_upgrade(m);
cout<<endl<<"enter [0] to go back:";
cin>>m;
if(m==0)
goto x;

}
}
getch();
}


A presentation on clipping Technique in C graphics


#include <stdio.h>
#include<conio.h>
#include<iostream.h>
#include <stdlib.h>
#include <graphics.h>
#include<dos.h>
#define MAX 20
typedef struct
{
float x;
float y;
}PT;
int m;//global variable for polygon clipping
/*prototype for sutherland polygon clipping functions*/
void polygon_clipping();
void polygon_info();
void top(PT p1,PT p[20],PT pp[20]);
void bottom (PT p2,PT p[20],PT pp[20]);
void left(PT p1,PT p[20],PT pp[20]);
void right(PT p2,PT p[20],PT pp[20]);
void drawpolygon(PT x[20],int n);


//*prototype of cohensutherland line clipping*/
void line_clipping();
void line_clipping_info();
void cohen_sutherland (double x1, double y1, double x2, double y2,
double xmin, double ymin, double xmax, double ymax);
/*cohen suther land line clipping*/
enum { TOP = 0x1, BOTTOM = 0x2, RIGHT = 0x4, LEFT = 0x8 };

enum { FALSE, TRUE };
typedef unsigned int outcode;

outcode compute_outcode(int x, int y,
int xmin, int ymin, int xmax, int ymax)
{
    outcode oc = 0;

    if (y > ymax)
oc |= TOP;
    else if (y < ymin)
oc |= BOTTOM;


    if (x > xmax)
oc |= RIGHT;
    else if (x < xmin)
oc |= LEFT;

    return oc;
}
/*prototype for Weiler-Atherton Polygon Clipping*/
void weiler_polygon_clipping();

void main()
{
int ch;

    int gd = DETECT, gm;

initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
clrscr();
setbkcolor(2);
settextstyle(SMALL_FONT,HORIZ_DIR,6);
outtextxy(100,60,"A PRESENTATION ON CLIPPING TECHNIQUE ");
outtextxy(100,90,"Submitted by Saurabh And Shubham ");

outtextxy(50,130,"Name:Saurabh gupta ");
outtextxy(50,170,"Registration no.:11009096");
outtextxy(50,210,"Rollno:K1003A19");

outtextxy(350,130,"Name:Shubham varshney");
outtextxy(350,170,"Registration no.:11011481");
outtextxy(350,210,"Rollno:K1003A24");

outtextxy(50,350,"submitted to Mr.Gaurav Raj");
outtextxy(50,390,"DEPARTMENT OF COMPUTER SCIENCE");




outtextxy(50,250,"press 1 to start presentation");
settextstyle(SMALL_FONT,HORIZ_DIR,4);
int x;
cin>>x;
if(x==1)
{
label0:
cleardevice();
setbkcolor(3);
settextstyle(SMALL_FONT,HORIZ_DIR,6);
outtextxy(50,30,"[1] cohen suderland line clipping");
outtextxy(50,50,"[2] suderland-hodgeman polygon clipping");
outtextxy(50,70,"[3] wieler-artheton");
outtextxy(50,90,"Enter your choice:");
outtextxy(50,110,"Enter 0 to exit");
settextstyle(SMALL_FONT,HORIZ_DIR,4);
cin>>ch;
clrscr();
switch(ch)
{

case 1:
label1:
cleardevice();
setbkcolor(4);                        //set background colour
line_clipping_info();               //function of line clipping
line_clipping();
outtextxy(50,50,"press 0 to go back to main menu");
outtextxy(50,60,"press 2 to see polygon clipping");
outtextxy(50,70,"press 3 to see  weiler-Atherton Polygon Clipping");
cin>>x;
if(x==0)
goto label0;
if(x==2)
goto label2;
if(x==3)
goto label3;
// break;

case 2:
label2:
cleardevice();
setbkcolor(5);
polygon_info();
outtextxy(50,350,"press 1 to see the example of polygon clipping");
cin>>x;
if(x==1)
polygon_clipping();
outtextxy(50,60,"press 0 to go back to main menu");
outtextxy(50,70,"press 1 to see line clipping");
outtextxy(50,80,"press 3 to see  weiler-Atherton Polygon Clipping");
cin>>x;
if(x==0)
goto label0;
if(x==1)
goto label1;
if(x==3)
goto label3;

//break;


case 3:
label3:
cleardevice();
setbkcolor(6);
weiler_polygon_clipping();
outtextxy(50,360,"press 0 to go back to main menu");
outtextxy(50,370,"press 1 to see line clipping");
outtextxy(50,380,"press 2 to see polygon clipping");
cin>>x;
if(x==0)
goto label0;
if(x==1)
goto label1;
if(x==2)
goto label2;
}
}

else
{
cleardevice();
outtextxy(100,100,"wrong choice pressed");
}
cleardevice();
setbkcolor(2);
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 5);
outtextxy(150,150,"THANK YOU");

getch();
closegraph();

}







void cohen_sutherland (double x1, double y1, double x2, double y2,
double xmin, double ymin, double xmax, double ymax)
{
    int accept;
    int done;
    outcode outcode1, outcode2;

    accept = FALSE;
    done = FALSE;

    outcode1 = compute_outcode (x1, y1, xmin, ymin, xmax, ymax);
    outcode2 = compute_outcode (x2, y2, xmin, ymin, xmax, ymax);
    do
    {
if (outcode1 == 0 && outcode2 == 0)
{
   accept = TRUE;
   done = TRUE;
}
else if (outcode1 & outcode2)
{
   done = TRUE;
}
else
{
   double x, y;
   int outcode_ex = outcode1 ? outcode1 : outcode2;
   if (outcode_ex & TOP)
   {
x = x1 + (x2 - x1) * (ymax - y1) / (y2 - y1);
y = ymax;
   }

   else if (outcode_ex & BOTTOM)
   {
x = x1 + (x2 - x1) * (ymin - y1) / (y2 - y1);
y = ymin;
   }
   else if (outcode_ex & RIGHT)
   {
y = y1 + (y2 - y1) * (xmax - x1) / (x2 - x1);
x = xmax;
   }
   else
   {
y = y1 + (y2 - y1) * (xmin - x1) / (x2 - x1);
x = xmin;
   }
   if (outcode_ex == outcode1)
   {
x1 = x;
y1 = y;
outcode1 = compute_outcode (x1, y1, xmin, ymin, xmax, ymax);
   }
   else
   {
x2 = x;
y2 = y;
outcode2 = compute_outcode (x2, y2, xmin, ymin, xmax, ymax);
   }
}
    } while (done == FALSE);

    if (accept == TRUE)
line (x1, y1, x2, y2);
}


void left(PT p1,PT p[20],PT pp[20])
{
int  i,j=0;
for(i=0;i<m;i++)
{
if(p[i].x < p1.x && p[i+1].x >= p1.x){
if(p[i+1].x-p[i].x!=0)
{
pp[j].y = (p[i+1].y-p[i].y)/(p[i+1].x-p[i].x)* (p1.x-p[i].x)+p[i].y;
}
else
{
pp[j].y = p[i].y;
}
pp[j].x = p1.x;
j++;
pp[j].x=p[i+1].x;
pp[j].y=p[i+1].y;
j++;
}
if(p[i].x > p1.x && p[i+1].x >= p1.x)
{
pp[j].y = p[i+1].y;
pp[j].x = p[i+1].x;
j++;
}
if(p[i].x > p1.x && p[i+1].x <= p1.x)
{
if(p[i+1].x-p[i].x!=0)
{
pp[j].y = (p[i+1].y-p[i].y)/(p[i+1].x-p[i].x)* (p1.x-p[i].x)+p[i].y;
}
else
{
pp[j].y = p[i].y;
}
pp[j].x = p1.x;
j++;
}
}
for(i=0;i<j;i++)
{
p[i].x = pp[i].x;
p[i].y = pp[i].y;
}
p[i].x = pp[0].x;
p[i].y = pp[0].y;
m=j;
}
void right(PT p2,PT p[20],PT pp[20])
{
int i,j=0;
for(i=0;i<m;i++)
{if(p[i].x > p2.x && p[i+1].x <= p2.x)
{
if(p[i+1].x-p[i].x!=0)
{
pp[j].y = (p[i+1].y-p[i].y)/(p[i+1].x-p[i].x)* (p2.x-p[i].x)+p[i].y;
}
else
{
pp[j].y = p[i].y;
}
pp[j].x = p2.x;
j++;
pp[j].x=p[i+1].x;
pp[j].y=p[i+1].y;
j++;
}
if(p[i].x < p2.x && p[i+1].x <= p2.x)
{
pp[j].y = p[i+1].y;
pp[j].x = p[i+1].x;
j++;
}
if(p[i].x < p2.x && p[i+1].x >= p2.x)
{
if(p[i+1].x-p[i].x!=0)
{
pp[j].y = (p[i+1].y-p[i].y)/(p[i+1].x-p[i].x)* (p2.x-p[i].x)+p[i].y;
}
else
{
pp[j].y = p[i].y;
}
pp[j].x = p2.x;
j++;
}
}
for(i=0;i<j;i++)
{
p[i].x = pp[i].x;
p[i].y = pp[i].y;
}
p[i].x = pp[0].x;
p[i].y = pp[0].y;
m=j;
}
void top(PT p1,PT p[20],PT pp[20])
{
int  i,j=0;
for(i=0;i<m;i++){
if(p[i].y < p1.y && p[i+1].y >= p1.y)
{
if(p[i+1].y-p[i].y!=0)
{
pp[j].x = (p[i+1].x-p[i].x)/(p[i+1].y-p[i].y)* (p1.y-p[i].y)+p[i].x;
}
else
{
pp[j].x = p[i].x;
}
pp[j].y = p1.y;
j++;
pp[j].x=p[i+1].x;
pp[j].y=p[i+1].y;
j++;
}
if(p[i].y > p1.y && p[i+1].y >= p1.y)
{
pp[j].y = p[i+1].y;
pp[j].x = p[i+1].x;
j++;
}
if(p[i].y > p1.y && p[i+1].y <= p1.y)
{
if(p[i+1].y-p[i].y!=0)
{
pp[j].x = (p[i+1].x-p[i].x)/(p[i+1].y-p[i].y)* (p1.y-p[i].y)+p[i].x;
}
else
{
pp[j].x = p[i].x;
}
pp[j].y = p1.y;
j++;
}
}
for(i=0;i<j;i++)
{
p[i].x = pp[i].x;
p[i].y = pp[i].y;
}
p[i].x = pp[0].x;
p[i].y = pp[0].y;
m=j;
}
void bottom(PT p2,PT p[20],PT pp[20])
{
int i,j=0;for(i=0;i<m;i++)
{
if(p[i].y > p2.y && p[i+1].y <= p2.y)
{
if(p[i+1].y-p[i].y!=0)
{
pp[j].x = (p[i+1].x-p[i].x)/(p[i+1].y-p[i].y)* (p2.y-p[i].y)+p[i].x;
}
else
{
pp[j].x = p[i].x;
}
pp[j].y = p2.y;
j++;
pp[j].x=p[i+1].x;
pp[j].y=p[i+1].y;
j++;
}
if(p[i].y < p2.y && p[i+1].y <= p2.y)
{
pp[j].y = p[i+1].y;
pp[j].x = p[i+1].x;
j++;
}
if(p[i].y < p2.y && p[i+1].y >= p2.y)
{
if(p[i+1].y-p[i].y!=0)
{
pp[j].x = (p[i+1].x-p[i].x)/(p[i+1].y-p[i].y)* (p2.y-p[i].y)+p[i].x;
}
else
{
pp[j].x = p[i].x;
}
pp[j].y = p2.y;
j++;
}
}
for(i=0;i<j;i++)
{
p[i].x = pp[i].x;
p[i].y = pp[i].y;
}
p[i].x = pp[0].x;
p[i].y = pp[0].y;
m=j;
}
void drawpolygon(PT x[20],int m)
{
int i;
for(i=0;i<m-1;i++)
{
line(x[i].x,x[i].y,x[i+1].x,x[i+1].y);
}
line(x[i].x,x[i].y,x[0].x,x[0].y);
}




void line_clipping()
{
    int n=3;
    int i, j;
    int ln[MAX][4];
    int clip[4];


      outtextxy(370,300,"press enter to see demonstration");
      ln[0][0]=30+300;
      ln[0][1]=70+300;
      ln[0][2]=60+300;
      ln[0][3]=70+300;

      ln[1][0]=30+300;
      ln[1][1]=90+300;
      ln[1][2]=60+300;
      ln[1][3]=30+300;

      ln[2][0]=50+300;
      ln[2][1]=100+300;
      ln[2][2]=90+300;
      ln[2][3]=60+300;


    /*for (i=0; i<n; i++)
for (j=0; j<4; j++)
   scanf ("%d", &ln[i][j]);

    printf ("Enter the x- and y-coordinates of the left-top and right-");
    printf ("bottom corners\nof the clip window:\n");

    for (i=0; i<4; i++)
scanf ("%d", &clip[i]); */
clip[0]=40+300;
clip[1]=50+300;


clip[2]=80+300;
clip[3]=90+300;

       // cleardevice();
rectangle (clip[0], clip[1], clip[2], clip[3]);
for (i=0; i<n; i++)
line (ln[i][0], ln[i][1], ln[i][2], ln[i][3]);
getch();
   cleardevice();
    rectangle (clip[0], clip[1], clip[2], clip[3]);
    for (i=0; i<n; i++)
    {
cohen_sutherland (ln[i][0], ln[i][1], ln[i][2], ln[i][3],
   clip[0], clip[1], clip[2], clip[3]);
getch();
    }
    getch();
  //  closegraph();
    }

void polygon_clipping()
{
PT d,p1,p2,p[20],pi1,pi2,pp[20];
m=8;
p1.x=100;
p1.y=100;
p2.x=200;
p2.y=200;



p[0].x=150;
p[0].y=80;

p[1].x=170;
p[1].y=130;

p[2].x=220;
p[2].y=150;

p[3].x=170;
p[3].y=170;

p[4].x=150;
p[4].y=220;

p[5].x=130;
p[5].y=170;

p[6].x=80;
p[6].y=150;

p[7].x=130;
p[7].y=130;



p[8].x = p[0].x;
p[8].y = p[0].y;
cleardevice();
outtextxy(50,30,"before clipping the window is like this");
drawpolygon(p,m);
rectangle(p1.x,p1.y,p2.x,p2.y);
getch();
left(p1,p,pp);
right(p2,p,pp);
top(p1,p,pp);
bottom(p2,p,pp);
cleardevice();
outtextxy(50,30,"after clipping window is clipped like this");
rectangle(p1.x,p1.y,p2.x,p2.y);
drawpolygon(p,m);
getch();
//closegraph();
}



void line_clipping_info()
{
cleardevice();
setbkcolor(4);

outtextxy(50,30,"Cohen-Sutherland Line Clipping");
outtextxy(250,30,".......");
delay(1000);
outtextxy(50,60,"This is one of the oldest and most popular line-clipping procedure.");
outtextxy(50,70,"Generally,the method speed up the processing of the line segments by");
outtextxy(50,80,"performing initial tests that reduce the number of intersections that");
outtextxy(50,90,"must be calculated.Every line end point in a picture is assigned");
outtextxy(50,100,"a four-digit binary code,called a region,that identifies the location");
outtextxy(50,110,"of the point realtive to the boundaries as shown in fig.");
outtextxy(50,140,"bit 1: Left");
outtextxy(50,150,"bit 2: Right");
outtextxy(50,160,"bit 3: Below");
outtextxy(50,170,"bit 4: Above");

rectangle(50,190,200,300);
delay(1000);
line(100,190,100,300);
delay(1000);
line(150,190,150,300);
delay(1000);
line(50,230,200,230);
delay(1000);
line(50,265,200,265);

outtextxy(60,200,"1001");
delay(1000);
outtextxy(110,200,"1000");
delay(1000);
outtextxy(160,200,"1010");
delay(1000);

outtextxy(60,240,"0001");
delay(1000);
outtextxy(110,240,"0000");
delay(1000);
outtextxy(160,240,"0010");
delay(1000);
outtextxy(60,275,"0101");
delay(1000);
outtextxy(110,275,"0100");
delay(1000);
outtextxy(160,275,"0110");
delay(1000);
outtextxy(101,250,"window");
delay(1000);

outtextxy(300,300,"Example:");
delay(1000);
}

void polygon_info()
{
cleardevice();
outtextxy(50,30,"Sytherland-Hodgeman Polygon Clipping");
outtextxy(250,30,".........");
delay(1000);
outtextxy(50,60,"There are possible four cases when procesing vertices in sequence");
outtextxy(50,70,"around the perimeter of a polygon.As each pair of adjacent polygon");
outtextxy(50,80,"vertices are passed to a window boundary clipper,we make the following");
outtextxy(50,90,"[1] if the first vertext is outside the window boundary and the second ");
outtextxy(50,100,"   vertex is inside, both the intersection point of the polygon edge");
outtextxy(50,110,"   with the window boundary and second vertex is added to the output");
outtextxy(50,120,"[2] if both input vertices are inside the window boundary.");
outtextxy(50,130,"    only the second vertex is added to the output vertex list");
outtextxy(50,140,"[3] if the first vetex is inside the window boundary and the second");
outtextxy(50,150,"    vertex is outside only the edge intersection with the window boundary is");
outtextxy(50,160,"    added to the output list");
outtextxy(50,170,"[4] if both input vertices are outside the window boundary, nothing is");
outtextxy(50,180,"    addded to the output list.");
delay(500);
rectangle(50,200,100,300);
delay(1250);
line(30,250,80,250);
delay(1100);
outtextxy(20,257,"v1");
outtextxy(85,257,"v2");
outtextxy(50,253,"v1'");
outtextxy(50,310,"out-in");
outtextxy(50,320,"save v1',v2");

rectangle(150,200,200,300);
delay(1250);
line(170,220,180,280);
delay(1100);
outtextxy(175,220,"v1");
outtextxy(160,280,"v2");
outtextxy(150,310,"in-in");
outtextxy(150,320,"save v2");

rectangle(250,200,300,300);
delay(1250);
line(230,280,280,250);
delay(1100);
outtextxy(230,280,"v2");
outtextxy(280,250,"v1");
outtextxy(240,260,"v1'");
outtextxy(250,310,"in-out");
outtextxy(250,320,"save v1'");

rectangle(350,200,400,300);
delay(1250);
line(330,210,330,280);
delay(1100);
outtextxy(320,210,"v1");
outtextxy(320,280,"v2");
outtextxy(350,310,"out-out");
outtextxy(350,320,"save none");
}
void weiler_polygon_clipping()
{
outtextxy(50,30,"Weiler-Atherton Polygon Clipping");
outtextxy(50,60,"In this clipping method vertex processing procedures");
outtextxy(50,70,"for window boundaries are modified so that concave polygons");
outtextxy(50,80,"are displayed correctly.The basic idea int this algorithm");

outtextxy(50,90,"is that instead of always proceeding around the polygon edges");
outtextxy(50,100,"as vertices are processed,we sometimes want to follow the window");
outtextxy(50,110,"boundaries.Which path follow depends on the polygon-processing");
outtextxy(50,120,"direction (clockwise or counter clockwise) and whether the pair");
outtextxy(50,130,"of polygon vertices currently being processed represents an");
outtextxy(50,140,"outside-to-inside or an inside-to-outside pair.");
outtextxy(50,170,"For clockwise direction processing of polygon vertices, we use");
outtextxy(50,180,"following rules.");
outtextxy(50,190,"[1] For an outside-to-inside pair of vertices,follow the polygon");
outtextxy(50,200,"    boundary.");
outtextxy(50,210,"[2] For an inside-to-outside pair of vertices,follow the window");
outtextxy(50,220,"    boundary in a clockwise direction.");
rectangle(70,240,180,360);
delay(1100);
line(30,310,110,270);
delay(1100);
line(110,270,100,295);
delay(1100);
line(100,295,50,330);
delay(1100);
line(50,330,110,340);
delay(1100);
line(110,340,30,350);
delay(1100);
line(30,310,30,350);
delay(1100);
outtextxy(20,310,"v1");
delay(1100);
outtextxy(110,270,"v2");
delay(1100);
outtextxy(105,295,"v3");
delay(1100);
outtextxy(45,330,"v4");
delay(1100);
outtextxy(115,340,"v5");
delay(1100);
outtextxy(20,350,"v6");
delay(1100);
outtextxy(65,285,"v1'");
delay(1100);
outtextxy(65,305,"v3'");
 delay(1100);
outtextxy(75,325,"v4'");
delay(1100);
outtextxy(50,350,"v5'");

outtextxy(50,250,"press 1 to start presentation");
 cleardevice();
rectangle(70,240,180,360);
setcolor(11);
line(70,290,110,270);
line(110,270,100,295);
line(100,295,70,320);
line(70,290,70,320);
delay(2000);
line(70,330,110,340);
line(70,330,110,340);
line(110,340,70,350);
line(70,330,70,350);
setcolor(15);



}

Thursday 21 February 2013

a program to set nth bit of an integer to 0


#include<stdio.h>
#include<conio.h>
void main()
{
int n=2;
int f=12;
clrscr();
f&=~(1L<<n);
printf("%d",f);
getch();
}


Explanation:
f &=~(1L<<n)
=> f = f & ~ (1L<<n)
in binary; f : 0000 1100
             1L: 0000 0001
   (1L<<2) : 0000 0100  ; bits are shifted to left 2 times.
  ~(1L<<2) : 1111 1011 ; complement the bits.
  &  is a bitwise AND operator, it will perform AND operation and result will be stored to f  so;
                f : 0000 1000
output will be 8.



A program to set nth bit of an integer to 1


#include<stdio.h>
#include<conio.h>
void main()
{
int n=2;
 int f=8;
clrscr();
f |= (1L<<n);
printf("%d",f);
getch();
}

Explanation:
f |= (1L<<n)
=> f = f | (1L<<n)
in binary; f : 0000 1000
             1L: 0000 0001
   (1L<<2) : 0000 0100  ; bits are shifted to left 2 times.
   | is a bitwise or operator, it will perform or operation and result will be stored to f  so;
                f : 0000 1100
output will be 12.


Wednesday 20 February 2013

array of pointer


#include<iostream.h>
#include<conio.h>
void sort(char *name[],const int size);
void main()
{
char *name[]={"saurabh","amit","sushant","rohan"};
sort(name,4);
getch();
}
void sort(char *name[],const int size)
{ clrscr() ;
for(int i=0;i<size;i++)

cout<<name[i]<<"\t";
}

accessing elements of array of any dimention with single loop with pointer


#include<stdio.h>
#include<conio.h>
int sum(int *ptr,const int row,const int col);
void main()
{
int a[][3]={1,2,3,4,5,6,7,8,9};
int *ptr;
clrscr();
ptr=&a[0][0];
printf("%d",sum(ptr,3,3));
getch();
}
int sum(int *ptr,const int row,const int col)
{
int s=0;
for(int i=0;i<row*col;i++)
{
s=s+*(ptr+i);
}
return s;
}
NOTE: program will sum all the elements of array.

pointer to array


#include<stdio.h>
#include<conio.h>
int highest(int *ptr,const int row,const int col);
void main()
{
int *ptr;
int temp[3][4]={3,4,2,6,5,8,9,12,0,4,7,10};
ptr=&temp[0][0];
printf("%d",highest(ptr,3,4));
getch();
}
int highest( int *ptr,const int row,const int col)
{
int h=0;
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
if(*(ptr+i*col+j)> h)
h=*(ptr+i*col+j);
return h;
}

NOTE: here *(ptr+i*col+j)=temp[i][j].
program finds the highest value element of 3x4 array. 

passing array to function



#include<stdio.h>
#include<conio.h>
const int row=3,col=4;
int high(int temp[3][4])
{
int i,j,h=0;
for( i=0;i<row;i++)
{
for( j=0;j<col;j++)
{
if(h<temp[i][j])
h=temp[i][j];
}
}
return h;
}

void main()
{
int temp[][4]={12,23,45,10,13,24,24,56,30,45,28,90};
printf("%d",high(temp));
getch();
}

Friday 25 January 2013

A program to reverse the words of a sentence

eg. i am a good boy
result: boy good a am i.


#include<stdio.h>
#include<conio.h>
void main()
{
char a[20],c[20];
char x=' ';
int k,l,m,i,j,r,b[10];
j=0;
for(i=0;i<20;i++)
c[i]=' ';
clrscr();

printf("enter a sentence:");
for(i=0;i<20;i++)
scanf("%c",&a[i]);
for(i=0;i<20;i++)
printf("%c",a[i]);
for(i=0;i<20;i++)
{
if(a[i]==x)
{
b[j]=i;
j++;

}
}
//printf("%d",j);
r=0;
/*for(i=0;i<j;i++)
printf("%d",b[i]+1);*/
printf("\n");
for(m=1;m<=j;m++)
{
l=b[j-m];
for(i=r;i<20;i++)
{
if(a[l+1]!='\0'&& a[l+1]!=' ' &&l<20)
{
c[i]=a[l+1];
l++;
r++;
}
}
r++;
c[r]=' ';
}


for(i=0;i<20;i++)
{
printf("%c",c[i]);
}
getch();
}

NOTE: give one space before entering the input and many spaces after completion of sentence so that input exceeds the no. of elements in array.






Remove character from one string which matches in other


eg.s1="abcde" ,s2="xyzab" then result "cde".




#include<stdio.h>
#include<conio.h>
void main()
{
char a[10],b[10];
int i,j,k;
for(i=0;i<10;i++)
a[i]='\0';

printf("enter string a:");
scanf("%s",&a);
printf("enter string b:");
scanf("%s",&b);
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
if(a[i]==b[j])
{
for(k=i;k<10;k++)
a[k]=a[k+1];

}
}
}

printf("%s",a);
getch();
}


Thursday 24 January 2013

Removing duplicacy in a string with C


#include<stdio.h>
#include<conio.h>
void main()
{
char a[10];
char x;
int i,j,k;
clrscr();
printf("enter a string:");
scanf("%s",&a);

for(j=0;j<10;j++)
{
x=a[j];
for(i=j+1;i<10;i++)
{
if(a[i]==x)
{
//printf("%d",i);

for( k=i;k<10;k++)
{
a[k]=a[k+1];

}
}
}
}
printf("%s",a);
getch();
}

input: microsoftim
ouptut: microsft

Conversion of decimal to binary,octal,hexadecimal in C/C++


#include<stdio.h>
#include<conio.h>
void main()
{
int s,a,k,c,i,b[10],m[10];
int n=2;
clrscr();
i=0;
c=0;
printf("enter a number:");
scanf("%d",&a);
while(a>0)
{
b[i]=a%n;

a=a/n;

i++;
c++;

}
k=0;
for(i=c-1;i>=0;i--)
{
m[k]=b[i];
k++;
}
for(i=0;i<c;i++)
{
printf("%d",m[i]);
}

getch();
}

input: 9
output:1001
if you want to calculate octal then replace n=8, for hexadecimal, n=16;

Sunday 20 January 2013

Elevator Program in Java


import java.io.*;

class elevator
{
int currentfloor;
int headingfloor;
boolean movement;
boolean doors;

void goToFloor(int s)
{
headingfloor=s;
System.out.println("\nLift is heading to floor="+headingfloor);
}

void openDoors()
{
doors=true;
System.out.println("\nDoors are open\n");
}

void closeDoors()
{
doors=false;
System.out.println("\nDoors are close\n");
}

void goingUp()
{
movement=true;
}

void goingDown()
{
movement=false;
}

void print(int h)
{
currentfloor=h;
System.out.print("\n@@Heading please wait@@\n");
if(headingfloor>currentfloor)
{
System.out.print("\nMovement up\n");
}
else
{
System.out.print("\nMovement down\n");
}
}
}


class ElevatorProgram
{
public static void main(String args[]) throws IOException
{
elevator ob=new elevator();
elevator obdup=new elevator();
ob.openDoors();
System.out.print("\nPresent floor=");
BufferedReader stdin1 = new BufferedReader ( new InputStreamReader( System.in ) );
String h;
h=stdin1.readLine();
int a= Integer.parseInt(h);
System.out.print("\nDesired floor=");
BufferedReader stdin = new BufferedReader ( new InputStreamReader( System.in ) );
String l;
l=stdin.readLine();
int u= Integer.parseInt(l);
ob.goToFloor(u);

obdup.goingUp();
obdup.goingDown();
ob.print(a);
obdup.closeDoors();
}
}

Matrix Multiplication in java




class MatrixMultiply{

        public static void main(String[]args)  {

          int array[][] ={{1,2,3},{4,5,6},{7,8,9}};

          int array1[][] ={{1,2,3},{4,5,6},{7,8,9}};

          int array2[][] = new int[3][3];

          int x= array.length;

          System.out.println("Matrix 1: ");

            for(int i = 0; i <x; i++) {

            for(int j = 0; j <x; j++) {

              System.out.print(" "+ array[i][j]);

            }

          System.out.println();

          }

          int y= array1.length;

          System.out.println("Matrix 2: ");

            for(int i = 0; i <y; i++) {

            for(int j = 0; j <y; j++) {

              System.out.print(" "+array1[i][j]);

            }

          System.out.println();

          }

            for(int i = 0; i <x; i++) {

            for(int j = 0; j <y; j++) {

              for(int k = 0; k <y; k++){

                array2[i][j] +=array[i][k]*array1[k][j];

              }

            }

           }

          System.out.println("Multiply of both matrix : ");

          for(int i = 0; i <x; i++) {

            for(int j = 0; j <y; j++) {

              System.out.print(" "+array2[i][j]);

            }

          System.out.println();

          }

        }

      }

A simple banner with applet in java


/* A simple banner applet. This applet creates a thread that scrolls the message contained in msg right to left across the applet's window. */
import java.awt.*;
import java.applet.*;
/*
<applet code="SimpleBanner" width=600 height=300>
</applet>
*/
public class SimpleBanner extends Applet implements Runnable {
String msg = "HELLO";
Thread t = null;
int state;
boolean stopFlag;
// Set colors and initialize thread.
public void init()
   {
       setBackground(Color.pink);
       setForeground(Color.red);
   }
// Start thread
                 public void start()
                     {
                          t = new Thread(this);
                          stopFlag = false;
                          t.start();
                    }
// Entry point for the thread that runs the banner.
                public void run()
                    {
                          char ch;
// Display banner
                         for( ; ; ) {
                             try
                               {
                                 repaint();
                                 Thread.sleep(5000);
                                 ch = msg.charAt(0);
                                 msg = msg.substring(1, msg.length());
                                 msg += ch;
                                 if(stopFlag)
                                        break;
                            } catch(InterruptedException e) {}
                     }
}
// Pause the banner.
public void stop()
                      {
           stopFlag = true;
                              t = null;
                      }
// Display the banner.
                 public void paint(Graphics g)
                     {
                        g.drawString(msg, 80, 10);
                     }
    }

A moving Banner in Java with Applet


import java.awt.*;
import java.applet.*;
/*
<applet code="ParamBanner" width=300 height=50>
<param name=message value="Java makes the Web move!">
</applet>
*/
public class ParamBanner extends Applet implements Runnable
          {
String msg;
Thread t = null;
int state;
boolean stopFlag;
// Set colors and initialize thread.
public void init()
    {
               setBackground(Color.cyan);
               setForeground(Color.red);
                       }
// Start thread
public void start()
                       {
                 msg = getParameter("message");
if(msg == null) msg = "Message not found.";
msg = " " + msg;
t = new Thread(this);
stopFlag = false;
t.start();
       }

Sunday 6 January 2013

Button click and event handling with applet in java


package event1;
import java.applet.Applet;
import java.awt.event.*;
import java.awt.*;


public class Event1 extends Applet implements  ActionListener {
   Button btn1,btn2;
   public void init()
    {
  setLayout(new FlowLayout());
   btn1=new Button("blue");
   btn2=new Button("green");
btn1.addActionListener(this);
btn2.addActionListener(this);
add(btn1);
add(btn2);
// setSize(400,400);
//setBounds(200,180,200,140);
//setVisible(true);
}
  public void actionPerformed(ActionEvent e)
   {
       if(e.getSource()==btn1)
       {
          setBackground(Color.BLUE);
       }
       else if(e.getSource()==btn2)
        setBackground(Color.GREEN);   
   }
}

A moving vehicle with applet in java


package animation1;
import java.applet.Applet;
import java.awt.*;

public class Animation1 extends Applet implements Runnable{
  private int x,y,x1,y1,x3,y3;
  Thread th;
    public void init()
   {  x=50;
   y=50;
   x1=50;
   y1=200;
   x3=150;
   y3=200;
  
       setForeground(Color.BLACK);
     
           //repaint();
          
       
     
   }
    public void start()
    {
        th=new Thread (this);
        th.start();
       
    }
   public void run()
   {
        for(int i=0;i<1000;i++)
       { 
           x=x+3;
          // y++;
           x1=x1+3;
          // y1++;
           x3=x3+3;
          // y3++;
            repaint();
           try{
              
         Thread.sleep(50);
              
           }
          catch(InterruptedException e){}
       }
   }
  /* public void update(Graphics g)
    {
        paint(g);
    }*/
   public void paint(Graphics g)
   {  
       g.drawRect(x,y,150,150);
       g.drawOval(x1,y1,50,50);
       g.drawOval(x3,y3,50,50);
       
             
   
            }
}

Addition of two number with applet and event handling


package applet2;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Applet2 extends Applet implements ActionListener{
 
   Label lbl1,lbl2,lbl3,lbl4;
   TextField txt1,txt2;
   Button btn;
   public void init()
   { setLayout(new GridLayout(4,2));
      setBackground(Color.GRAY);
       lbl1=new Label("enter first Number");
       lbl2=new Label("enter second Number");
       lbl3=new Label("Sum");
       lbl4=new Label();
       txt1=new TextField(20);
       txt2=new TextField(20);
       btn=new Button("Result");
        Component add1 = add(lbl1);
       Component add2=add(txt1);
     
      Component add3= add(lbl2);
       Component add4=add(txt2);
      Component add5= add(lbl3);
       Component add6=add(lbl4);
       Component add7=add(btn);
       btn.addActionListener(this);
   }
   public void actionPerformed(ActionEvent e)
   {
       int s1,s2,s3;
       if(e.getSource()==btn);
       {
         s1=Integer.parseInt(txt1.getText());
          s2=Integer.parseInt(txt2.getText());
          s3=s1+s2;
          lbl4.setText(Integer.toString(s3));
       }
   }
   
}

Saturday 5 January 2013

Add subtract divide multiply in java

package calculator;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


class cal extends JFrame implements ActionListener
{
    // cal cl=new cal();
    int s3,s1,s2;
    JLabel num1,num2,res,rs;
    JPanel panel1,panel2;
    JButton add,sub,mul,div;
    JTextField n1,n2,n3;
    cal()
    {
     panel1=new JPanel(new FlowLayout());
      panel2=new JPanel(new FlowLayout());
     num1=new JLabel("Number1");
     num2=new JLabel("Nmber2");
     res=new JLabel("Result");
     rs=new JLabel("rgjfjj");
     n1=new JTextField(5);
     n2=new JTextField(5);
     n3=new JTextField(5);
     add=new JButton("ADD");
     sub=new JButton("SUB");
     mul=new JButton("MUL");
     div=new JButton("DIV");
    
     add.addActionListener(this);
     mul.addActionListener(this);
     sub.addActionListener(this);
     div.addActionListener(this);
   Component add1= panel1.add(num1);
  Component add2=  panel1.add(n1);
   Component add3= panel1.add(num2);
   Component add4= panel1.add(n2);
   Component add5= panel1.add(res);
    Component add6 = panel1. add(n3);
    Component add7 = panel2.   add(add);
    Component add8 = panel2.   add(sub);
    Component add9 = panel2.   add(mul);
    Component add10 = panel2.  add(div);
     add(panel1,BorderLayout.NORTH);
     add(panel2,BorderLayout.SOUTH);
    
    
      
     }
   
    public void actionPerformed(ActionEvent e)
   {
      int s1=Integer.parseInt(n1.getText());
      int s2=Integer.parseInt(n2.getText());
     
     
       if(e.getSource()==add)
       {
           s3=s1+s2;
      System.out.println(s3);
       n3.setText(Integer.toString(s3));
       }
       else if(e.getSource()==sub)
       {
           s3=s1-s2;
      System.out.println(s3);
       n3.setText(Integer.toString(s3));
       }
        else if(e.getSource()==div)
       {
           s3=s1/s2;
      System.out.println(s3);
       n3.setText(Integer.toString(s3));
       }
       else if(e.getSource()==mul)
       {
           s3=s1*s2;
      System.out.println(s3);
       n3.setText(Integer.toString(s3));
       }
}
}

public class Calculator {
  
    public static void main(String[] args) {
       cal cl=new cal();
       cl.setBounds(200, 150, 120, 550);
       cl.setTitle("calculator");
       cl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       cl.setResizable(true);
       cl.setVisible(true);
       cl.setSize(500,200);
    }
}