0% found this document useful (0 votes)
16 views18 pages

Graph

GRAPH THEORY NOTES
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views18 pages

Graph

GRAPH THEORY NOTES
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 18

/* Aim - Program for one file to another file */

#include<dos.h>
#include<stdio.h>
#include<conio.h>

void main()
{
char ch;
FILE *fp_R, *fp_W;
clrscr();

fp_R = fopen("file.txt","r");
fp_W = fopen("Nfile.txt","w");

printf("\n Wait, File Coping ....... ");

while(!feof(fp_R))
{
ch = fgetc(fp_R);
fputc(ch,fp_W);
}

delay(1000);
printf("\n File Copy Completed ....... ");

getch();
fclose(fp_R);
fclose(fp_W);

} /* END OF void main( ) FUNCTION */

Unit IV
Display Adapter
A display adapter is an expansion card whose function is to generate and output images to
display. Some video cards offer added functions, such as video capture, TV tuner adapter, MPEG-
2 and MPEG-4 decoding, FireWire, light pen, TV output, or the ability to connect multiple
monitors. A display adapter is also known as a video card graphics accelerator card, display
adapter, or graphics card.

High end video cards have a much broader range of capability; for example, they play a
very important role for graphic designers and 3D animators, who tend to require optimum
displays as well as faster rendering.
The display adapter in a desktop computer that creates the electronic signals required by
the monitor. It decide the maximum resolution, refresh rate and number of colors that can be
displayed, which the monitor must also be able to support. On many PC motherboards, the
display circuits are built into the chipset, and a card is not required.

The display adapter's primary purpose is to continuously convert the graphic patterns
(bitmaps) in memory frame buffers into signals for the monitor's screen. High-end adapters move
the image through a graphics pipeline adding texture and 2D and 3D effects, all functions that
used to be done by the computer's CPU. A super fast gaming adapter is a sophisticated parallel
processing computer.

The first PC display adapters (CGA, EGA, PGA) sent digital signals to the monitor, which
converted them into analog for the CRT. Starting with VGA, analog signals were output to the
monitor. Increasingly, display adapters provide both analog and digital outputs, the latter a DVI
interface for a flat panel monitor. On portables with LCD screens, the display circuitry has been
digital from end to end.

Color Graphics Adapter (CGA)

The Color Graphics Adapter (CGA), originally also called the Color/Graphics Adapter or
IBM Color/Graphics Monitor Adapter, introduced in 1981. CGA was IBM’s first color graphics
card, and the first color computer display standard for the IBM PC.

The standard IBM CGA graphics card was equipped with 16 kilobytes of video memory,
and could be connected either to a NTSC-compatible monitor or TV via an RCA jack, or to a
dedicated 4-bit "RBGI" interface CRT monitor.

Built around the Motorola MC6845 display controller, the CGA card featured several
graphics and text modes. The highest resolution of any mode was 640×200, and the highest color
depth supported was 4-bit that can support to 16 colors.

Display Screen
Display Screen is also called computer monitor. A display screen used to present output
from a computer, video camera, VCR or other video generator. The clarity of a CRT (Cathode Ray
Tube) monitor is based on video bandwidth, dot pitch, refresh rate and convergence. A monitor is
the TV-like part of the computer that you look at to see information.

Cathode Ray Tube (CRT), a vacuum tube used as a display screen in a computer monitor or
TV. The viewing end of the tube is coated with phosphors, which emit light when struck by
electrons. CRT was a popular term for the entire computer display terminal. Now, computer
displays have shifted from CRTs to flat LCD panels.

The CRT works by heating a cathode which causes electrons to flow. Accelerating and
focusing anodes turn the electrons into a fine beam that is directed to the phosphors by magnetic
fields that are generated by steering coils. The viewing end of a color CRT tube is coated with red,
green and blue phosphor dots, and separate electron guns bombard their respective colors a line at
a time in a prescribed sequence. The resulting color displayed on screen is determined by the
intensity of the electron beams as they strike the red, green and blue phosphors at that same pixel
location.

There are many ways to classify monitors. The most on the basic of color capabilities monitors into
three classes -
 Monochrome Monitors - Monochrome monitors actually display two colors, one for the
background and one for the foreground. The colors can be black and white, green and
black, or amber and black.
 Gray-Scale Monitors - A gray-scale monitor is a special type of monochrome monitor
capable of displaying different shades of gray.
 Color Monitors - Color monitors can display anywhere from 16 to over 1 million different
colors. Color monitors are sometimes called RGB monitors because they accept three
separate signals i. e. Red, Green & Blue.

Screen size is another important aspect of a monitor. Screen sizes are measured in diagonal
inches, the distance from one corner to the opposite corner diagonally. A typical size for small
VGA monitors is 14 inches. Monitors that are 16 or more inches diagonally are often called full-
page monitors. Monitors can be either portrait i. e. height is greater than width or landscape i. e.
width is greater than height.

The resolution of a monitor indicates how densely packed the pixels. The more pixels
[dots/inch] mean sharper the image. Modern monitors can display 1024 by 768 pixels, the SVGA
standard. Some high-end models can display 1280 by 1024, or even 1600 by 1200.

Analog Monitor is a video monitor that accepts analog signals from the computer's display adapter,
which does the digital-to-analog conversion. An analog monitor may accept only a narrow range of display
resolutions. Only VGA or VGA and Super VGA, or it may accept a wide range of signals including TV.

Digital monitor is a video monitor controlled by a computer circuit that retains settings and
resolutions in memory. Subsequent changes in resolutions do not require adjustments. Most
computer monitors today are digitally controlled, but still accept analog signals from the display
adapter.
Multi-Frequency Monitor is a monitor that adjusts to all frequencies within a range or to a
set of specific frequencies within a range.

Unit V

Graphics In C Programming Language

C Programming Language can work in two modes –

1) Text Mode And


2) Graphics Mode

Function initgraph( )

Function initgraph( ) is used to load the graphics drivers and initialize the graphics system. For
every function, that uses graphics mode, graphics mode must be initialized before using that
function. Protype of Function initgraph( ) is -

void far initgraph(int far *graphdriver, int far *graphmode, char far *path)

Function initgraph( ) initializes the graphics system by loading a graphics driver from disk,
then putting the system into graphics mode. Function initgraph( ) also resets all graphics settings
(color, palette, current position, viewport, etc.) to their defaults.

integer *graphdriver, that specifies the graphics driver to be used. We can give graphdriver
a value using a constant of the graphics_drivers enumeration type.

integer *graphmode that specifies the initial graphics mode to be used. We can give
*graphmode a value using a constant of the graphics_modes enumeration type.

For autodetect graphics driver & mode, both integer *graphdriver and integer *graphmode
set to DETECT. If *graphdriver = DETECT, initgraph sets *graphmode to the highest resolution
available for the detected driver.

Char far *path Specifies the directory path where Function initgraph( ) looks for graphics
drivers (*.BGI) first. If they're not there, Function initgraph( ) graph looks in the current directory.
If *path is null, the driver files must be in the current directory. This is also the path settextstyle( )
searches for the stroked character font files (*.CHR).

It is possible to set function initgraph( ) to autodetect, this is calls function detectgraph( ) to


select a graphics driver and mode. After a call to function initgraph( ), *graphdriver is set to the
current graphics driver, and *graphmode is set to the current graphics mode.

Function closegraph( )
Function closegraph( ) close the graphics mode and returns to the position it was before the
initgraph function was called i. e. Text Mode. Function closegraph( ) releases all the resources
occupied by the graphics system like memry, fonts, drivers etc. Prototype of function closegraph( )

void far closegraph (void) ;

Function closegraph() deallocates all memory allocated by the graphics system. It then
restores the screen to the mode it was in before you called of initgraph( ) function.

The graphics system deallocates memory, such as the drivers, fonts, and internal buffer,
through a call to function _graphfreemem( ) .

Colors in Text Mode

C Programming Language support following colors in Text Mode –

Background and Foreground Colors Support Text Mode

Support for Support for


S No Color Constant Value Backgroun Foregroun
d d
1 BLACK 0 Yes Yes
2 BLUE 1 Yes Yes
3 GREEN 2 Yes Yes
4 CYAN 3 Yes Yes
5 RED 4 Yes Yes
6 MAGENTA 5 Yes Yes
7 BROWN 6 Yes Yes
8 LIGHTGRAY 7 Yes Yes
9 DARKGRAY 8 No Yes
10 LIGHTBLUE 9 No Yes
11 LIGHTGREEN 10 No Yes
12 LIGHTCYAN 11 No Yes
13 LIGHTRED 12 No Yes
14 LIGHTMAGENTA 13 No Yes
15 YELLOW 14 No Yes
16 WHITE 15 No Yes
17 BLINK 128

