• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

ProjectsGeek

Transformations computer graphics using C++ Language

April 5, 2011 by ProjectsGeek Leave a Comment

Transformations computer graphics on Geometric Figures using C++ Language

Write a program to Transformations computer graphics using C++ Language like ..

  • Rotation
  • Shear
  • Translation

Transformations computer graphics using C++ Language Code

 #include  
 #include  
 #include  
 #include  
 class transformation  
 {  
   int edge,v[50],sx,sy,input[20][3],scale[3][3],result[20][3],clk,midx,midy;  
   float ang,scale1[3][3],result1[20][3];  
   public:  
   void input1()  
   {  
     clrscr();  
     cout<<"\nENTER NO OF EDGES";  
     while(1)  
     {  
       cin>>edge;  
       if(edge<3)  
         cout<<"\nEDGE SHOULD NOT LESS THAN 3";  
       else  
         break;  
     }  
     cout<<"\nENTER VERTICES";  
     int j=0;  
     for(int i=0;i<edge;i++) <br="">     {  
       cout<<"x-cordinate";  
       cin>>v[j];  
       input[i][0]=v[j++];  
       cout<<"y-cordinate";  
       cin>>v[j];  
       input[i][1]=v[j++];  
       input[i][2]=1;  
     }  
   }  
   void display()  
   {  
     clrscr();  
     int j=0;  
     midx=getmaxx()/2;  
     midy=getmaxy()/2;  
     setcolor(WHITE);  
     line(0,midy,2*midx,midy);  
     line(midx,0,midx,2*midy);  
     setcolor(BLUE);  
     for(int i=0;i<edge;i++) <br="">     {  
       if(edge-i!=1)  
         line(v[j]+midx,midy-v[j+1],v[j+2]+midx,midy-v[j+3]);  
       else  
         line(v[j]+midx,midy-v[j+1],v[0]+midx,midy-v[1]);  
       j=j+2;  
     }  
     getch();  
   }  
   void display1()  
   {  
     int j=0;  
     midx=getmaxx()/2;  
     midy=getmaxy()/2;  
     setcolor(WHITE);  
     line(0,midy,2*midx,midy);  
     line(midx,0,midx,2*midy);  
     setcolor(GREEN);  
     for(int i=0;i<edge;i++) <br="">     {  
       if(edge-i!=1)  
         line(result[j][0]+midx,midy-result[j][1],result[j+1][0]+midx,midy-result[j+1][1]);  
       else  
         line(result[j][0]+midx,midy-result[j][1],result[0][0]+midx,midy-result[0][1]);  
       j=j+1;  
     }  
     getch();  
   }  
   void display2()  
   {  
     int j=0;  
     midx=getmaxx()/2;  
     midy=getmaxy()/2;  
     setcolor(WHITE);  
     line(0,midy,2*midx,midy);  
     line(midx,0,midx,2*midy);  
     setcolor(BLUE);  
     for(int i=0;i<edge;i++) <br="">     {  
       if(edge-i!=1)  
         line(result1[j][0]+midx,midy-result1[j][1],result1[j+1][0]+midx,midy-result1[j+1][1]);  
       else  
         line(result1[j][0]+midx,midy-result1[j][1],result1[0][0]+midx,midy-result1[0][1]);  
       j=j+1;  
     }  
     getch();  
   }  
   void refx()  
   {  
     scale[0][0]=1;  
     scale[0][1]=scale[1][0]=0;  
     scale[1][1]=-1;  
     scale[0][2]=scale[1][2]=scale[2][0]=scale[2][1]=0;  
     scale[2][2]=1;  
     multiply(input,scale,result);  
     display();  
     display1();  
   }  
   void refy()  
   {  
     scale[0][0]=-1;  
     scale[0][1]=scale[1][0]=0;  
     scale[1][1]=1;  
     scale[0][2]=scale[1][2]=scale[2][0]=scale[2][1]=0;  
     scale[2][2]=1;  
     multiply(input,scale,result);  
     display();  
     display1();  
   }  
   void refo()  
   {  
     scale[0][0]=-1;  
     scale[0][1]=scale[1][0]=0;  
     scale[1][1]=-1;  
     scale[0][2]=scale[1][2]=scale[2][0]=scale[2][1]=0;  
     scale[2][2]=1;  
     multiply(input,scale,result);  
     display();  
     display1();  
   }  
   void refxy()  
   {  
     scale[0][1]=1;  
     scale[0][0]=scale[1][1]=0;  
     scale[1][0]=1;  
     scale[0][2]=scale[1][2]=scale[2][0]=scale[2][1]=0;  
     scale[2][2]=1;  
     multiply(input,scale,result);  
     display();  
     display1();  
   }  
   void refxy1()  
   {  
     scale[0][1]=-1;  
     scale[0][0]=scale[1][1]=0;  
     scale[1][0]=1;  
     scale[0][2]=scale[1][2]=scale[2][0]=scale[2][1]=0;  
     scale[2][2]=1;  
     multiply(input,scale,result);  
     display();  
     display1();  
   }  
   void shear()  
   {  
     cout<<"SHEAR X FACTOR";  
     cin>>sx;  
     cout<<"SHEAR Y FACTOR";  
     cin>>sy;  
     scale[0][1]=sy;  
     scale[1][0]=sx;  
     scale[0][0]=scale[1][1]=1;  
     scale[0][2]=scale[1][2]=scale[2][0]=scale[2][1]=0;  
     scale[2][2]=1;  
     multiply(input,scale,result);  
     display();  
     display1();  
   }  
   void scal()  
   {  
     cout<<"SCALE X FACTOR";  
     cin>>sx;  
     cout<<"SCALE Y FACTOR";  
     cin>>sy;  
     scale[0][1]=scale[1][0]=0;  
     scale[0][0]=sx;  
     scale[1][1]=sy;  
     scale[0][2]=scale[1][2]=scale[2][0]=scale[2][1]=0;  
     scale[2][2]=1;  
     multiply(input,scale,result);  
     display();  
     display1();  
   }  
   void trans()  
   {  
     cout<<" X FACTOR";  
     cin>>sx;  
     cout<<" Y FACTOR";  
     cin>>sy;  
     scale[0][0]=scale[1][1]=scale[2][2]=1;  
     scale[0][1]=scale[0][2]=scale[1][0]=scale[1][2]=0;  
     scale[2][0]=sx;  
     scale[2][1]=sy;  
     multiply(input,scale,result);  
     display();  
     display1();  
   }  
   void rot()  
   {  
     cout<<"\nENTER THE ANGLE";  
     cin>>ang;  
     cout<<"\nENTER DIRECTION\n1. ANTICLOCKWISE\n2.CLOCKWISE";  
     cin>>clk;  
     scale1[0][0]=scale1[1][1]=cos((ang*3.14)/180);  
     scale1[0][2]=scale1[1][2]=scale1[2][0]=scale1[2][1]=0;  
     scale1[2][2]=1;  
     if(clk==1)  
     {  
       scale1[0][1]=sin((ang*3.14)/180);  
       scale1[1][0]=-sin((ang*3.14)/180);  
     }  
     else  
     {  
       scale1[0][1]=-sin((ang*3.14)/180);  
       scale1[1][0]=sin((ang*3.14)/180);  
     }  
     multiply1(input,scale1,result1);  
     display();  
     display2();  
   }  
   void rot1()  
   {    int x,y;  
     cout<<"\nENTER THE ANGLE";  
     cin>>ang;  
     cout<<"\nenter the x and y coordinates about which to rotate";  
     cin>>x;  
     cin>>y;  
     cout<<"\nENTER DIRECtION\nENTER 1 FOR ANTICLOCKWISE";  
     cin>>clk;  
     scale1[0][0]=scale1[1][1]=cos((ang*3.14)/180);  
     scale1[0][2]=scale1[1][2]=0;  
     scale1[2][0]=((-x)*cos((ang*3.14)/180)+y*sin((ang*3.14)/180)+y);  
     scale1[2][1]=((-x)*sin((ang*3.14)/180)-y*cos((ang*3.14)/180)+y);  
     scale1[2][2]=1;  
     if(clk==1)  
     {  
       scale1[0][1]=sin((ang*3.14)/180);  
       scale1[1][0]=-sin((ang*3.14)/180);  
     }  
     else  
     {  
       scale1[0][1]=-sin((ang*3.14)/180);  
       scale1[1][0]=sin((ang*3.14)/180);  
     }  
     multiply1(input,scale1,result1);  
     display();  
     display2();  
   }  
   void multiply(int input[][3],int b[][3],int result[][3])  
   {  
     int i=0;  
     for(i=0;i<edge;i++) <br="">     {  
       result[i][0]=input[i][0]*b[0][0]+input[i][1]*b[1][0]+input[i][2]*b[2][0];  
       result[i][1]=input[i][0]*b[0][1]+input[i][1]*b[1][1]+input[i][2]*b[2][1];  
       result[i][2]=input[i][0]*b[0][2]+input[i][1]*b[1][2]+input[i][2]*b[2][2];  
     }  
   }  
   void multiply1(int input[][3],float b1[][3],float result1[][3])  
   {  
     int i=0;  
     for(i=0;i<edge;i++) <br="">     {  
       result1[i][0]=input[i][0]*b1[0][0]+input[i][1]*b1[1][0]+input[i][2]*b1[2][0];  
       result1[i][1]=input[i][0]*b1[0][1]+input[i][1]*b1[1][1]+input[i][2]*b1[2][1];  
       result1[i][2]=input[i][0]*b1[0][2]+input[i][1]*b1[1][2]+input[i][2]*b1[2][2];  
     }  
   }  
 };  
 void main()  
 {  
   int gd=DETECT,gm;  
     initgraph(&gd,&gm,"c:\\tc\\bgi");  
   int ch;  
   transformation t;  
   do  
   {  
     clrscr();  
     cout<<"\n main menu";  
     cout<<"\n1.input";  
     cout<<"\n2.display";  
     cout<<"\n3.scaling";  
     cout<<"\n4.translation";  
     cout<<"\n5.rotation";  
     cout<<"\n6.reflection";  
     cout<<"\n7. shear";  
     cout<<"\n8. exit";  
     cout<<"\n enter ur choice";  
     cin>>ch;  
     switch(ch)  
     {  
       case 1:  
         cout<<"\ninput";  
         t.input1();  
         break;  
       case 2:  
         cout<<"\ndisplay";  
         t.display();  
         break;  
       case 3:  
         cout<<"\nscaling";  
         t.scal();  
         break;  
       case 4:  
         cout<<"\ntranslation";  
         t.trans();  
         break;  
       case 5:  
         int ch1;  
         do  
         {  
           clrscr();  
           cout<<"\nrotation\n1.about origin\n2.arbitary point\n3.return";  
           cin>>ch1;  
           switch(ch1)  
           {  
             case 1:  
               cout<<"\nabout origin";  
               t.rot();  
               break;  
             case 2:  
               cout<<"\narbitary point";  
               t.rot1();  
               break;  
             case 3:  
               break;  
           }  
         }while(ch1!=3);  
         break;  
       case 6:  
         do  
         {  
           clrscr();  
           cout<<"\n menu";  
           cout<<"\n1. reflection about x axix";  
           cout<<"\n2. reflection about y axix";  
           cout<<"\n3.reflection about origin";  
           cout<<"\n4.refletion about y=x line";  
           cout<<"\n5.reflection about y=-x line";  
           cout<<"\n6.exit";  
           cout<<"\n enter ur choice";  
           cin>>ch1;  
           switch(ch1)  
           {  
             case 1:  
               cout<<"\nreflection about x axix";  
               t.refx();  
               break;  
             case 2:  
               cout<<"\nreflection about y axix";  
               t.refy();  
               break;  
             case 3:  
               cout<<"\nreflection about origin";  
               t.refo();  
               break;  
             case 4:  
               cout<<"\nrefletion about y=x line";  
               t.refxy();  
               break;  
             case 5:  
               cout<<"\nreflection about y=-x line";  
               t.refxy1();  
               break;  
             case 6:  
               break;  
           }  
         }while(ch1!=6);  
         break;  
        case 7:  
         cout<<"\nshear";  
         t.shear();  
         break;  
        case 8:  
         break;  
     }  
   }while(ch!=8);  
 }

 

