1.
Draw the following pattern using standard graphics
library
[Link] Diagram of Computer
[Link] Flag of India
[Link]-Chart symbols,DFD symbols,ER-Diagram symbols
a)Block Diagram of Computer
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\TURBOc3\\bgi");
setbkcolor(WHITE);
setcolor(10);
rectangle(40,150,160,240);
line(180,190,200,200);
line(160,200,200,200);
line(180,210,200,200);
rectangle(200,50,400,400);
rectangle(220,70,380,380);
line(220,160,380,160);
line(220,280,380,280);
setcolor(6);
settextstyle(1,0,1);
outtextxy(70,180,"INPUT");
outtextxy(270,210,"ALU");
outtextxy(240,110,"MEMORY UNIT");
outtextxy(230,320,"CONTROL UNIT");
outtextxy(480,180,"OUTPUT");
setcolor(10);
rectangle(460,150,580,240);
line(440,190,460,200);
line(400,200,460,200);
line(440,210,460,200);
setcolor(20);
outtextxy(150,430,"BLOCK DIAGRAM OF COMPUTER");
getch();
closegraph();
}
***********************OUTPUT**************************
**************
b)Display Flag of India
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int x,y,i,gd=DETECT,gm;
float PI=3.14;
clrscr();
initgraph(&gd,&gm,"c:\\TURBOC3\\bgi");
setbkcolor(WHITE);
setcolor(4);
rectangle(200,30,450,80);
setfillstyle(1,4);
floodfill(201,31,4);
setcolor(15);
rectangle(200,80,450,130);
setfillstyle(1,15);
floodfill(201,81,15);
setcolor(2);
rectangle(200,130,450,180);
setfillstyle(1,2);
floodfill(201,131,2);
setcolor(1);
circle(325,105,20);
for(i=0;i<=360;i=i+15)
{
x=20*cos(i*PI/180);
y=20*sin(i*PI/180);
line(325,105,325+x,105-y);
}
setcolor(7);
rectangle(195,30,200,400);
setfillstyle(1,7);
floodfill(196,31,7);
setcolor(20);
settextstyle(1,0,7);
outtextxy(130,410,"FLAG OF INDIA");
getch();
closegraph();
}
******************************OUTPUT*******************
*************
c)Flow-Chart symbols,DFD symbols,ER-Diagram Symbols
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd,gm;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\TURBOC3\\bgi");
setbkcolor(WHITE);
setcolor(20);
settextstyle(1,0,1);
outtextxy(170,50,"SYMBOLS OF THE FLOWCHART");
settextstyle(0,0,1);
outtextxy(120,100,"NAME");
outtextxy(440,100,"SYMBOL");
outtextxy(110,140,"TERMINAL SYMBOL");
line(430,130,480,130);
line(430,150,480,150);
arc(430,140,90,270,10);
arc(480,140,270,450,10);
outtextxy(110,180,"INPUT/OUTPUT SYMBOL");
line(430,170,480,170);
line(420,190,470,190);
line(430,170,420,190);
line(480,170,470,190);
outtextxy(110,220,"PROCESSING SYMBOL");
rectangle(430,210,500,240);
outtextxy(110,260,"DECISION SYMBOL");
line(450,250,420,280);
line(450,250,480,280);
line(420,280,450,310);
line(480,280,450,310);
outtextxy(110,340,"ON-PAGE CONNECTOR");
circle(450,350,25);
outtextxy(110,420,"FLOW-LINES");
line(430,440,460,440);
outtextxy(427,437,"<");
line(470,440,500,440);
outtextxy(497,437,">");
line(465,410,465,435);
outtextxy(462,407,"^");
line(465,445,465,470);
outtextxy(462,467,"v");
getch();
closegraph();
}
***********************OUTPUT**************************
******
.DFD Symbols
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\TURBOc3\\bgi");
settextstyle(1,0,1);
outtextxy(190,100,"DATA FLOW DIAGRAM SYMBOLS");
outtextxy(130,180,"External Entity");
rectangle(420,170,500,190);
outtextxy(130,250,"Process");
circle(450,260,20);
outtextxy(130,310,"Data Store");
line(400,310,470,310);
line(400,340,470,340);
outtextxy(130,370,"Data Flow");
line(400,380,467,380);
outtextxy(462,368,">");
getch();
closegraph();
}
*********************************OUTPUT****************
*************
.ER-Diagram
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
settextstyle(1,0,1);
outtextxy(220,50,"ER-DIAGRAM SYMBOL");
outtextxy(120,100,"Attribute");
ellipse(460,100,0,360,40,15);
outtextxy(120,160,"Entity");
rectangle(420,170,500,190);
outtextxy(130,220,"Multivalued Attribute");
ellipse(460,220,0,360,70,20);
ellipse(460,220,0,360,65,15);
outtextxy(130,300,"Relationship");
line(450,275,410,300);
line(410,300,450,323);
line(450,323,490,300);
line(490,300,450,275);
outtextxy(130,360,"Weak entity");
rectangle(390,335,515,380);
rectangle(395,340,510,375);
getch();
closegraph();
}
*******************************OUTPUT******************
***********
[Link] to implement Bresenhams Line Drawing Algorithm
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void DDA(int x1,int y1,int x2,int y2);
void main()
{
int gd=DETECT,gm;
int x1,x2,y1,y2;
initgraph(&gd,&gm,"c:\\TURBOc3\\bgi");
printf("\nEnter coordinates of 1 point=");
scanf("%d%d",&x1,&y1);
printf("\nEnter cooerdinate of 2 point=");
scanf("%d%d",&x2,&y2);
DDA(x1,y1,x2,y2);
getch();
closegraph();
}
void DDA(int x1,int y1,int x2,int y2)
{
int i,e,deltax,deltay;
deltax=x2-x1;
deltay=y2-y1;
e=2*deltay-deltax;
for(i=0;i<=deltax;i++)
{
putpixel(x1,y1,15);
if(e>0)
{
y1=y1+1;
e=e+(2*deltay-2*deltax);
}
else
{
e=e+2*deltay;
}
x1=x1+1;
}
}
****************************OUTPUT*********************
**************
[Link] to implement Bresenham’s circle Drawing Algorithm
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,x,y,r;
float x1,y1,p;
clrscr();
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
printf("\nEnter the radius=");
scanf("%d",&r);
x=getmaxx()/2;
y=getmaxy()/2;
x1=0;
y1=r;
p=3-(2*r);
while(x1<=y1)
{
x1=x1+0.1;
if(p<0)
{
p=p+(4*x1)+6;
}
else
{
y1=y1-0.1;
p=p+(4*(x1-y1))+10;
}
putpixel(x+x1,y+y1,10);
putpixel(x-x1,y-y1,10);
putpixel(x+x1,y-y1,10);
putpixel(x-x1,y+y1,10);
putpixel(x+y1,y+x1,10);
putpixel(x-y1,y-x1,10);
putpixel(x+y1,y-x1,10);
putpixel(x-y1,y+x1,10);
}
getch();
closegraph();
}
***********************OUTPUT**************************
******
[Link] DDA Line drawing algorithm
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void DDA(int x1,int y1,int x2,int y2);
void main()
{
int gd=DETECT,gm;
int x1,x2,y1,y2;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
printf("\nEnter coordinate of point 1=");
scanf("%d%d",&x1,&y1);
printf("\nEnter coordinate of point 2=");
scanf("%d%d",&x2,&y2);
DDA(x1,y1,x2,y2);
getch();
closegraph();
}
void DDA(int x1,int y1,int x2,int y2)
{
int length,i;
float x,y,xinc,yinc;
length=abs(x2-x1);
if(abs(y2-y1)>length)
{
length=abs(y2-y1);
}
xinc=(x2-x1)/length;
yinc=(y2-y1)/length;
x=x1+0.5;
y=y1+0.5;
for(i=1;i<=length;i++)
{
putpixel(x,y,6);
x=x+xinc;
y=y+yinc;
}
}
************************OUTPUT*************************
**************
[Link] translation transformation on polygon.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gd=DETECT,gm;
int x,y,x1,y1,x2,y2,tx,ty,a,b,c,d,e,f;
clrscr();
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
printf("\nEnter the first co-ordinate=");
scanf("%d%d",&x,&y);
printf("\nEnter the second co-ordinate=");
scanf("%d%d",&x1,&y1);
printf("\nEnter the third co-ordinate=");
scanf("%d%d",&x2,&y2);
outtextxy(x-10,y-20,"Before translation");
line(x,y,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x,y);
printf("Enter the value of tx and ty=");
scanf("%d%d",&tx,&ty);
a=x+tx;
b=y+ty;
c=x1+tx;
d=y1+ty;
e=x2+tx;
f=y2+ty;
line(a,b,c,d);
line(c,d,e,f);
line(e,f,a,b);
outtextxy(a-20,b-30,"After translation");
getch();
closegraph();
***************************OUTPUT**********************
***
[Link] scalling transformation on polygon.
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void main()
{
int driver=DETECT,mode;
int x,y,x1,y1, x2,y2,sx,sy,a,b,c,d,e,f;
clrscr();
initgraph(&driver,&mode,"c:\\tc\\bgi");
printf("Enter the first co-ordinate of point 1:");
scanf("%d%d",&x,&y);
printf("Enter the second co-ordinste of point 2:");
scanf("%d%d",&x1,&y1);
printf("Enter the third co-ordinate of point:");
scanf("%d%d",&x2,&y2);
outtextxy(10,y-20,"Before scalling");
line(x,y,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x,y);
printf("enter the value of sx and sy:");
scanf("%d%d",&sx,&sy);
a=x*sx;
b=y*sy;
c=x1*sx;
d=y1*sy;
e=x2*sx;
f=y2*sy;
line(a,b,c,d);
line(c,d,e,f);
line(e,f,a,b);
outtextxy(a+20,b-30,"after scalling");
getch();
closegraph();
}
****************************OUTPUT*********************
*******
[Link] rotation transformation on polygon.
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void main()
{
int driver=DETECT,mode;
int x1,y1,x2,y2,x,y,x4,y4,a,b,x3,y3;
clrscr();
initgraph(&driver,&mode,"c:\\tc\\bgi");
printf("Enter the first co-ordinate of point 1:");
scanf("%d%d",&x1,&y1);
printf("Enter the second co-ordinste of point 2:");
scanf("%d%d",&x2,&y2);
printf("Enter the third co-ordinate of point:");
scanf("%d%d",&x3,&y3);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
outtextxy(10,y1-20,"before rotation transformation");
getch();
x=x1*cos(45*3.14/180)+y1*sin(45*3.14/180);
y=-x1*sin(45*3.14/180)+y1*sin(45*3.14/180);
x4=x2*cos(45*3.4/180)+y2*sin(45*3.14/180);
y4=-x2*sin(45*3.14/180)+y2*sin(45*3.4/180);
a=x3*cos(45*3.4/80)+y3*cos(45*3.14/180);
b=-x3*sin(45*3.14/180)+y3*cos(45*3.13/180);
line(x,y,x4,y4);
line(x4,y4,a,b);
line(a,b,x,y);
outtextxy(x+50,y+30,"after roatation");
getch();
closegraph();
}
*****************OUTPUT******************************