Color support also depends on graphics driver and graphics mode.

/*Aim – Program to display various colors available in text mode */

#include<dos.h>
#include<stdio.h>
#include<conio.h>

void main()
{

int n;
clrscr();

printf("\n Text without BLINK ");


for(n=1;n<=15;n++)
{
textcolor(n);
textbackground(0);
delay(600);
cprintf("\n\n\rColor Value %2i : C Programming",n);
}

getch();
clrscr();

printf("\n Text With BLINK ");


for(n=1;n<=15;n++)
{
textcolor(n+BLINK);
textbackground(0);
delay(600);
cprintf("\n\n\rColor Value %2i : C Programming",n);
}

getch();
getch();
}

Colors in Graphics Mode


C Programming Language support following colors in Graphics Mode FOR CGA driver &
CGA0 mode –

S No Color Constant Value

1 CGA_LIGHTGREEN 1
2 CGA_LIGHTGRED 2
3 CGA_YELLOW 3

C Programming Language support following colors in Graphics Mode FOR CGA driver &
CGA1 mode –

S No Color Constant Value

1 CGA_LIGHTCYAN 1
2 CGA_LIGHTMAGENTA 2
3 CGA_WHITE 3

C Programming Language support following colors in Graphics Mode FOR CGA driver &
CGA2 mode –

S No Color Constant Value

1 CGA_GREEN 1
2 CGA_RED 2
3 CGA_BROWN 3

C Programming Language support following colors in Graphics Mode FOR CGA driver &
CGA3 mode –

S No Color Constant Value

1 CGA_CYAN 1
2 CGA_MAGENTA 2
3 CGA_LIGHTGRAY 3

C Programming Language support following colors in Graphics Mode FOR EGA driver &
EGAHI mode and EGALO mode –

S No Color Constant Value

1 EGA_BLACK 0
2 EGA_BLUE 1
3 EGA_GREEN 2
4 EGA_CYAN 3
5 EGA_RED 4
6 EGA_MAGENTA 5
7 EGA_LIGHTGRAY 7
8 EGA_BROWN 20
9 EGA_DARKGRAY 56
10 EGA_LIGHTBLUE 57
11 EGA_LIGHTGREEN 58
12 EGA_LIGHTCYAN 59
13 EGA_LIGHTRED 60
14 EGA_LIGHTMAGENTA 61
15 EGA_YELLOW 62
16 EGA_WHITE 63

Drawing various shapes in C Programming


Function for drawing line

In C programming language, three functions are available –

void far line (int v1, int h1, int v2, int h2);
void far linerel (int dv, int dh);
void far lineto (int v, int h);
void far line (int v1, int h1, int v2, int h2);

Function line( ) draws a line between two specified points i. e. v1,h1 to v2,h2. For example -

line (20,40,150,280);

Calling function line ( ) will draw straight line from (20,40) to (150,280). We can draw line in
various color and style.

/*Program : line.c */
/*Aim – Draw line from (20,40) to (150,280) with Red color*/

#include<graphics.h>
#include<stdio.h>
#include<conio.h>

void main()
{

int GD=0,GM=0,r;
clrscr();

initgraph(&GD,&GM,"c:\\turboc3\\bgi");

printf("\nDrawing Line .......... ");

setlinestyle (DASHED_LINE, 3 ,1);


setcolor(RED);
/* line(v1,h1,v2,h2); */

line(20,40,150,280);

getch();
getch();

closegraph();
}

line (20,40,150,280);

Calling function line ( ) will draw straight line from (20,40) to (150,280). We can draw line in
various color and style.
Function linerel( )

Prototype of function linerel( ) –

void far linerel (int dv, int dh);

Function linerel( ) draws a line from current position to specified distance i. e. dv, dh. For example
-

moveto(50,70);
linerel(150,280);

Function moveto( ) move current position point to position (v,h) i.e. (50,70) and Function
linerel( ) draws a line from the current position to a point located at relative distance (dv, dh) i. e.
(150,280), then current position advances by (dv, dh) i. e. (200,350).

/*Program : linerel.c */
/*Aim – Draw line from current position to relative distance (150,280) with Blue color*/