Other Projects to Try:

  1. Boundary and Flood Fill Algorithms in C++ Language
  2. Bressenham and DDA Line Drawing algorithms
  3. Operator Overloading on String Functions C++ Language
  4. Computer graphics codes in C++ Language
  5. Graphics Editor code Using C++ Language

Filed Under: Computer Graphics Tagged With: Computer Graphics

Operator Overloading on String Functions C++ Language

April 5, 2011 by ProjectsGeek Leave a Comment

Operator Overloading on String Functions C++ Language

Write a program to perform Operator Overloading on String Functions using C++ Language . String Operations like

  • Input String
  • Concatenation String
  • Reverse String
  • Display String
  • Equality String
  • String Copy

 All these Functions should be implemented by Operator Overloading on String Functions C++ Language .

  Operator Overloading on String Functions Code

 #include  
 #include  
 #include  
 #include  
 class sub;  
 class overlod  
 {  
   char *p;  
   int len;  
   public:  
   overlod()  
   {  
     len=0;  
     p=new char[20];  
   }  
   overlod(char *s)  
   {  
     len=strlen(s);  
     p=new char[len+1];  
   }  
   void input()  
   {  
     cout<<"\nENTER THE STRING";  
     cin>>p;  
   }  
   void operator<<(overlod s1)  
   {  
     cout<<s1.p; <br="">     getch();  
   }  
   friend overlod operator+(overlod &s,overlod &t)  
     {  
       overlod temp;  
       temp.len=s.len+t.len;  
       temp.p=new char[temp.len+1];  
       strcpy(temp.p,s.p);  
       strcat(temp.p,t.p);  
       return temp;  
     }  
   int operator=(overlod s2)  
   {  
     int i;  
     i=strcmp(p,s2.p);  
     return i;  
   }  
   void operator==(overlod s3)  
   {  
     len=strlen(s3.p);  
     p=new char[len+1];  
     strcpy(p,s3.p);  
   }  
   void operator>>(overlod s1)  
   {  
     strrev(s1.p);  
     cout<<s1.p; <br="">     getch();  
     strrev(s1.p);  
   }  
   int operator -()  
   {  
     int i=0,j;  
     j=strlen(p)-1;  
     for(i=0;i<=j;i++,j--)  
     {  
         if((*(p+i))!=(*(p+j)))  
           return 0;  
     }  
     return 1;  
   }  
 };  
 void main(void)  
 {  
   overlod s1,s2,s3;  
   int ch,i;  
   do  
   {  
     clrscr();  
     cout<<"\nSTRING OPERATION"<<"\n1.INPUT"<<"\n2.CONCATENATION"<<"\n3.REVERSE"<<"\n4.DISPLAY STRING"<<"\n5.EQUALITY"<<"\n6.STRING COPY"<<"\n7.PALLINDROME"<<"\n8.EXIT";  
     cout<<"\n ENTER UR CHOICE";  
     cin>>ch;  
     clrscr;  
     switch(ch)  
     {  
       case 1:  
         cout<<"\ninput";  
         s1.input();  
         s2.input();  
         break;  
       case 2:  
         cout<<"\nCONCATENATION OF STRING1 & STRING2 IS:";  
         s1<<s1+s2; <br="">         break;  
       case 3:  
         cout<<"\nREVERSE STRING OF STRING IS:";  
         s2>>s1;  
         break;  
       case 4:  
         cout<<"\nDISPLAYING STRING";  
         s2<<s1; <br="">         break;  
       case 5:  
         i=(s1=s2);  
         if(i!=0)  
           cout<<"NOT EQUAL";  
         else  
           cout<<"EQUAL";  
         getch();  
         break;  
       case 6:  
         cout<<"\nCOPIED STRING IS:";  
         s3==s1;  
         s2<<s3; <br="">         break;  
       case 7:  
         i=-s1;  
         if(i!=0)  
           cout<<"\nSTRING IS PALINDROME";  
         else  
           cout<<"\nSTRING IS NOT PALINDROME";  
         getch();  
         break;  
       case 8:break;  
       default:  
         cout<<"\nINVALID CHOICE";  
     }  
   }while(ch!=8);  
 }

 

