CG 7
CG 7
Aim: Evaluate the 4-bit region code for line endpoints and determine whether the line lies
inside or outside the screen.
Objective: To calculate and display the 4-bit region code for line endpoints and determine
whether the line lies within the screen boundaries.
Code:
#include <iostream.h>
#include <conio.h>
#include <graphics.h>
#include<dos.h>
void main() {
outtextxy(450,200,"Bhumika_22BCS16875");
cout << "Enter the endpoints of the line (x1, y1, x2, y2): ";
cout << "For " << i << "th endpoint, region code is: "
<< bit1 << bit2 << bit3 << bit4 << endl;
if (!(num[0] | num[1])) {
} else {
delay(7000);
getch();
closegraph();
}
1. Output:
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING
Learning Outcomes:
Understanding Line Clipping Concepts – Learn how to determine if a line is inside,
outside, or needs clipping using region codes.
Working with Graphics in Turbo C++ – Gain hands-on experience with initgraph(), line(),
and closegraph() functions.
Bitwise Operations for Region Coding – Learn how to use bitwise operations to categorize
line endpoints efficiently.
Handling User Input and Decision Making – Understand how to take user inputs and
apply conditional statements to analyze positions.
Implementation of Cohen-Sutherland Logic – Get an introduction to a basic form of the
Cohen-Sutherland line clipping algorithm.