Question 20 marks
In the handouts of CS602 – Computer Graphics many examples are given in which GRAPHICS.H Header file is used. If you compile the given code in Dev-C++ IDE / Compiler the errors are reported because the given code is using GRAPHICS.H which is originally provided by Borland (www.borland.com). But there are ways to compile that code on Dev-C++. For this purpose you can consult the following tutorials:
- http://vulms.vu.edu.pk/Courses/CS602/Downloads/DevCppTutorialGraphics_h.pdf
- http://www.uniqueness-template.com/devcpp/
You are required to compile the given code after following the above tutorial and submit the following files in zip archive:
- Dev-C++ Project File (e.g. Project1.dev)
- C++ Source (e.g. main.cpp)
- O/Object File (mian.o)
- Makefile.win
- Executable File (e.g. Project1.exe) it is much necessary as a proof that you have successfully compiled the code.
- Microsoft Word File explaining the code.
Solution
asd
download the "graphics.h" and "libbgi.a" from the following link.
copy "graphics.h" into "C:\Dev-Cpp\include\"
and
"libbgi.a" into "C:\Dev-Cpp\lib\".
open devcpp and start new project. choose windows application from new project dialog.
create new source file and paste the below code into it.
Source Code:
#include <graphics.h>
#include <iostream>
#include <conio.h>
#include <math.h>
float round(float x){
return x+0.5;
}
class Table{
private:
int xc, yc;
int xp, yp;
int x1, x2, x3, x4;
int y1, y2, y3, y4;
int legLength;
int sfx, sfy;
public:
Table(){
xc=320, yc=240;
xp=0; yp=0;
x1=-10, x2=10, x3=10, x4=-10;
y1=-7, y2=-7, y3=7, y4=7;
legLength=10;
sfx=1, sfy=1;
}
void translate(int tx, int ty){
xp+=tx;
yp+=ty;
}
void rotate (float angle){
int tempx=x1;
x1=tempx*cos(angle)-y1*sin(angle);
y1=tempx*sin(angle)+y1*cos(angle);
tempx=x2;
x2=tempx*cos(angle)-y2*sin(angle);
y2=tempx*sin(angle)+y2*cos(angle);
tempx=x3;
x3=tempx*cos(angle)-y3*sin(angle);
y3=tempx*sin(angle)+y3*cos(angle);
tempx=x4;
x4=tempx*cos(angle)-y4*sin(angle);
y4=tempx*sin(angle)+y4*cos(angle);
}
void scale(int sx, int sy){
x1=x1*sx;
x2=x2*sx;
x3=x3*sx;
x4=x4*sx;
y1=y1*sy;
y2=y2*sy;
y3=y3*sy;
y4=y4*sy;
legLength=legLength*sy;
}
void draw(){
int xc=this->xc+xp;
int yc=this->yc+yp;
line (xc+x1, yc+y1, xc+x2, yc+y2);
line (xc+x2, yc+y2, xc+x3, yc+y3);
line (xc+x3, yc+y3, xc+x4, yc+y4);
line (xc+x4, yc+y4, xc+x1, yc+y1);
line (xc+x1, yc+y1, xc+x1, yc+y1+legLength);
line (xc+x2, yc+y2, xc+x2, yc+y2+legLength);
line (xc+x3, yc+y3, xc+x3, yc+y3+legLength);
line (xc+x4, yc+y4, xc+x4, yc+y4+legLength);
}};
int main(){
//clrscr(); //it is not needed in DevCPP
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "c:\\Dev-Cpp\\lib");
Table table;
table.draw();
setcolor(CYAN);
table.translate(15, 25);
table.draw();
table.translate(50, 0);
table.scale(3,2);
table.draw();
table.translate(-100, 0);
table.rotate(3.14/4);
table.draw();
getch();
closegraph();
return 0;
}
go to the menu "project -> project options" than "parameters" copy the below commands in the "linker field"
-lbgi
-lgdi32
-lcomdlg32
-luuid
-loleaut32
-lole32
-lgdi32
-lcomdlg32
-luuid
-loleaut32
-lole32
than compile the programe.
copy all the project files zip them and submit.
Thanks
No comments:
Post a Comment