Other Projects to Try:

  1. String Operations with Pointers
  2. String Operations in C Program
  3. Student Database using Virtual functions in C++
  4. String Operations in C Language
  5. How to append two strings in PHP | Simple ways

Filed Under: Computer Graphics Tagged With: Computer Graphics

Bressenham and DDA Line Drawing algorithms

April 5, 2011 by ProjectsGeek Leave a Comment

Bressenham DDA Line drawing and Circle Drawing Algorithms

Write a program for Bressenham and DDA Line Drawing algorithms using C++ language. Simulate these algorithms using C++ graphics classes and functions.
User has to provide input initially and then by selecting proper option user will get the output.

DDA Line Drawing algorithm Code

#include  
 #include  
 #include  
 #include  
 #include  
 class algo  
 {  
   float x1,x2,y1,y2;  
   public:  
   int sign(float a)  
   {  
   if(a>0)  
     return 1;  
   if(a<0)  
     return -1;  
   return 0;  
   }  
 void dda(float,float,float,float);  
 void br_line(float,float,float,float);  
 void br_c(float,float,float);  
 };  
 void main()  
 {  
   algo a;  
   int ch,gdriver=DETECT,gmode;  
   initgraph(&gdriver,&gmode,"c:\\tc\\bgi");  
   do  
   {  
     cleardevice();  
     cout<< "\n\t\t\t#### MAIN MENU ####";  
     cout<< "\n\t\t1.DDA LINE DRAWING ALGORITHM";  
     cout<< "\n\t\t2.BRESENHAM LINE DRAWIG ALGORITHM";  
     cout<< "\n\t\t3.BRESENHAM CIRCLE DRAWNG ALGORITHM";  
     cout<< "\n\t\t4.EXIT";  
     cout<< "\n\t\tENTER UR CHOICE:";  
     cin>> ch;  
     clrscr();  
     switch(ch)  
     {  
       case 1:  float x2,x1,y2,y1;  
         cout<< "\n\t\tDDA LINE DRAWING ALGO";  
         cout<< "\n\tEnter (x1,y1) co-ordinates of first point:";  
         cin>>x1>>y1;  
         cout<< "\n\tEnter (x2,y2) co-ordinates. of last point:";  
         cin>>x2>>y2;  
         a.dda(x1,y1,x2,y2);  
         getch();  
         break;  
       case 2:  cout<< "\n\t\tBRESENHAM LINE DRAWIG ALGO";  
         cout<< "\n\tEnter (x1,y1) co-ordinates of first point";  
         cin>>x1>>y1;  
         cout<< "\n\tEnter (x2,y2) co-ordinates of end point";  
         cin>>x2>>y2;  
         a.br_line(x1,y1,x2,y2);  
         getch();  
         break;  
       case 3:  cout<< "\n\t\tBRESENHAM CIRCLE DRAWNG ALGO";  
         cout<< "\n\tEnter center co-ordinates.";  
         cin>>x1>>y1;  
         float r;  
         cout<< "\n\tEnter radius";  
         cin>>r;  
         a.br_c(x1,y1,r);  
         getch();  
         break;  
       case 4:  break;  
       default:cout<< "\t\tInvalid Choice\n";  
         getch();  
         break;  
     }  
   }while(ch!=4);  
   closegraph();  
 }  
 void algo:: dda(float x1,float y1,float x2,float y2)  
 {  
   float dx,dy,len,i,xn,yn,x,y,midx,midy;  
   midx=getmaxx()/2;  
   midy=getmaxy()/2;  
   line(0,midy,2*midx,midy);  
   line(midx,0,midx,2*midy);  
   x1+=midx;  
   y1=-y1;  
   y1+=midy;  
   x2+=midx;  
   y2=-y2;  
   y2+=midy;  
   dx=abs(x2-x1);  
   dy=abs(y2-y1);  
   if(dx>=dy)  
     len=dx;  
   else  
     len=dy;  
   dx=(x2-x1)/len;  
   dy=(y2-y1)/len;  
   x=x1+0.5*sign(dx);  
   y=y1+0.5*sign(dy);  
   putpixel(x,y,WHITE);  
   i=1;  
   while(i<=len)  
   {  
     putpixel(x,y,RED);  
     x=x+dx;  
     y=y+dy;  
     i++;  
   }  
   getch();  
 }  
 void algo:: br_line(float x1,float y1,float x2,float y2)  
 {  
   float dx,dy,s1,s2,e,i,change,x,y,midx,midy,x3,y3,exch;  
   midx=getmaxx()/2;  
   midy=getmaxy()/2;  
   line(0,midy,2*midx,midy);  
   line(midx,0,midx,2*midy);  
   x1+=midx;  
   y1=-y1;  
   y1+=midy;  
   x2+=midx;  
   y2=-y2;  
   y2+=midy;  
   x=abs(x2-x1);  
   y=abs(y2-y1);  
   x3=x1;  
   y3=y1;  
   s1=sign(x2-x1);  
   s2=sign(y2-y1);  
   e=2*y-x;  
   if(y>x)  
   {  
     int temp=x;  
     x=y;  
     y=temp;  
     exch=1;  
   }  
   else  
     exch=0;  
   i=1;  
   while(i<=x)  
   {  
     putpixel(x3,y3,WHITE);  
     while(e>=0)  
     {  
       if(exch==1)  
         x3+=s1;  
       else  
         y3+=s2;  
       e=e-2*x;  
     }  
     if(exch==1)  
       y3+=s2;  
     else  
       x3+=s1;  
     e=e+2*y;  
     i++;  
   }  
 }  
 void algo:: br_c(float a,float b,float r)  
 {  
   float d,x,y,midx,midy;  
   midx=getmaxx()/2;  
   midy=getmaxy()/2;  
   line(0,midy,2*midx,midy);  
   line(midx,0,midx,2*midy);  
   x+=midx;  
   y=-y;  
   y+=midy;  
   x1=0,y1=r;  
   d=3-2*r;  
   while(x1<=y1)  
   {  
     if(d<0)  
     {  
       d=d+4*x1+6;  
     }  
     else  
     {  
       d=d+4*(x1-y1)+10;  
       y1=y1-1;  
     }  
     x1=x1+1;  
     putpixel(x1+a+(getmaxx()/2),y1+b+(getmaxy()/2),BLUE);  
     putpixel(y1+a+(getmaxx()/2),x1+b+(getmaxy()/2),BLUE);  
     putpixel(-x1+a+(getmaxx()/2),-y1+b+(getmaxy()/2),BLUE);  
     putpixel(-x1+a+(getmaxx()/2),y1+b+(getmaxy()/2),BLUE);  
     putpixel(y1+a+(getmaxx()/2),-x1+b+(getmaxy()/2),BLUE);  
     putpixel(-y1+a+(getmaxx()/2),x1+b+(getmaxy()/2),BLUE);  
     putpixel(x1+a+(getmaxx()/2),-y1+b+(getmaxy()/2),BLUE);  
     putpixel(-y1+a+(getmaxx()/2),-x1+b+(getmaxy()/2),BLUE);  
   }  
 }

 

 

