Write a program to scale a figure given by user. Options for the users are circle, triangle or rectangle.

#include<stdio.h>
#include<conio.h>
#include<graphics.h>

void Triangle(int, int, int, int, int, int);
//int midx=319, midy=239;

void  main()
{
  int gdriver=DETECT, gmode, c,r,x1,y1,x2,y2,x3,y3;
  float S,Sx,Sy;
  initgraph(&gdriver,&gmode,"c:\\tc\\bgi");

  clrscr();
  cleardevice();

  printf("1.Circle \n2.Triangle \n3.Rectangle \n\n");
  printf("Enter the choice : ");
  scanf("%d",&c);
  clrscr();
  cleardevice();

  switch(c)
  {
        case 1:
              printf("Enter the value of center (x1,y1) : ");
              scanf("%d %d",&x1,&y1);
              printf("Enter the Radius of the circle r : ");
              scanf("%d",&r);
              printf("Enter the scaling Factor S : ");
              scanf("%f",&S);
              circle(x1,y1,r);
              //    line(0,midy,2*midx,midy);
              //    line(midx,0,midx,2*midy);
              getch();    setcolor(4);
              circle(x1,y1,r*S);
              break;

        case 2:
              printf("Enter the value of (x1,y1) : ");
              scanf("%d %d",&x1,&y1);
              printf("Enter the value of (x2,y2) : ");
              scanf("%d %d",&x2,&y2);
              printf("Enter the value of (x3,y3) : ");
              scanf("%d %d",&x3,&y3);
              printf("Enter the scaling Factor (Sx,Sy) : ");
              scanf("%f %f",&Sx,&Sy);
              //    line(0,midy,2*midx,midy);
              //    line(midx,0,midx,2*midy);
              Triangle(x1,y1,x2,y2,x3,y3);
              getch();    setcolor(4);
              Triangle(x1*Sx,y1*Sy,x2*Sx,y2*Sy,x3*Sx,y3*Sy);
              break;

  case 3:
        printf("Enter the top-left point of the rectangle : ");
        scanf("%d %d",&x1,&y1);
  printf("\n\nEnter the bottom-right point of the rectangle : ");
              scanf("%d %d",&x2,&y2);
              printf("Enter the scaling Factor (Sx,Sy) : ");
              scanf("%f %f",&Sx,&Sy);
             //     line(0,midy,2*midx,midy);
            //      line(midx,0,midx,2*midy);
              rectangle(x1,y1,x2,y2);
              getch();    setcolor(4);
              rectangle(x1*Sx,y1*Sy,x2*Sx,y2*Sy);
              break;
  }
  getch();
  closegraph();
}

void Triangle(int x1, int y1, int x2, int y2, int x3, int y3)
{
  line(x1,y1,x2,y2);
  line(x2,y2,y3,y3);
  line(x3,y3,x1,y1);
}

Read more...

Write a program to rotate a wheel clockwise or anticlockwise as per user’s choice.


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
          
#define R 3.14/180

void drawline(int, int, int , int, int);

void main()
{
int gdriver=DETECT, gmode,i,d,ch,x,y,r;
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
cleardevice();

x=getmaxx()/2,    y=getmaxy()/2;
printf("Enter the Radius of the circle : ");
scanf("%d",&r);
printf("\n\n1.Clockwise -> Up-Arrow Key   \n2.Anticlockwise -> Down-Arrow Key");
printf("\n\nEnter the Direction of circle rotation : ");
ch = getch();

for(i=0 ; ; i++)
{
       if(kbhit())
       {
             ch = getch();
             if (ch == 72)
                   d = 1;
             else if (ch == 80)
                   d = -1;
             else if (ch == '\x1B')
                   exit(0);
       }
       drawline(x,y,r,d*i,15);
       circle(x,y,r);
       delay(300);
       drawline(x,y,r,d*i,0);
}
}
void drawline(int x, int y, int r, int a, int c)
{
setcolor(c);
line(x+r*cos(0*R+a),y+r*sin(0*R+x+r*cos(180*R+a),y+r*sin(180*R+a);
line(x+r*cos(45*R+a),y+r*sin(45*R+a),x+r*cos(225*R+a),y+r*sin(225*R+a);
line(x+r*cos(90*R+a), y+r*sin(90*R+a), x+r*cos(270*R+a),y+r*sin(270*R+a));
line(x+r*cos(135*R+a),y+r*sin(135*R+a),x+r*cos(315*R+a),y+r*sin(315*R+a));
}

Read more...

Top Down Parsing in Complier Design Source Code Programming

First include the package and Necessary variable. I use the following function int parse::scannt(char a), void parse::input(),int parse::scant(char b), void parse::process(),void parse::input(), To perform the operation Processing.
Compiler Design Source code Programming
#include<iostream.h>
#include<conio.h>
#include<string.h>
class parse
{
int nt,t,m[20][20],i,s,n,p1,q,k,j;
char p[30][30],n1[20],t1[20],ch,b,c,f[30][30],fl[30][30];
public:
int scant(char);
int scannt(char);
void process();
void input();
};

int parse::scannt(char a)
{
int c=-1,i;
for(i=0;i<nt;i++)
{
if(n1[i]==a)
{
return i;
}
}
return c;
}

int parse::scant(char b)
{
int c1=-1,j;
for(j=0;j<t;j++)
{
if(t1[j]==b)
{
return j;
}
}
return c1;
}


void parse::input()

{
cout<<"Enter the number of productions:";
cin>>n;
cout<<"Enter the productions one by one"<<endl;
for(i=0;i<n;i++)
cin>>p[i];
nt=0;
t=0;
}

void parse::process()
{
for(i=0;i<n;i++)
{
if(scannt(p[i][0])==-1)
n1[nt++]=p[i][0];
}
for(i=0;i<n;i++)
{
for(j=3;j<strlen(p[i]);j++)
{
if(p[i][j]!='e')
{
if(scannt(p[i][j])==-1)
{
if((scant(p[i][j]))==-1)
t1[t++]=p[i][j];
}
}
}

Read more...
Related Posts Plugin for WordPress, Blogger...

Engineering material

GTU IDP/ UDP PROJECT

GTU IDP/ UDP PROJECT

Patel free software download

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP