• 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

Computer Graphics

Matrix Operations in C Language

April 6, 2011 by ProjectsGeek Leave a Comment

Matrix Operations in C Language

Implement following Matrix operations as Given Below: 

  • Addition with arrays.
  • Multiplication without pointers to arrays
  • Transpose with  arrays
  • Saddle point without pointers to arrays

Matrix Operations in C Code

#include  
 #include  
 template  
 class matrix  
 {  
   public:  
   T mat[10][10];  
   int i;  
   matrix()  
   {  
     cout<<"\n\tMATRIX IS:";  
     for(i=0;i<m;i++) <br="">       for(j=0;j<n;j++) <br="">         mat[i][j]=0;  
   }  
   matrix(int m,int n)  
   {  
     cout<<"\n\tMATRIX IS:";  
     for(int i=0;i<m;i++) <br="">       for(int j=0;j<n;j++) <br="">         cin>>mat[i][j];  
   }  
   void display(int m,int n)  
   {  
     for(int i=0;i<m;i++) <br="">     {  
       cout<<"\n";  
       for(int j=0;j<n;j++) <br="">       {  
         cout<<"\t";  
         cout<<mat[i][j]; <br="">       }  
     }  
     getch();  
   }  
 };  
 template  
 void add(T1 mat1,T2 mat2,int r,int c)  
 {  
    int i,j;  
    float mat[20][20];  
    for(i=0;i<r;i++) <br="">    {  
     for(j=0;j<c;j++) <br="">     {  
       mat[i][j]=mat1[i][j]+mat2[i][j];  
     }  
    }  
    disp_res(mat,r,c);  
    getch();  
 }  
 template  
 void disp_res(T mat,int m,int n)  
 {  
     for(int i=0;i<m;i++) <br="">     {  
       cout<<"\n";  
       for(int j=0;j<n;j++) <br="">       {  
         cout<<"\t";  
         cout<<mat[i][j]; <br="">       }  
     }  
     getch();  
 }  
 template  
 void sub(T1 mat1,T2 mat2,int r,int c)  
 {  
    int i,j;  
    float mat[20][20];  
    for(i=0;i<r;i++) <br="">    {  
     for(j=0;j<c;j++) <br="">     {  
       mat[i][j]=mat1[i][j]-mat2[i][j];  
     }  
    }  
    disp_res(mat,r,c);  
    getch();  
 }  
 template  
 void mul(T1 mat1,T2 mat2,int r,int c,int a)  
 {  
   int i,j,k;  
   float mat[10][10];  
   for(i=0;i<r;i++) <br="">   {  
     for(j=0;j<a;j++) <br="">     {  
       mat[i][j]=0;  
       for(k=0;k<c;k++) <br="">       mat[i][j]+=mat1[i][k]*mat2[k][j];  
     }  
   }  
   disp_res(mat,r,a);  
   getch();  
 }  
 template  
 void trans(T mat,int m,int n)  
 {  
     int i,j;  
     T t;  
     if(m>=n)  
     {  
       for(i=0;i<m;i++) <br="">       {  
         for(j=0;j<i;j++) <br="">         {  
           t[i][j]=mat[i][j];  
           mat[i][j]=mat[j][i];  
           mat[j][i]=t[i][j];  
         }  
       }  
       disp_res(mat,n,m);  
     }  
     else  
     {  
       for(i=0;i<n;i++) <br="">       {  
         for(j=0;j<i;j++) <br="">         {  
           t[i][j]=mat[i][j];  
           mat[i][j]=mat[j][i];  
           mat[j][i]=t[i][j];  
         }  
       }  
       disp_res(mat,m,n);  
     }  
     getch();  
 }  
 void main()  
 {  
   int ch,r,c,ch1;  
   matrixt3();  
   do  
   {  
     clrscr();  
     cout<<"\n\t##### MATRIX OPERATIONS ######"  
       <<"\n\t1.INPUT"  
       <<"\n\t2.DISPLAY"  
       <<"\n\t3.ADDITION"  
       <<"\n\t4.SUBTRACTION"  
       <<"\n\t5.MULTIPLICATION"  
       <<"\n\t6.TRANSPOSE"  
       <<"\n\t7.EXIT";  
     cout<<"\n\tENTER UR CHOICE:";  
     cin>>ch;  
     switch(ch)  
     {  
       case 1:  
         cout<<"\n\tENTER NO. OF ROWS:";  
         cin>>r;  
         cout<<"\n\tENTER NO. OF COLUMNS:";  
         cin>>c;  
         matrixt1(r,c);  
         matrixt2(r,c);  
         break;  
       case 2: do  
         {  
           cout<<"\n\t#### DISPLAY MENU ####";  
           cout<<"\n\t1.1st MATRIX";  
           cout<<"\n\t2.2nd MATRIX";  
           cout<<"\n\t3.EXIT";  
           cout<<"\n\tENTER UR CHOICE:";  
           cin>>ch1;  
           clrscr();  
           switch(ch1)  
           {  
             case 1: cout<<"\n\t1st MATRIX";  
               t1.display(r,c);  
               break;  
             case 2: cout<<"\n\t2nd MATRIX";  
               t2.display(r,c);  
               break;  
             case 3: break;  
           }  
         }while(ch1!=3);  
         break;  
       case 3: cout<<"\n\tADDITION IS:";  
         add(t1.mat,t2.mat, r,c);  
         break;  
       case 4: cout<<"\n\tSUBTRACTION IS:";  
         sub(t1.mat,t2.mat, r,c);  
         break;  
       case 5: cout<<"\n\tMULTIPLICATION IS:";  
         mul(t1.mat,t2.mat, r,c,r);  
         break;  
       case 6: do  
         {  
           cout<<"\n\t#### TRANSPOSE MENU ####";  
           cout<<"\n\t1.1st MATRIX";  
           cout<<"\n\t2.2nd MATRIX";  
           cout<<"\n\t3.EXIT";  
           cout<<"\n\tENTER UR CHOICE:";  
           cin>>ch1;  
           clrscr();  
           switch(ch1)  
           {  
             case 1: cout<<"\n\tTRANSPOSE OF 1st MATRIX:";  
               trans(t1.mat,r,c);  
               trans(t1.mat,r,c);  
               break;  
             case 2: cout<<"\n\tTRANSPOSE OF 2nd MATRIX:";  
               trans(t2.mat,r,c);  
               trans(t2.mat,r,c);  
               break;  
             case 3: break;  
           }  
         }while(ch1!=3);  
         break;  
       case 7:  
         break;  
     }  
   }while(ch!=7);  
 }

 