Other Projects to Try:

  1. Graphics Editor code Using C++ Language
  2. Transformations computer graphics using C++ Language
  3. Matrix Operations in C Language
  4. Friend Function Implementation using C++
  5. Boundary and Flood Fill Algorithms in C++ Language

Filed Under: Computer Graphics Tagged With: Computer Graphics

Graphics Editor code Using C++ Language

April 5, 2011 by ProjectsGeek Leave a Comment

Graphics Editor code Using C++ Language

Write a Graphics Editor program to develop a graphics editor which includes features like  line draw, rectangle draw,circle draw, pie chart draw,ellipse draw,polygon draw,bard raw, pixel draw,text draw etc.

Graphics Editor have a menu for user interaction from which user can provide input to program.By selecting appropriate option user will get output.

 

Graphics Editor code

 

 
 #include  
 #include  
 #include  
 #include  
 #include  
 class figures  
 {  
   int x1,y1,x2,y2,rad,xrad,yrad,startang,endang,midx,midy;  
   public:  
   figures()  
   {  
     x1=0;  
     y1=0;  
     x2=0;  
     y2=0;  
     rad=0;  
     xrad=0;  
     startang=0;  
     endang=0;  
     midx=getmaxx();  
     midy=getmaxy();  
   }  
       ~figures()  
   {  
   void linedraw(void);  
   void rectangledraw(void);  
   void circledraw(void);  
   void piechartdraw();  
   void ellipsedraw(void);  
   void polygondraw(void);  
   void bardraw(void);  
   void pixeldraw(void);  
   void textdraw(void);  
 };  
 void figures::linedraw(void)  
 {  
   int gd=DETECT,gm;  
   cout<<"x1 is ";  
   cin>>x1;  
   cout<<"y1 is ";  
   cin>>y1;  
   cout<<"x2 is ";  
   cin>>x2;  
   cout<<"y2 is ";  
   cin>>y2;  
   getch();  
   clrscr();  
   initgraph(&gd,&gm,"c:\\tc\\bgi");  
   midx=getmaxx()/2;  
   midy=getmaxy()/2;  
   setcolor(4);  
   outtextxy(20+x1,20+y1,"A LINE");  
   line(0,midy,midx*2,midy);  
   line(midx,0,midx,2*midy);  
   setcolor(YELLOW);  
   line(x1+midx,midy-y1,x2+midx,midy-y2);  
   getch();  
   cleardevice();  
   closegraph();  
 }  
 void figures::rectangledraw(void)  
 {  
   int gd=DETECT,gm;  
   cout<<"x1 is ";  
   cin>>x1;  
   cout<<"y1 is ";  
   cin>>y1;  
   cout<<"x2 is ";  
   cin>>x2;  
   cout<<"y2 is ";  
   cin>>y2;  
   getch();  
   clrscr();  
   initgraph(&gd,&gm,"c:\\tc\\bgi");  
   midx=getmaxx()/2;  
   midy=getmaxy()/2;  
   setcolor(4);  
   outtextxy(20+x1,20+y1,"A RECTANGLE");  
   line(0,midy,midx*2,midy);  
   line(midx,0,midx,2*midy);  
   setcolor(YELLOW);  
   rectangle(x1+midx,midy-y1,x2+midx,midy-y2);  
   getch();  
   cleardevice();  
   closegraph();  
 }  
 void figures::circledraw(void)  
 {  
   int gd=DETECT,gm;  
   cout<<"CENTER POINTS"<<endl; <br="">   cout<<"x1 is ";  
   cin>>x1;  
   cout<<"y1 is ";  
   cin>>y1;  
   cout<<"r is ";  
   cin>>rad;  
   getch();  
   clrscr();  
   initgraph(&gd,&gm,"c:\\tc\\bgi");  
   midx=getmaxx()/2;  
   midy=getmaxy()/2;  
   setcolor(4);  
   outtextxy(20+x1,20+y1,"A CIRCLE"); //use setaspestratio  
   setcolor(YELLOW);  
   line(0,midy,midx*2,midy);  
   line(midx,0,midx,2*midy);  
   setcolor(YELLOW);  
   circle(x1+midx,midy-y1,rad);  
   getch();  
   cleardevice();  
   closegraph();  
 }  
 void figures::ellipsedraw()  
 {  
   int gd=DETECT,gm;  
   cout<<"CENTER POINTS"<<endl; <br="">   cout<<"x1 is ";  
   cin>>x1;  
   cout<<"y1 is ";  
   cin>>y1;  
   cout<<"horizontal axis is ";  
   cin>>xrad;  
   cout<<"vertical axis is ";  
   cin>>yrad;  
   cout<<"starting angle is ";  
   cin>>startang;  
   cout<<"ending angle is ";  
   cin>>endang;  
   getch();  
   clrscr();  
   initgraph(&gd,&gm,"c:\\tc\\bgi");  
   midx=getmaxx()/2;  
   midy=getmaxy()/2;  
   setcolor(4);  
   outtextxy(20+x1,20+y1,"AN ELLIPSE");  
   line(0,midy,midx*2,midy);  
   line(midx,0,midx,2*midy);  
   setcolor(YELLOW);  
   ellipse(x1+midx,midy-y1,startang,endang,xrad+midx,midy-yrad);  
   getch();  
   cleardevice();  
   closegraph();  
 }  
 void figures::piechartdraw(void)  
 {  
   int gd=DETECT,gm,d=0,i,sum=0;  
   int a[10];  
   cout<<"how many data you want to enter"<<endl; <br="">   cin>>d;  
   for(i=0;i<d-1;i++) <br="">   {  
     cout<<"percentage of data  "<<i+1<<" =="<<endl;  
     cin>>a[i];  
     sum=sum+a[i];  
   }  
   a[i]=100-sum;  
   cout<<" percentage="" of="" data="" "<<i+1<<"="=" "<<100-sum<<endl;="" <br="">   getch();  
   clrscr();  
   initgraph(&gd,&gm,"c:\\tc\\bgi");  
   midx=getmaxx()/2;  
   midy=getmaxy()/2;  
   setcolor(4);  
   outtextxy(20+x1,20+y1,"A PIECHART");  
   line(0,midy,midx*2,midy);  
   line(midx,0,midx,2*midy);  
   startang=0;  
   endang=0;  
   for(i=0;i<d;i++) <br="">   {  
     startang=endang;  
     endang=startang+(a[i]*360)/100;  
     setfillstyle(SOLID_FILL,i+3);  
     pieslice(midx,midy,startang,endang,150);  
   }  
   getch();  
   cleardevice();  
   closegraph();  
 }  
 void figures::polygondraw()  
 {  
   int gd=DETECT,gm;  
   int poly[20],i=0;  
   char other;  
   cout<<"Enter vertices of the polygon"<<endl; <br="">   do  
   {  
     cout<<"x is ";  
     cin>>poly[i];  
     poly[i]=poly[i]+318;  
     i++;  
     cout<<"y is ";  
     cin>>poly[i];  
     poly[i]=-poly[i]+237;  
     i++;  
     cout<<endl<<"want to="" enter="" again";="" <br="">     cin>>other;  
   }while(other=='y');  
   //closing polygon  
   poly[i++]=poly[0];  
   poly[i]=poly[1];  
   clrscr();  
    i=(i+1)/2;  
   initgraph(&gd,&gm,"c:\\tc\\bgi");  
   midx=getmaxx()/2;  
   midy=getmaxy()/2;  
   setcolor(RED);  
   line(0,midy,midx*2,midy);  
   line(midx,0,midx,2*midy);  
   setfillstyle(SOLID_FILL,GREEN);  
    //use fillpoly to fill color  
    fillpoly(i,poly);//drawpoly(number of point we have entered,array);  
    getch();  //includes closing point also therefore i+1  
   cleardevice();  
   closegraph();  
 }  
 void figures::bardraw()  
 {  
   int gd=DETECT,gm,d=0,i,a[10],sum=0;  
     cout<<"how many data you want to enter"<<endl; <br="">   cin>>d;  
   for(i=0;i<d-1;i++) <br="">   {  
     cout<<"percentage of data  "<<i+1<<" =="<<endl;  
     cin>>a[i];  
         sum=sum+a[i];  
   }  
     a[i]=100-sum;  
     cout<<" percentage="" of="" data="" "<<i+1<<"="=" "<<100-sum<<endl;="" <br="">     getch();  
     clrscr();  
   initgraph(&gd,&gm,"c:\\tc\\bgi");  
   midx=getmaxx()/2;  
   midy=getmaxy()/2;  
   setcolor(4);  
   outtextxy(20+x1,20+y1,"A BARGRAPH");  
   line(0,midy,midx*2,midy);  
   line(midx,0,midx,2*midy);  
     for(i=0;i<d;i++) <br="">   {  
         setfillstyle(SOLID_FILL,i+3);  
         bar(45*(i+1)+midx,midy-((a[i]*100)/100),midx+(45*(i+1))+20,midy);    //(width,height,dist from y axis,bottom down)  
   }  
   getch();  
   cleardevice();  
   closegraph();  
 }  
 void figures::pixeldraw(void)  
 {  
   int gd=DETECT,gm;  
   cout<<"x1 is ";  
   cin>>x1;  
   cout<<"y1 is ";  
   cin>>y1;  
   getch();  
   clrscr();  
   initgraph(&gd,&gm,"c:\\tc\\bgi");  
   midx=getmaxx()/2;  
   midy=getmaxy()/2;  
   setcolor(4);  
   outtextxy(20+x1,20+y1,"A PIXEL");  
   line(0,midy,midx*2,midy);  
   line(midx,0,midx,2*midy);  
   setcolor(YELLOW);  
   outtextxy(midx+x1,midy-y1,"(x1,y1)");  
   putpixel(midx+x1,midy-y1,YELLOW);  
   getch();  
   cleardevice();  
   closegraph();  
 }  
 void figures::textdraw() //graphics textstyle //cprintf  
 {  
   int gd=DETECT,gm;  
   initgraph(&gd,&gm,"c:\\tc\\bgi");  
   for(int i=0;i<4;i++)  
   {  
     textmode(i);  
     cout<<"C";  
     getch();  
   }  
   closegraph();  
 }  
 void main(void)  
 {  
   figures draw;  
   int ch,ch1,i,n;  
   clrscr();  
   do  
   {  
     clrscr();  
     draw.menu();  
     cin>>ch;  
     switch(ch)  
     {  
       case 1:  
         clrscr();  
         cout<<"HOW MANY LINE U WANT:";  
         cin>>n;  
         for(i=0;i<n;i++) <br="">           draw.linedraw();  
         break;  
       case 2:  
         clrscr();  
         cout<<"HOW MANY LINE U WANT:";  
         cin>>n;  
         for(i=0;i<n;i++) <br="">           draw.circledraw();  
         break;  
       case 3:  
         clrscr();  
         draw.ellipsedraw();  
         break;  
       case 4:  
         clrscr();  
         draw.piechartdraw();  
         break;  
       case 5:  
         clrscr();  
         draw.polygondraw();  
         break;  
       case 6:  
         clrscr();  
         draw.bardraw();  
         break;  
       case 7:  
         cout<<"HOW MANY LINE U WANT:";  
         cin>>n;  
         for(i=0;i<n;i++) <br="">           draw.pixeldraw();  
         break;  
       case 8:  
         draw.rectangledraw;  
         break;  
       case 9:  
         draw.textdraw();  
         break;  
       case 10:  
         break;  
       default:  
         cout<<"\nINVALID CHOICE";  
         }  
     }while(ch!=9);  
 getch();  
 }

 

 

Other Projects to Try:

  1. Transformations computer graphics using C++ Language
  2. Boundary and Flood Fill Algorithms in C++ Language
  3. Bressenham and DDA Line Drawing algorithms
  4. Matrix Operations in C Language
  5. Text or Screen Editor in C++ Language

Filed Under: Computer Graphics Tagged With: Computer Graphics

Weather report program in c++ using constructor

April 5, 2011 by ProjectsGeek Leave a Comment

Weather report program in c++ using constructor

Create a class named weather report that holds a daily weather report with data members dayofmonth,high temp , low temp ,amount rain and amount snow.The constructor initializes the fields with default values. Weather report program in c++ using constructor Includes a function that prompts the user and sets values for each field so that you can override the default values.

Write a program Weather report program in c++ using constructor that creates a monthly report.

 Weather report program in c++ using constructor Code

 

 #include  
 #include  
 #include  
 class ping  
 {  
     int day,snowfall,rainfall,lowtemp,hightemp;  
     public:  
       static int count ;         
       ping();            
       ping(int,int,int,int,int);      
       ping::ping(ping &z)         
       {  
         day=z.day;  
         hightemp=z.hightemp;  
         lowtemp=z.lowtemp;  
         snowfall=z.snowfall;  
         rainfall=z.rainfall;  
       }  
       int dayno();  
       void daily();  
       void copy(int,int,int,int,int) ;  
       void change(int );  
 };  
 int ping::count ;  
 ping::ping()  
 {  
     day=99;  
     hightemp=999;  
     lowtemp=-999;  
     snowfall=0;  
     rainfall=0;  
     cout<< "\t\t\tRecord created\n";  
 }  
 void ping::change(int dom)  
 {  
   day=dom;  
 }  
 ping::ping(int dom,int ht,int lt,int s,int r)  
 {  
     day= dom;  
     hightemp=ht;  
     lowtemp=lt;  
     snowfall=s;  
     rainfall=r;  
 }  
 void ping::daily()  
 {  
     cout << "\t ";  
     cout << hightemp << "\t\t ";  
     cout << lowtemp << "\t ";  
     cout << snowfall << "\t ";  
     cout << rainfall << "\t ";  
 }  
 int ping::dayno()  
 {  
     return day;  
 }  
 void main()  
 {  
     int ch,i=0,j,flag=0;  
     int k,temp;  
     ping *array[31];  
     do  
       {  
         clrscr();  
         cout << "\t\t\t\t***Main Menu***\n";  
         cout << "\t\t\t\t1.Create Daily Report\n";  
         cout << "\t\t\t\t2.Display Daily Report\n";  
         cout << "\t\t\t\t3.Display Monthly Report\n";  
         cout << "\t\t\t\t4.Delete a record\n";  
         cout << "\t\t\t\t5.Exit\n";  
         cout << "\t\t\t\tEnter your choice:\n";  
         cin >> ch;  
         switch(ch)  
           {  
               case 1:  
                   do  
                   {  
                     int dom;  
                     temp=0 ;  
                     cout<<"\n\t\tEnter date of month: ";  
                     cin>>dom;  
                     array[i]->count++;  
                     if(array[i]->count>1)  
                     {  
                           cout <<"\nDO U WANT TO COPY DATA FROM PREVIOUS DAY (y/n)";  
                           if(getche()=='y'||getche()=='Y')  
                           {  
                                 array[i]=new ping;  
                                 *array[i]=*array[i-1];  
                                 array[i]->change(dom);  
                                 i=i+1;  
                                 temp=1;  
                           }  
                     }  
                     if(temp==0)  
                     {  
                         int ht ;  
                         cout << "\tEnter maximum temperature: ";  
                         cin >> ht;  
                         int lt;  
                         cout << "\tEnter the minimum temperature: ";  
                         cin >> lt;  
                         int s;  
                         cout << "\tEnter amount of snowfall: ";  
                         cin >> s;  
                         int r;  
                         cout << "\tEnter amount of rainfall: ";  
                         cin >> r ;  
                         array[i++]=new ping(dom,ht,lt,r,s);  
             }  
             cout<<"\n\t\tDO U WANT TO ENTER MORE:";  
         }while(getche()=='y'||getche()=='Y');  
           break;  
       case 2:  
           cout << "\t\t\tDisplay Daily Report\n";  
           cout << "\tEnter the day to be viewed: ";  
           cin>>k;  
           for(j=0;j<i;j++) <br="">             if(array[j]->dayno()==k)  
             {  
               cout<<"\n\n   Day Temperature  AmtRain AmtSnow";  
               cout<<"\n"<<"     ";  
               array[j]->daily();  
               getch();  
               break;  
             }  
           if(j==i)  
           {  
             cout<<"\nRecord not found ";  
             cout<<"\nNOT AVAILABLE";  
             getch();  
           }  
           break;  
       case 3:  
           clrscr();  
           cout<<"\n\t\tWEATHER REPORT";  
           if(i==0)  
           {  
             cout<<"\n\nRecord not found...";  
             break;  
           }  
           else  
             cout<<"\n\n   Day Temperature  AmtRain AmtSnow";  
             cout<<"\n"<<"     ";  
           for(j=0;j<i;j++) <br="">           {  
             cout<<"\n"<<"     ";  
             array[j]->daily();  
           }  
           getch();  
           break;  
           break;  
       case 4:  
           cout<<"\nENTER THE DATE WHICH U WANT TO DELETE:";  
           int dom;  
           cin>>dom;  
           for(j=0;j<i;j++) <br="">           {  
               if(array[j]->dayno()==dom)  
               {  
                 delete array[j];  
                 while(j<i) <br="">                 {  
                   array[j]=array[j+1];  
                   j++;  
                 }  
                 j--;  
                 break;  
               }  
             }  
             if(j==i)  
               cout<<"\nDATE IS NOT FOUND";  
             else  
               {  
                 array[i]->count--;  
                 i--;  
               }  
               break;  
       case 5 :  
           break ;  
       default:  
           cout<< " \t\tWrong choice...Enter again\n ";  
     }  
   }while(ch!=5);  
 }

 

Other Projects to Try:

  1. Friend Function Implementation using C++
  2. Matrix Operations in C Language
  3. Operator Overloading on String Functions C++ Language
  4. Exception Handling in C++ Language
  5. Bressenham and DDA Line Drawing algorithms

Filed Under: Computer Graphics Tagged With: Computer Graphics

Factorial,Greatest Number, Palindrome AWK

April 4, 2011 by ProjectsGeek 2 Comments

 

Factorial,Greatest Number,Palindrome String  using AWK Programming


Write a Menu driven program using AWK Programming for

 

a) Find factorial of a number.

