Applications: Unit - Vi
Applications: Unit - Vi
Applications
– Case study of simple bank transactions and program
development.
Preprocessor directives
– Macro expansion
- file inclusion
- condition compilation
- miscellaneous directives.
Graphics in C
– Line drawing
- Rectangle
- ellipse
- working with image
- move to function
- graphic related library functions
simple bank transactions
Case study:
Objective is to maintain a bank’s account information.
Some of the important tasks are:
-Updating existing account
- Adding new account
- Deleting account
- storing list of all accounts in a text file for printing
void main(void)
{
char *array;
int elements, elemnt_size;
………………………….
SORT(3)(array,elements, elements_size);
}
sort_function3(array,elements,element_size);
Graphics in C
Text Mode Graphics Mode
• And screen has the size of 480 pixels in y-axis, so 240 is the
center of y-axis.
• rectangle(100,100,200, 200);
– Output:
– (100,100)
(200,200)
Drawing ellipse
ellipse(midx, midy,starting-angle,ending-angle,radius-x, radius-y);
ellipse(320,240,0,360,50,100);
ellipse(midx, midy,starting-angle,ending-angle,radius-x,
radius-y);
• Example1:
ellipse(320,240,0,360,50,100);
www.sirjameel.com
ellipse(midx, midy,starting-angle,ending-angle,radius-x,
radius-y);
• Example2:
ellipse(320,240,0,360,100,100);
www.sirjameel.com
ellipse(midx, midy,starting-angle,ending-angle,radius-x,
radius-y);
• Example3:
ellipse(320,240,0,360,100,50);
www.sirjameel.com
• /*
shapes.c
example 1.1
*/
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT, gm;
int poly[12]={350,450, 350,410, 430,400, 350,350, 300,430, 350,450 };
initgraph(&gd, &gm, "");
circle(100,100,50);
outtextxy(75,170, "Circle");
rectangle(200,50,350,150);
outtextxy(240, 170, "Rectangle");
ellipse(500, 100,0,360, 100,50);
outtextxy(480, 170, "Ellipse");
line(100,250,540,250);
outtextxy(300,260,"Line");
sector(150, 400, 30, 300, 100,50);
outtextxy(120, 460, "Sector");
drawpoly(6, poly);
outtextxy(340, 460, "Polygon");
getch();
closegraph();
}
Graphics library functions
• void far outtextxy(int x, int y, char *text);
displays the string in graphics mode at
specified position.
• void far outtext(char *text );- displays string
at the current position.
• void far setcolor(int color);
• void far setbkcolor(int color);
• BLACK: 0
BLUE: 1
GREEN: 2
CYAN: 3
RED: 4
MAGENTA: 5
BROWN: 6
LIGHTGRAY: 7
DARKGRAY: 8
LIGHTBLUE: 9
LIGHTGREEN: 10
LIGHTCYAN: 11
LIGHTRED: 12
LIGHTMAGENTA: 13
YELLOW: 14
WHITE: 15
• gotoxy()
• This will initialize the graphics cursor to the
specified co-ordianate.In C gotoxy function
is used very frequently to locate the cursor
at different locations whenever as
necessary.
gotoxy(x,y);
• putpixel()
• It will colour the pixel specified by the co-
ordinates.
putpixel(x,y,white);
• lineto()
• Draws a line from its current location to the
co-ordinate(x,y)
• Lineto(x,y);
• settextstyle()
• The fonts available are :TRIPLEX_FONT,
SMALL_FONT, SANS_SERIE_FONT,
GOTHIC_FONT
• The direction can be changed as
HORIZ_DIR or VERT_DIR
• Settextstyle(GOTHIC_FONT,VERT_DIR)
;
Move to functions
• moverel(int x,int y);- this function is used
to move to cursor to a point a relative
distance away from the current CP
moveto(int x,int y)- move the cursor to the
specified location.
• Loading the header file of C graphics.h
• The C graphics is the header file which
should be included to initialize your
computer to start using graphics methods
and also to initialize the monitor. These
kinds of statements before the main
program are called preprocessor
dierctives. Its very simple as coded below.
• #INCLUDE<STDIO.H>
• #INCLUDE<GRAPHICS.H>
• Void main()
• {
- This initialization is done inside the main
program.The method initgraph() is used for this
purpose there are three parameters for this , the
first two are of integer type and the next is the
path which you can leave blank in quotes to take
the default path.
Initializing 'Graphics Driver' and
'Graphics Mode' from Borland C
graphics library
• #INCLUDE<STDIO.H>
• #INCLUDE<CONIO.H>
• #INCLUDE<GRAPHICS.H>
• VOID MAIN()
• {
• INT GDRIVER=DETECT,GMODE;
• INITGRAPH(&GDRIVER,&GMODE," ");
• }