Other Projects to Try:

  1. How to Implement Hash Table using C language
  2. Hash table code in C Language
  3. Matrix operations in c language
  4. Matrix Operations in C Language
  5. Sparse Matrix Operations Code using C Langauge

Filed Under: C Assignments, Computer Graphics Tagged With: Computer Graphics

Student Database in C Language

April 6, 2011 by ProjectsGeek 4 Comments

Student Database in C Language 

Accept student information (e.g. Roll No, Name, Percentage etc.).

  • Display the data in descending order of Percentage (Bubble Sort).
  • Display data for Roll No specified by user (Linear Search).
  • Display the number of passes and comparisons for different test cases (Worst,
  • Average, Best case).

Student Database in C Language  Code

 #include  
 #include  
 #include  
 #include  
 class A  
 {  
   protected:  
   char blood[4],name[20];  
   int date,month,year;  
   public:  
   void inputa()  
   {  
     cout<<"ENTER NAME";  
     gets(name);  
     cout<<"ENTER DATE OF BIRTH";  
     cin>>date>>month>>year;  
     cout<<"ENTER BLODD GROUP!!";  
     gets(blood);  
   }  
   virtual void display()  
   {  
     cout<<"\nNAME:"<<name; <br="">     cout<<"\nDATE OF BIRTH:"<<date<<" "<<month<<"="" "<<year;="" <br="">     cout<<"\nBLOOD GROUP:"<<blood; <br="">     getch();  
   }  
 };  
 class B:virtual public A  
 {  
   protected:  
   int height;  
   int weight;  
   public:  
   void inputb()  
   {  
     cout<<"ENTER HEIGHT";  
     cin>>height;  
     cout<<"ENTER weight";  
     cin>>weight;  
   }  
   virtual void display()  
   {  
     cout<<"\nheight :"<<height; <br="">     cout<<"\nweight:"<<weight; <br="">     getch();  
   }  
 };  
 class C:virtual public A  
 {  
   protected:  
   int hno ;  
   char city[10];  
   unsigned long int insno;  
   public:  
   void inputc()  
   {  
     cout<<"ENTER ADDRESS OF CARD HOLDER";  
     cout<<"HOUSE NO";  
     cin>>hno;  
     cout<<"CITY";  
     cin>>city;  
     cout<<"ENTER INSURANCE NO";  
     cin>>insno;  
   }  
   virtual void display()  
   {  
     cout<<"\nADDRESS OF CARD HOLDER:"<<hno<<" "<<city;="" <br="">     cout<<"\nINSURANCE NO OF CARD HOLDER:"<<insno; <br="">     getch();  
   }  
 };  
 class D:public B,public C  
 {  
   int licno;  
   unsigned long int teleno;  
   public:  
   int id;  
   D()  
   {  
     id=0;  
     strcpy(name,'\0');  
     date=0;  
     month=0;  
     year=0;  
     height=0 ;  
     weight=0;  
     strcpy(blood,'\0');  
     hno=0;  
     strcpy(city,'\0');  
     insno=0;  
     teleno=0;  
     licno=0;  
   }  
   D(D &  d)  
   {  
     id=d.id;  
     strcpy(name,d.name);  
     date=d.date;  
     month=d.month;  
     year=d.year;  
     height=d.height;  
     weight=d.weight;  
     strcpy(blood,d.blood);  
     hno=d.hno;  
     strcpy(city,d.city);  
     insno=d.insno;  
     teleno=d.teleno;  
     licno=d.licno;  
   }  
   void inputd()  
   {  
     cout<<"ENTER TELEPHONE NO AFTER FIRST DIGIT ";  
     cin>>teleno;  
     cout<<"ENTER LICENCE NO";  
     cin>>licno;  
   }  
   void display()  
   {  
     clrscr();  
     cout<<"\nID NO"<<id; <br="">     cout<<"\nNAME:"<<name; <br="">     cout<<"\nDATE OF BIRTH:"<<date<<" "<<month<<"="" "<<year;="" <br="">     cout<<"\nHEIGHT:"<<height; <br="">     cout<<"\nWEIGHT:"<<weight; <br="">     cout<<"\ncBLOOD GROUP"<<blood; <br="">     cout<<"\nADDRESS:"<<hno<<" "<<city;="" <br="">     cout<<"\nINSURANCE NO:"<<insno; <br="">     cout<<"\nPHONE NO:"<<"9"<<teleno; <br="">     cout<<"\nLICENCE NO:"<<licno; <br="">     getch();  
   }  
 };  
 void main()  
 {  
   D d[20];  
   int ch=0,i=0,j;  
   do  
   {  
     clrscr();  
     cout<<"\t\t\t\t1.BUILD A MASTER TABLE\n" ;  
     cout<<"\t\t\t\t2.DISPLAY THE ENTRIES\n" ;  
     cout<<"\t\t\t\t3.INSERT A NEW DATA\n";  
     cout<<"\t\t\t\t4.DELETE A DATA\n" ;  
     cout<<"\t\t\t\t5.SEARCH FOR SPECIFIC ENTRY\n";  
     cout<<"\t\t\t\t6.EXIT\n" ;  
     cout<<"\t\t\t\tENTER UR CHOICE";  
     cin>>ch;  
     switch(ch)  
     {  
       case 1:  
         cout<<"\n\t\tBUILD A RECORD FOR CREDIT CARD!!";  
         i=0;  
         do  
         {  
           d[i].id=i+1;  
           d[i].inputa();  
           d[i].inputb();  
           d[i].inputc();  
           d[i].inputd();  
       i++;  
           cout<<"WANT TO ENTER MORE DATA";  
         }while(getche()=='y');  
         break;  
       case 2:  
         cout<<"\n\t\tDISPLAY CREDIT CARD RECORD!!";  
         for(j=0;j<i;j++) <br="">         {  
           d[j].display();  
         }  
         break;  
       case 3:  
         cout<<"\n\t\tINSERT A NEW RECORD IN CREDIT CARD ENTRY!!";  
         int k=i;  
         for(j=0;j<i;j++) <br="">           if(d[j].id!=j+1)  
           {  
             k=j;  
             while(j<i) <br="">               d[j+1]=d[j++];  
             break;  
           }  
         d[k].id=k+1;  
         d[k].inputa();  
         d[k].inputb();  
         d[k].inputc();  
         d[k].inputd();  
         i++;  
         break;  
       case 4:  
         cout<<"\n\t\tDELETE A CREDIT CARD RECORD \n\t\tENTER ID";  
         cin>>k;  
         for(j=0;j<i;j++) <br="">           if(d[j].id==k)  
           {  
             while(j<(i-1))  
              {  
               d[j]=d[j+1];  
               break;  
              }  
           }  
           i--;  
         break;  
       case 5:  
         cout<<"\n\t\tSEARCH FOR SPECIFIC ENTRY\n\t\tENTER ID";  
         cin>>k;  
         for(j=0;j<i;j++) <br="">           if(d[j].id==k)  
             break;  
         if(j!=i)  
         {  
             d[j].display();  
         }  
         else  
           cout<<"SORRY RECORD NOT FOUND";  
         getch();  
         break;  
       case 6:  
         break;  
     }  
   }while(ch!=6);  
   getch();  
 }

 

Other Projects to Try:

  1. Matrix Operations in C Language
  2. Friend Function Implementation using C++
  3. Operator Overloading on String Functions C++ Language
  4. Simple Student Database using C Language
  5. Student Database using Virtual functions in C++

Filed Under: C Assignments, Computer Graphics Tagged With: Computer Graphics

Boundary and Flood Fill Algorithms in C++ Language

April 6, 2011 by ProjectsGeek 2 Comments

Boundary and Flood Fill Algorithms

Write a program for Boundary and Flood Fill Algorithms in C++ Language . Boundary and Flood Fill Algorithms in C++ should accept the coordinates for polygon.

  • INPUT
  • FLOOD FILL
  • BOUNDARY FILL
  • EXIT

After selecting Boundary and Flood fill algorithm option , It must fill polygon by both algorithms.

Boundary and Flood Fill Algorithms Code

 #include  
 #include  
 #include  
 #include  
 #define max 100000  
 class fill  
 {  
   int edge,a[50],sx,sy,midx,midy;  
   public:  
   void input()  
   {  
     cout<<"\nENTER NO OF EDGES:";  
     cin>>edge;  
     int j=0;  
     for(int i=0;i<edge;i++) <br="">     {  
       cout<<"\nENTER THE X"<<i+1<<"coordinate:"; <br="">       cin>>a[j++];  
       cout<<"\nENTER THE Y"<<i+1<<"coordinate:"; <br="">       cin>>a[j++];  
     }  
   }  
   void b_fill(int x,int y,int clr)  
   {  
     int j=0;  
     midx=getmaxx()/2;  
     midy=getmaxy()/2;  
     setcolor(WHITE);  
     line(0,midy,2*midx,midy);  
     line(midx,0,midx,2*midy);  
     setcolor(RED);  
     for(int i=0;i<edge;i++) <br="">     {  
       if(edge-i!=1)  
         line(a[j]+midx,midy-a[j+1],a[j+2]+midx,midy-a[j+3]);  
       else  
         line(a[j]+midx,midy-a[j+1],a[0]+midx,midy-a[1]);  
       j=j+2;  
     }  
     getch();  
     int st[max][2],top=-1;  
     x=midx+x;  
     y=midy-y;  
     st[++top][0]=x;  
     st[top][1]=y;  
     while(top!=-1)  
     {  
       x=st[top][0];  
       y=st[top][1];  
       top--;  
       if((getpixel(x+1,y)!=clr)&&(getpixel(x+1,y)!=RED))  
       {  
         putpixel(x+1,y,clr);  
         st[++top][0]=x+1;  
         st[top][1]=y;  
       }  
       if((getpixel(x-1,y)!=clr)&&(getpixel(x-1,y)!=RED))  
       {  
         putpixel(x-1,y,clr);  
         st[++top][0]=x-1;  
         st[top][1]=y;  
       }  
       if((getpixel(x,y+1)!=clr)&&(getpixel(x,y+1)!=RED))  
       {  
         putpixel(x,y+1,clr);  
         st[++top][0]=x;  
         st[top][1]=y+1;  
       }  
       if((getpixel(x,y-1)!=clr)&&(getpixel(x,y-1)!=RED))  
       {  
         putpixel(x,y-1,clr);  
         st[++top][0]=x;  
         st[top][1]=y-1;  
       }  
      }  
   }  
   void f_fill(int x,int y,int clr)  
   {  
     int j=0;  
     midx=getmaxx()/2;  
     midy=getmaxy()/2;  
     setcolor(WHITE);  
     line(0,midy,2*midx,midy);  
     line(midx,0,midx,2*midy);  
     setcolor(RED);  
     for(int i=0;i<edge;i++) <br="">     {  
       if(edge-i!=1)  
         line(a[j]+midx,midy-a[j+1],a[j+2]+midx,midy-a[j+3]);  
       else  
         line(a[j]+midx,midy-a[j+1],a[0]+midx,midy-a[1]);  
       j=j+2;  
     }  
     getch();  
     int st[max][2],top=-1;  
     x=midx+x;  
     y=midy-y;  
     st[++top][0]=x;  
     st[top][1]=y;  
     putpixel(x,y,col);  
     while(top!=-1)  
     {  
       x=st[top][0];  
       y=st[top][1];  
       top--;  
       if((getpixel(x+1,y)!=clr)&&(getpixel(x+1,y)==7))  
       {  
         putpixel(x+1,y,clr);  
         st[++top][0]=x+1;  
         st[top][1]=y;  
       }  
       if((getpixel(x-1,y)!=clr)&&(getpixel(x-1,y)==7))  
       {  
         putpixel(x-1,y,clr);  
         st[++top][0]=x-1;  
         st[top][1]=y;  
       }  
       if((getpixel(x,y+1)!=clr)&&(getpixel(x,y+1)==7))  
       {  
         putpixel(x,y+1,clr);  
         st[++top][0]=x;  
         st[top][1]=y+1;  
       }  
       if((getpixel(x,y-1)!=clr)&&(getpixel(x,y-1)==7))  
       {  
         putpixel(x,y-1,clr);  
         st[++top][0]=x;  
         st[top][1]=y-1;  
       }  
      }  
   }  
 };  
 void menu()  
 {  
   clrscr();  
   cout<<"\n\t##### MAIN MENU #####";  
   cout<<"\n\t1.INPUT";  
   cout<<"\n\t2.FLOOD FILL";  
   cout<<"\n\t3.BOUNDARY FILL";  
   cout<<"\n\t4.EXIT";  
   cout<<"\n\tENTER UR CHOICE:";  
 }  
 void main()  
 {  
   int gd=DETECT,gm;  
     initgraph(&gd,&gm,"c:\\tc\\bgi");  
   int ch,x,y,clr;  
   fill f;  
   do  
   {  
     menu();  
     cin>>ch;  
     clrscr();  
     switch(ch)  
     {  
       case 1:  
         f.input();  
         break;  
       case 2:  
         cout<<"\n#### FLOOD FILL ####";  
         cout<<"\nENTER THE COLOR CODE TO FILL:";  
         cin>>clr;  
         cout<<"\nENTER THE X-COORDINATE OF SEED POINT:";  
         cin>>x;  
         cout<<"\nENTER THE Y-COORDINATE OF SEED POINT:";  
         cin>>y;  
         f.f_fill(x,y,clr);  
         getch();  
         break;  
       case 3:  
         cout<<"\n#### BOUNDARY FILL ####";  
         cout<<"\nENTER THE COLOR CODE TO FILL:";  
         cin>>clr;  
         cout<<"\nENTER THE X-COORDINATE OF SEED POINT:";  
         cin>>x;  
         cout<<"\nENTER THE Y-COORDINATE OF SEED POINT:";  
         cin>>y;  
         f.b_fill(x,y,clr);  
         getch();  
         break;  
       case 4:  
         break;  
     }  
   }while(ch!=4);  
 }

 

 

Other Projects to Try:

  1. Graphics Editor code Using C++ Language
  2. Transformations computer graphics using C++ Language
  3. Computer graphics codes in C++ Language
  4. Paging Algorithms using C language OS problem
  5. Bressenham and DDA Line Drawing algorithms

Filed Under: C Assignments, Computer Graphics Tagged With: Computer Graphics

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

  • « Go to Previous Page
  • Page 1
  • Page 2
  • Page 3
  • 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