b) Find greatest of three numbers

c) Find a prime numbers.

d) Find whether a number is palindrome

e) Find whether a string is palindrome

 f) Exit.

Factorial,Greatest Number,Palindrome AWK Programming Code

 

 

BEGIN{  
   print"main menu" ;  
   print"1.factorial of number" ;  
   print"2.greatest of numbers" ;  
   print"3.prime number" ;  
   print"4.palindrome of number" ;  
   print"5.palindrome of string" ;  
   print"enter ur choice" ;  
   getline ch<"-" ;  
   print ch ;  
   if(ch==1)  
   {  
    print "enter the number" ;  
    getline tmp<"-" ;  
    c=1 ;  
    while(tmp != 0)  
    {  
     c=c*tmp ;  
     tmp-- ;  
     }  
    print c ;  
    }  
   if(ch==2)  
   {  
    print "enter first number" ;  
    getline a1<"-" ;  
    print "enter second number" ;  
    getline a2<"-" ;  
    print "enter third number" ;  
    getline a3<"-" ;  
    if(a1>a2 && a1>a3)  
    print "first number is greater " ;  
    if(a2>a1 && a2>a3)  
    print "second number is greater " ;  
    if(a3>a1 && a3>a2)  
    print "third number is greater " ;  
    }  
    if(ch==3)  
    {  
     print "enter the number" ;  
     getline tmp<"-" ;  
     if(tmp==1)  
     print "not prime number" ;  
     i=tmp-1 ;  
     while(i > 1)  
     {  
      a=tmp%i ;  
      i--;  
      if(a == 0)  
      {  
       print "not prime number" ;  
       break ;      
      }  
     }  
      if(i==1)  
      print "prime number " ;  
     }  
     if(ch==4)  
     {  
      print "enter the number" ;  
      getline tmp<"-" ;  
      sd=0 ;  
      rev=" " ;  
      on=tmp ;  
      n=length(tmp)-1 ;  
      while(tmp != 0)  
      {  
        sd=tmp % 10 ;  
        tmp=tmp / 10;  
        rev=rev+(sd*(10^n)) ;  
        n-- ;  
       }  
      print rev ;  
      if(on == rev)  
       print "palindrome" ;  
      else  
      print "not palindrome" ;  
     }  
     if(ch==5)  
     {  
      print "enter the number" ;  
      getline tmp<"-" ;  
      p = ""  
      for(i=length(tmp); i > 0; i--) { p = p substr(tmp, i, 1) }  
      print p  
      if(p == tmp )  
      print "palindrome " ;  
      else  
      print "not palindrome" ;      
     }  
 }

 

Other Projects to Try:

  1. Factorial,Greatest Number,String Palindrome Shell code
  2. Student Database using AWK Programming
  3. string operations such as Copy, Length, Reversing, Palindrome, Concatenation
  4. Implement using Socket Programming (TCP/UDP) in Java
  5. Factorial of a number using recursion in C

Filed Under: Operating System . Linux Assignments

  • « Go to Previous Page
  • Page 1
  • Interim pages omitted …
  • Page 130
  • Page 131
  • Page 132
  • Page 133
  • Page 134
  • Page 135
  • Go to Next Page »

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy