Group Assignment CAED-C++ Programming
Group Assignment CAED-C++ Programming
Assignment Title Date of Proposal Group Members : C++ Programming for Line, Circle, Rectangle and Ellipse : June 16th, 2011 : 1. Muhammad Fauzan bin Ghazali 2. Muhammad Arief Fikry bin Zainalabidin 3. Mohamad Shukor bin Sahroni 4. Muhammad Nur Fauzi bin Md Salehan 5. Azlan bin Azahar Year Programme of Study Lecturer : 2nd Year 1st Semester : Mechanical Engineering : Dr Muhammad Ali Khan 13692 13666 13551 13627 13704
Assignment Title: C++ Programming for Line, Circle, Rectangle and Ellipse
Graphic Programming
Based on research done in the internet, the construction of circle, rectangle and ellipse by C++ programming codes can be done by using graphic programming named Turbo C++ graphics programming. For the purpose of these programming codes displays, it is recommended to use Turbo C++ 3.0 for ease and efficient functionalities. There are two files required for the graphic programming purpose, named GRAPHICS.H and GRAPHICS.LIB. As for TURBO C++, these two files are wellaccompanied along with the software. Another requirement is graphics monitor and adapter card such as CGA, EGA and VGA which are essential for graphics mode functions. In order to construct different shapes, various functions are available to run the task. These functions includes rectangle function, ellipse function and circle function as well as line function for the drawing of rectangle, ellipse, circle and line respectively. The functions are stated as follows:
Rectangle (left, top, right, bottom) Ellipse (x, y, stangle, endangle, xrad, yrad) Circle (x, y, rad) Line (x1, y1, x2, y2)
Code Explanation In order to construct the programming codes, the keywords must be understood at first. These keywords are as follow: Initgraph: It is a type of function that is used to switch from text mode to graphic mode or initialises the graphic mode. It selects best resolution and directs the value to mode in variable graphic mode. Two int variables are graphic driver and graphic mode. 1. Graphic mode handles value that emphasizes the type of resolution and monitor that are being used.
2. Graphic driver specifies the graphic driver to be used. In the program codes, we have gd=DETECT means we have passed the highest possible value available for detected driver. The & symbol is used for initgraph to pass address of the constants. Path: In form of ( C:\\tc\\bgi). It specifies the directory path where initgraph looks for the graphics drivers (*.BGI). Function(): Function consists of types of shapes that will be constructed. Type of functions available included line, circle, ellipse, arc and rectangular. Closegraph(): It switches back the screen from graphics mode to text mode. This function is called after the getch() function. Restorcrtmode(): This mode restores the original video mode detected by initgrapgh function. Getch(): The function gets character from console but does not echo it on screen. This is used to pause the screen until user hits any key.
Reference
-Introduction to graphic programming and Turbo C++ Graphic Programming http://onecore.net/turbo-c-graphics-programming.htm -Type of function used to construct a shape http://onecore.net/turbo-c-graphics-part-2.htm