#include<graphics.h>
#include<stdio.h>
#include<conio.h>

void main()
{

int GD=0,GM=0 ;
clrscr();

initgraph(&GD,&GM,"c:\\turboc3\\bgi");

printf("\n Drawing Line .......... ");

//linerel(dv,dh);
setbkcolor(YELLOW); /*set background color to Yellow*/
setlinestyle(0,7,1);
setcolor(BLUE); /*set line color to Blue */
moveto(50,70); /*move current position to intersect point 50,70 ( i. e. Vertical 50 & Horizontal 70)*/
linerel(150,280); /* linerel( ) draw line from current position (50,70) to relative distance of (150,280) */

getch();
closegraph();
}
Above program draw line with blue color from intersection point of 50,70 to 200,350,
because current position is 50,70 and relative distance is (150,280).

Function lineto( )

Prototype of function lineto( ) –

void far lineto (int dv, int dh);

Function lineto( ) draws a line from current position to specified point (dv, dh) . For example -

moveto(20,80);
lineto(250,200);

Function moveto( ) move current position point to position (v,h) i.e. (20,80) and Function
lineto( ) draws a line from the current position to a point located at relative point(dv, dh) i. e.
(250,200), then current position advances by (dv, dh) i. e. (250,200).

/*Program : lineto.c */
/*Aim – Draw line from current position to point (250,200) with Yellow color*/

#include<graphics.h>
#include<stdio.h>
#include<conio.h>

void main()
{

int GD=0,GM=0 ;
clrscr();

initgraph(&GD,&GM,"c:\\turboc3\\bgi");

printf("\n Drawing Line .......... ");

//lineto(dv,dh);
setlinestyle(0,7,1);
setcolor(YELLOW); /*set line color to Yellow */
moveto(20,80); /*move current position to intersect point 50,70 ( i. e. Vertical 50 & Horizontal 70)*/
lineto(250,200); /* lineto( ) draw line from current position (20,80) to point (250,200) */
getch();
closegraph();
}

Above program draw line with yellow color from intersection point of 20,80 to 250,200.

For drawing line following line styles are available –

Constant Name Value Meaning

SOLID_LINE 0 Solid line


DOTTED_LINE 1 Dotted line
CENTER_LINE 2 Centered line
DASHED_LINE 3 Dashed line
USERBIT_LINE 4 User-defined line style

For drawing line following line width are available –

Constant Name Value Meaning

NORM_WIDTH 1 1 Pixel Wide


THICK_WIDTH 3 3 Pixel Wide

Drawing Different Shapes

Function circle ( )

Library function circle( ) draw a circle in the current drawing color. Prototype of library function
circle( ) –

void far circle(int v, int h, int radius);

For example –
setcolor(BLUE);
/* circle(v,h,radius)*/
circle(250,280,150);

In above example circle is drawn from intersection point (250,280) and radius of circle is 150 pixels.
Because of setcolor( ) , the circle is draw in blue color.

/*Program – circle.c */
#include<graphics.h>
#include<stdio.h>
#include<conio.h>

void main()
{
int GD=0,GM=0;
clrscr();

initgraph(&GD,&GM,"c:\\turboc3\\bgi");

printf("\n Drawing Circle .......... ");

setbkcolor(YELLOW);
setcolor(BLUE);

/* circle(v,h,radius)*/
circle(250,280,150);

getch();
getch();
closegraph();

}
Function arc ( )

Library function arc( ) draw a circular arc in the current drawing color, from starting angle
to end angle. Function arc ( ) travels from starting angle to end angle .Prototype of library function
arc( ) –

void far arc(int v, int h, int st_angle, int end_angle, int radius);

For example –

setcolor(BLUE);
/* arc(v, h, SA, EA, radius)*/
arc(300,350,45,180,250);
In above example arc is drawn from intersection point (300,350) and radius of circle is 250
pixels, arc start from angle 450 to 1800 . Because of setcolor(BLUE) , the circle is draw in blue color.

/*Program – arc.c */

#include<graphics.h>
#include<stdio.h>
#include<conio.h>

void main()
{
int GD=0,GM=0;
clrscr();

initgraph(&GD,&GM,"c:\\turboc3\\bgi");

printf("\n Drawing Arc .......... ");

setcolor(BLUE);
/* arc(v,h, SA, EA,radius)*/
arc(300,350,45,180,250);

getch();
getch();
closegraph();
}

Function pieslice( )

Library function pieslice( ) draw a circular arc in the current drawing color, from starting
angle to end angle. Function pieslice ( ) travels from starting angle to end angle .Prototype of
library function pieslice ( ) –

void far pieslice(int v, int h, int st_angle, int end_angle, int radius);

For example –

setcolor(BLUE);
/* pieslice(v, h, SA, EA, radius)*/
pieslice (300,350,45,180,250);
In above example pieslice is drawn from intersection point (300,350) and radius of circle is
250 pixels, arc start from angle 450 to 1800 . Because of setcolor(BLUE) , the circle is draw in blue
color.

/*Program – pieslice.c */
#include<graphics.h>
#include<stdio.h>
#include<conio.h>

void main()
{
int GD=0,GM=0;
clrscr();

initgraph(&GD,&GM,"c:\\turboc3\\bgi");
printf("\n Drawing Pieslice .......... ");

setcolor(RED);
setfillstyle(4,2);

/* pieslice (v,h, SA, EA,radius)*/


pieslice (300,350,45,180,250);

getch();
getch();
closegraph();
}

Library function pieslice( ), we can fill with different patterns and colors, it is not possible
with function arc( ) . Function setfillstyle(Fill_Pattern, Color) use pattern to fill in arc draw by
function pieslice( ) . Different fill pattern available in C programming are –

Names Value Means Fill With...

EMPTY_FILL 0 Back Ground Color


SOLID_FILL 1 Solid Fill
LINE_FILL 2 --- Fill
LTSLASH_FILL 3 /// Fill
SLASH_FILL 4 ///, Thick lines
BKSLASH_FILL 5 \\\, Thick lines
LTBKSLASH_FILL 6 \\\ Fill
HATCH_FILL 7 Light hatch
XHATCH_FILL 8 Heavy cross hatch
INTERLEAVE_FILL 9 Interleaving lines
WIDE_DOT_FILL 10 Widely spaceddots
CLOSE_DOT_FILL 11 Closely spaced dots

Text/String in C Graphics Programming

In c Programming language, we can print text \ string in various colors, style & size, either
in horizontal or vertical direction. For print Text\String in various colors, style & size, C language
provide two library functions supported by header file Graphics.h. Library functions prototypes
are –

void far outtext(char far *textstring);

void far outtextxy(int x, int y, char far *textstring);

Built In function outtext displays a Text/String on the screen at current position. We can
change current position by using library function moveto( ) supported by header file graphics.h.
Both library functions outtext( ) and outtextxy( ) work in graphics mode, not in text mode.

/* outtext(char far *textstring); */

moveto(100,20);
outtext(“C PROGRAMMING”);

In above statement moveto( ) function, change current position to (100,20) and than function
outtext( ) print “C PROGRAMMING” .

On other side, Built In function outtextxy displays a Text/String at the specified location on the
computer screen.

/* outtextxy(v , h, char *textstring); */

outtextxy(50, 80, “C PROGRAMMING”);

In above statement function outtextxy( ) print “C PROGRAMMING” at intersection point


50,80 .
To print Text\String in different color, we have to use library function setcolor( ). For
example –

setcolor(RED);

Above example set font color to red color.

To print Text\String in different style, size and direction, we have to use library function
settextstyle( ). For example –

/* settextstyle(font_name, font_direction, font_size); */

settextstyle(GOTHIC_FONT, VERT_DIR, 15);

Above example print in GOTHIC_FONT font style, Vertical direction and size 15.

Name Value

DEFAULT_FONT 0
TRIPLEX_FONT 1
SMALL_FONT 2
SANS_SERIF_FONT 3
GOTHIC_FONT 4

Two directions are support by C Programming -

Name Value Direction


HORIZ_DIR 0 Left to Right
VERT_DIR 1 Bottom to Top

The default direction is HORIZ_DIR.

#include<graphics.h>
#include<conio.h>
#include<stdio.h>

void main()
{
int GD=0,GM=0;
clrscr();
initgraph(&GD,&GM,"C:\\TC\\BGI") ;
setcolor(RED);
settextstyle(4,1,45);
outtext("Ashish");

getch();
getch();
closegraph();
}

Function outtext( ) and outtextxy( ) are for use in graphics mode; they will not work in text mode.

*****************

You might also like