Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


C++ Programming Code Examples

C++ > Computer Graphics Code Examples

Telephone directory which can be used to store, edit, search data

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
/* Telephone directory which can be used to store, edit, search data */ #include<iostream.h> #include<fstream.h> #include<graphics.h> #include<process.h> #include<io.h> #include<dos.h> #include<conio.h> #include<stdio.h> #include<string.h> class telephone { char name[25]; char address[40]; char phoneno[15]; public: telephone(){ } telephone(char nam[25], char add[40], char phone[15]) { strcpy(name,nam); strcpy(address,add); strcpy(phoneno,phone); } void init(); void button(int x1,int y1,int x2,int y2,char str[]); int press(int,int,int,int); int unpress(int,int,int,int); int mouseini(); int showmp(); int hidemp(); int getmp(int *button,int *x,int *y); int setmp(); int click(int x1,int y1,int x2,int y2,char str[]); int screen(); void login(); void search(); void delete1(); void insert(); void update(); void display() { cout<<" Name : "<<name; cout<<" Address : "<<address; cout<<" Phone Number: "<<phoneno; } int compare(char nam1[25]) { if(strcmp(nam1,name)==0) return 1; else return 0; } }; void telephone::login() { setcolor(15); line (320-150,320-13,320+150,320-13); line (320-150,320+12,320+150,320+12); line (320-150,320-13,320-150,320+12); line (320+150,320+12,320+150,320-13); int s=30,w; gotoxy(20,23); cout<<"LOADING . . ."; for (int x1=171,x2=171,y1=308,y2=331,y=1,S=0;x1<470;x1++,x2++,y++,S++) { setcolor(1); line (x1,y1,x2,y2); w=(x1-169)/3; for (int i=34; i<=78; i++) { gotoxy(i,23) ; cout <<" " ; } gotoxy(34,23); cout<<w<<"%"; if (x2>270) s=45; if (x2>370) s=10; if (x2==320) delay(999); else delay(s); } delay(800); for (int i=27; i<=78; i++) { gotoxy(i,23) ; cout <<" " ; } } void telephone::insert() { telephone tel1; fstream file; file.open("Phone.txt",ios::app); tel1.init(); file.write((char *) &tel1, sizeof(tel1)); setcolor(7); outtextxy(250,250,"Inserting Record....."); file.close(); delay(3000); } void telephone::init() { cout<<" Enter Name : "; cin.getline(name,25); cout<<" Enter Address : "; cin.getline(address,40); cout<<" Enter Phone Number: "; cin.getline(phoneno,15); } void telephone::delete1() { telephone tel1; fstream file ; char nam[25],nam1[25]; strcpy(nam1,""); cout<<"Enter the Name to be deleted: "; cin>>nam; file.open("Phone.txt", ios::in) ; fstream temp ; temp.open("temp.txt", ios::out) ; file.seekg(0,ios::beg) ; while (file.read((char *) &tel1, sizeof(telephone))) { if(!tel1.compare(nam)) temp.write((char *) &tel1, sizeof(telephone)) ; else strcpy(nam1,nam); } file.close() ; temp.close() ; setcolor(7); if(strlen(nam1)!=0) { file.open("Phone.txt", ios::out) ; temp.open("temp.txt", ios::in) ; temp.seekg(0,ios::beg) ; while (temp.read((char *) &tel1, sizeof(telephone))) { file.write((char *) &tel1, sizeof(telephone)) ; } file.close() ; temp.close() ; outtextxy(250,250,"Deleting Record....."); } else outtextxy(250,250,"Record not found"); delay(3000); } void telephone::update() { telephone tel1; fstream file ; char nam[25],nam1[25]; strcpy(nam1,""); cout<<"Enter the Name to be updated: "; cin>>nam; file.open("Phone.txt", ios::in) ; fstream temp ; temp.open("temp.txt", ios::out) ; file.seekg(0,ios::beg) ; while (file.read((char *) &tel1, sizeof(telephone))) { if(!tel1.compare(nam)) temp.write((char *) &tel1, sizeof(telephone)) ; else strcpy(nam1,nam); } file.close() ; temp.close() ; setcolor(7); if(strlen(nam1)!=0) { file.open("Phone.txt", ios::out) ; temp.open("temp.txt", ios::in) ; temp.seekg(0,ios::beg) ; while (temp.read((char *) &tel1, sizeof(telephone))) { file.write((char *) &tel1, sizeof(telephone)) ; } file.close() ; temp.close() ; char nam[25],add[40],ph[15]; file.open("Phone.txt",ios::app); cout<<" Enter Name : "; cin.getline(nam,25);cin.getline(nam,25); cout<<" Enter Address : "; cin.getline(add,40); cout<<" Enter Phone Number: "; cin.getline(ph,15); tel1=telephone(nam,add,ph); file.write((char *) &tel1, sizeof(tel1)); file.close(); outtextxy(250,250,"Updating Record....."); } else outtextxy(250,250,"Record not found"); delay(3000); } void telephone::search() { fstream file; telephone tel1; int i=1; char nam[25]; file.open("Phone.txt",ios::in); cout<<"Enter name to be Searched: "; cin>>nam; file.seekg(0,ios::beg); while(file.read((char *) &tel1, sizeof(telephone))) { if(tel1.compare(nam)) { tel1.display(); i=0; break ; } } file.close() ; if(i) { setcolor(7); outtextxy(250,250,"Record not found"); } getch(); } void telephone:: button(int x1,int y1,int x2,int y2,char str[]) { int xc,yc,i=0,l=0; while(i<strlen(str)) { l+=4; i++; } xc=(x2-x1)/2+x1-l; yc=(y2-y1)/2+y1; unpress(x1,y1,x2,y2); settextstyle(0,0,0); setcolor(11); outtextxy(xc,yc,str); } int telephone:: unpress(int x1,int y1,int x2,int y2) { setlinestyle(0,1,1); setfillstyle(1,1); bar(x1,y1,x2,y2); setcolor(WHITE); line(x1,y1,x2,y1); line(x1,y1,x1,y2); setcolor(0); line(x1,y2,x2,y2); line(x2,y1,x2,y2); return 0; } int telephone:: press(int x1,int y1,int x2,int y2) { setlinestyle(0,1,1); setfillstyle(1,1); bar(x1,y1,x2,y2); setcolor(0); line(x1,y1,x2,y1); line(x1,y1,x1,y2); setcolor(WHITE); line(x1,y2,x2,y2); line(x2,y1,x2,y2); return 0; } int telephone:: mouseini() { union REGS i,o; i.x.ax=0; int86(0x33,&i,&o); return(o.x.ax); } int telephone:: showmp() { union REGS i,o; i.x.ax=1; int86(0x33,&i,&o); return 0; } int telephone:: hidemp() { union REGS i,o; i.x.ax=2; int86(0x33,&i,&o); return 0; } int telephone:: getmp(int *button,int *x,int *y) { union REGS i,o; i.x.ax=3; int86(0x33,&i,&o); *button=o.x.bx; *x=o.x.cx; *y=o.x.dx; return 0; } int telephone:: setmp() { union REGS i,o; i.x.ax=4; int mx=getmaxx(),my=getmaxy(); i.x.cx=(3*mx/4)+20; i.x.dx=(3*my/4)+20; int86(0x33,&i,&o); return 0; } int telephone:: click(int x1,int y1,int x2,int y2,char str[]) { int button,x,y; int xc,yc,i=0,l=0; while(i<strlen(str)) { l+=4; i++; } xc=(x2-x1)/2+x1-l; yc=(y2-y1)/2+y1; getmp(&button,&x,&y); if( (x>x1 && x<x2) && (y>y1 && y<y2) && button==1) { hidemp(); press(x1,y1,x2,y2); setcolor(11); settextstyle(0,0,0); outtextxy(xc,yc,str); showmp(); while((button==1)) getmp(&button,&x,&y); hidemp(); unpress(x1,y1,x2,y2); showmp(); setcolor(11); settextstyle(0,0,0); outtextxy(xc,yc,str); for(i=50;i<500;i=i+50) { delay(10); sound(i+200); } showmp(); nosound(); setcolor(11); settextstyle(0,0,0); outtextxy(xc,yc,str); return 0; } else return 1; } int telephone:: screen() { settextstyle(0,1,6); setcolor(11); outtextxy(100,30,"TELEPHONE"); outtextxy(600,30,"DIRECTORY"); setmp(); button(250,100,400,150,"Insert"); button(250,150,400,200,"Delete"); button(250,200,400,250,"Update"); button(250,250,400,300,"Search"); button(250,300,400,350,"Exit"); while(1) { if(click(250,100,400,150,"Insert")==0) { cleardevice(); insert(); return 0; } if(click(250,150,400,200,"Delete")==0) { cleardevice(); delete1(); return 0; } if(click(250,200,400,250,"Update")==0) { cleardevice(); update(); return 0; } if(click(250,250,400,300,"Search")==0) { cleardevice(); search(); return 0; } if(click(250,300,400,350,"Exit")==0) exit(0); } } void main() { char user[25]="User Name",*pass,*pass1="user"; int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,""); while(1) { cleardevice(); settextstyle(0,0,1); outtextxy(250,250,"User Name:"); outtextxy(250,265,"Password :"); outtextxy(335,250,user); pass=getpass(""); if(strcmp(pass,pass1)==0) { cleardevice(); telephone tel; char op[8],cp[8],np[8]; tel.login(); while(1) { cleardevice(); tel.mouseini(); tel.showmp(); tel.screen(); } } else { cleardevice(); settextstyle(0,0,2); outtextxy(250,250,"Illegal User...."); delay(3000); } } }

setcolor() function is used to set the foreground color in graphics mode. After resetting the foreground color you will get the text or any other shape which you want to draw in that color. setcolor sets the current drawing color to color, which can range from 0 to getmaxcolor. The current drawing color is the value to which pixels are set when lines, and so on are drawn. The drawing colors shown below are available for the CGA and EGA, respectively.

The nosound() function in C language is used to stop the sound played by sound() function. The nosound() function is simply silent the system. The sound() and nosound() functions are very useful as they can create very nice music with the help of programming and our user can enjoy music during working in out the program.

In computer programming, we use the if statement to run a block code only when a certain condition is met. An if statement can be followed by an optional else statement, which executes when the boolean expression is false. There are three forms of if...else statements in C++: • if statement, • if...else statement, • if...else if...else statement, The if statement evaluates the condition inside the parentheses ( ). If the condition evaluates to true, the code inside the body of if is executed. If the condition evaluates to false, the code inside the body of if is skipped.

Settextstyle function is used to change the way in which text appears, using it we can modify the size of text, change direction of text and change the font of text. settextstyle sets the text font, the direction in which text is displayed, and the size of the characters. A call to settextstyle affects all text output by outtext and outtextxy.

The header file graphics.h contains setfillstyle() function which sets the current fill pattern and fill color. Current fill pattern and fill color is used to fill the area. setfillstyle sets the current fill pattern and fill color. To set a user-defined fill pattern, do not give a pattern of 12 (USER_FILL) to setfillstyle; instead, call setfillpattern.

Open file. Opens the file identified by argument filename, associating it with the stream object, so that input/output operations are performed on its content. Argument mode specifies the opening mode. If the stream is already associated with a file (i.e., it is already open), calling this function fails. The file association of a stream is kept by its internal stream buffer: Internally, the function calls rdbuf()->open(filename,mode|ios_base::out). The function clears the stream's state flags on success (setting them to goodbit). In case of failure, failbit is set.

Write block of data. Inserts the first n characters of the array pointed by s into the stream. This function simply copies a block of data, without checking its contents: The array may contain null characters, which are also copied without stopping the copying process. Internally, the function accesses the output sequence by first constructing a sentry object. Then (if good), it inserts character into its associated stream buffer object as if calling its member function sputc until n characters have been written or until an insertion fails (in this case it sets the badbit flag). Finally, it destroys the sentry object before returning.

setlinestyle() is a function which is used to draw the line of different- different styles. Turbo C compiler provides five line styles that are solid, dotted, center, dashed and user defined. These all five line styles are already enumerated in graphics.h header file as given below: setlinestyle() function contains three parameters type, pattern and thickness. First parameter contains the type of line like solid, dashed or dotted etc. Second parameter is applicable only when type of line is user defined. Third parameter specifies the thickness of the line it takes values 1 (line thickness of one pixel (normal)) or 3 (line thickness of three pixels (thick).

Positions cursor in text window. The gotoxy() function places the cursor at the desired location on the screen. This means it is possible to change the cursor location on the screen using the gotoxy() function. It is basically used to print text wherever the cursor is moved. If the coordinates are in any way invalid the call to gotoxy is ignored. Neither argument to gotoxy can be zero.

The exit function terminates the program normally. Automatic objects are not destroyed, but static objects are. Then, all functions registered with atexit are called in the opposite order of registration. The code is returned to the operating system. An exit code of 0 or EXIT_SUCCESS means successful completion. If code is EXIT_FAILURE, an indication of program failure is returned to the operating system. Other values of code are implementation-defined. Calls all functions registered with the atexit() function, and destroys C++ objects with static storage duration, all in last-in-first-out (LIFO) order. C++ objects with static storage duration are destroyed in the reverse order of the completion of their constructor. (Automatic objects are not destroyed as a result of calling exit().)

bar() function is a C graphics function that is used to draw graphics in the C programming language. The graphics.h header contains functions that work for drawing graphics. The bar() function is also defined in the header file. Bar function is used to draw a 2-dimensional, rectangular filled in bar. Coordinates of left top and right bottom corner are required to draw the bar. Left specifies the X-coordinate of top left corner, top specifies the Y-coordinate of top left corner, right specifies the X-coordinate of right bottom corner, bottom specifies the Y-coordinate of right bottom corner. Current fill pattern and fill color is used to fill the bar. To change fill pattern and fill color use setfillstyle.

The cout is a predefined object of ostream class. It is connected with the standard output device, which is usually a display screen. The cout is used in conjunction with stream insertion operator (<<) to display the output on a console. On most program environments, the standard output by default is the screen, and the C++ stream object defined to access it is cout. The "c" in cout refers to "character" and "out" means "output". Hence cout means "character output". The cout object is used along with the insertion operator << in order to display a stream of characters.

The header file graphics.h contains getmaxy() function which returns the maximum Y coordinate for current graphics mode and driver. getmaxy returns the maximum (screen-relative) y value for the current graphics driver and mode. For example, on a CGA in 320*200 mode, getmaxy returns 199. getmaxy is invaluable for centering, determining the boundaries of a region onscreen, and so on.

In C++ programming we are using the iostream standard library, it provides cin and cout methods for reading from input and writing to output respectively. To read and write from a file we are using the standard C++ library called fstream. Let us see the data types define in fstream library is: • ofstream: This data type represents the output file stream and is used to create files and to write information to files. • ifstream: This data type represents the input file stream and is used to read information from files. • fstream: This data type represents the file stream generally, and has the capabilities of both ofstream and ifstream which means it can create files, write information to files, and read information from files.

In while loop, condition is evaluated first and if it returns true then the statements inside while loop execute, this happens repeatedly until the condition returns false. When condition returns false, the control comes out of loop and jumps to the next statement in the program after while loop. The important point to note when using while loop is that we need to use increment or decrement statement inside while loop so that the loop variable gets changed on each iteration, and at some point condition returns false. This way we can end the execution of while loop otherwise the loop would execute indefinitely. A while loop that never stops is said to be the infinite while loop, when we give the condition in such a way so that it never returns false, then the loops becomes infinite and repeats itself indefinitely.

The header file graphics.h contains cleardevice() function. cleardevice() is a function which is used to clear the screen by filling the whole screen with the current background color. It means that cleardevice() function is used to clear the whole screen with the current background color and it also sets the current position to (0,0). Both clrscr() and cleardevice() functions are used to clear the screen but clrscr() is used in text mode and cleardevice function is used in the graphics mode.

The getch() is a predefined non-standard function that is defined in conio.h header file. It is mostly used by the Dev C/C++, MS- DOS's compilers like Turbo C to hold the screen until the user passes a single value to exit from the console screen. It can also be used to read a single byte character or string from the keyboard and then print. It does not hold any parameters. It has no buffer area to store the input character in a program. The getch() function does not accept any parameter from the user. It returns the ASCII value of the key pressed by the user as an input.

Get string length. Returns the length of the C string str. C++ strlen() is an inbuilt function that is used to calculate the length of the string. It is a beneficial method to find the length of the string. The strlen() function is defined under the string.h header file. The strlen() takes a null-terminated byte string str as its argument and returns its length. The length does not include a null character. If there is no null character in the string, the behavior of the function is undefined.

To create a program in Graphics Mode, the first step would be to include the header file graphics.h. This file is required for Graphics programming. After this, the graphics have to be initialized. C Language supports 16 Bit's MS-DOS environment. Initializing the Graphics mode is to call various functions, one such is called initgraph. initgraph initializes the graphics system by loading a graphics driver from disk (or validating a registered driver), and putting the system into graphics mode. To start the graphics system, first call the initgraph function. initgraph loads the graphics driver and puts the system into graphics mode. You can tell initgraph to use a particular graphics driver and mode, or to autodetect the attached video adapter at run time and pick the corresponding driver. If you tell initgraph to autodetect, it calls detectgraph to select a graphics driver and mode. initgraph also resets all graphics settings to their defaults (current position, palette, color, viewport, and so on)

outtextxy displays a text string in the viewport at the given position (x, y), using the current justification settings and the current font, direction, and size. To maintain code compatibility when using several fonts, use textwidth and textheight to determine the dimensions of the string. If a string is printed with the default font using outtext or outtextxy, any part of the string that extends outside the current viewport is truncated. outtextxy is for use in graphics mode; it will not work in text mode.

As the name already suggests, these operators help in assigning values to variables. These operators help us in allocating a particular value to the operands. The main simple assignment operator is '='. We have to be sure that both the left and right sides of the operator must have the same data type. We have different levels of operators. Assignment operators are used to assign the value, variable and function to another variable. Assignment operators in C are some of the C Programming Operator, which are useful to assign the values to the declared variables. Let's discuss the various types of the assignment operators such as =, +=, -=, /=, *= and %=. The following table lists the assignment operators supported by the C language:

Read block of data. Extracts n characters from the stream and stores them in the array pointed to by s. This function simply copies a block of data, without checking its contents nor appending a null character at the end. If the input sequence runs out of characters to extract (i.e., the end-of-file is reached) before n characters have been successfully read, the array pointed to by s contains all the characters read until that point, and both the eofbit and failbit flags are set for the stream. Internally, the function accesses the input sequence by first constructing a sentry object (with noskipws set to true). Then (if good), it extracts characters from its associated stream buffer object as if calling its member functions sbumpc or sgetc, and finally destroys the sentry object before returning.

Check whether eofbit is set. Returns true if the eofbit error state flag is set for the stream. This flag is set by all standard input operations when the End-of-File is reached in the sequence associated with the stream. Note that the value returned by this function depends on the last operation performed on the stream (and not on the next). Operations that attempt to read at the End-of-File fail, and thus both the eofbit and the failbit end up set. This function can be used to check whether the failure is due to reaching the End-of-File or to some other reason.

Our system can create various sounds on different frequencies. The sound() is very useful as it can create very nice music with the help of programming and our user can enjoy music during working in out the program. Sound function produces the sound of a specified frequency. Used for adding music to a C++ program.

The sizeof() is an operator that evaluates the size of data type, constants, variable. It is a compile-time operator as it returns the size of any variable or a constant at the compilation time. The size, which is calculated by the sizeof() operator, is the amount of RAM occupied in the computer. The sizeof is a keyword, but it is a compile-time operator that determines the size, in bytes, of a variable or data type. The sizeof operator can be used to get the size of classes, structures, unions and any other user defined data type. The data_type can be the data type of the data, variables, constants, unions, structures, or any other user-defined data type.

Compare two strings. Compares the C string str1 to the C string str2. This function starts comparing the first character of each string. If they are equal to each other, it continues with the following pairs until the characters differ or until a terminating null-character is reached. This function performs a binary comparison of the characters. For a function that takes into account locale-specific rules, see strcoll. The strcmp() function in C++ compares two null-terminating strings (C-strings). The comparison is done lexicographically. It is defined in the cstring header file.

In computer programming, loops are used to repeat a block of code. For example, when you are displaying number from 1 to 100 you may want set the value of a variable to 1 and display it 100 times, increasing its value by 1 on each loop iteration. When you know exactly how many times you want to loop through a block of code, use the for loop instead of a while loop. A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.

Break statement in C++ is a loop control statement defined using the break keyword. It is used to stop the current execution and proceed with the next one. When a compiler calls the break statement, it immediately stops the execution of the loop and transfers the control outside the loop and executes the other statements. In the case of a nested loop, break the statement stops the execution of the inner loop and proceeds with the outer loop. The statement itself says it breaks the loop. When the break statement is called in the program, it immediately terminates the loop and transfers the flow control to the statement mentioned outside the loop.

Get line from stream into string. The cin is an object which is used to take input from the user but does not allow to take the input in multiple lines. To accept the multiple lines, we use the getline() function. It is a pre-defined function defined in a <string.h> header file used to accept a line or a string from the input stream until the delimiting character is encountered. Extracts characters from is and stores them into str until the delimitation character delim is found (or the newline character, '\n', for (2)). The extraction also stops if the end of file is reached in is or if some other error occurs during the input operation. If the delimiter is found, it is extracted and discarded (i.e. it is not stored and the next input operation will begin after it).

Search range for subsequence. Searches the range [first1,last1) for the first occurrence of the sequence defined by [first2,last2), and returns an iterator to its first element, or last1 if no occurrences are found. The elements in both ranges are compared sequentially using operator== (or pred, in version (2)): A subsequence of [first1,last1) is considered a match only when this is true for all the elements of [first2,last2). This function returns the first of such occurrences. For an algorithm that returns the last instead, see find_end. The function shall not modify any of its arguments.

Copy string. Copies the C string pointed by source into the array pointed by destination, including the terminating null character (and stopping at that point). To avoid overflows, the size of the array pointed by destination shall be long enough to contain the same C string as source (including the terminating null character), and should not overlap in memory with source. strcpy() is a standard library function in C/C++ and is used to copy one string to another. In C it is present in string.h header file and in C++ it is present in cstring header file. It copies the whole string to the destination string. It replaces the whole string instead of appending it. It won't change the source string.

Set position in input sequence. Sets the position of the next character to be extracted from the input stream. Sets the position of the next character to be extracted from the input stream. seekg() is a function in the iostream library (part of the standard library) that allows you to seek to an arbitrary position in a file. It is used in file handling to sets the position of the next character to be extracted from the input stream from a given file. Internally, the function accesses the input sequence by first constructing a sentry object (with noskipws set to true). Then (if good), it calls either pubseekpos (1) or pubseekoff (2) on its associated stream buffer object (if any). Finally, it destroys the sentry object before returning. Calling this function does not alter the value returned by gcount.

A program shall contain a global function named main, which is the designated start of the program in hosted environment. main() function is the entry point of any C++ program. It is the point at which execution of program is started. When a C++ program is executed, the execution control goes directly to the main() function. Every C++ program have a main() function.

The cin object is used to accept input from the standard input device i.e. keyboard. It is defined in the iostream header file. C++ cin statement is the instance of the class istream and is used to read input from the standard input device which is usually a keyboard. The extraction operator(>>) is used along with the object cin for reading inputs. The extraction operator extracts the data from the object cin which is entered using the keyboard. The "c" in cin refers to "character" and "in" means "input". Hence cin means "character input". The cin object is used along with the extraction operator >> in order to receive a stream of characters.

The header file graphics.h contains getmaxx() function which returns the maximum X coordinate for current graphics mode and driver. getmaxx() returns the maximum (screen-relative) x value for the current graphics driver and mode. For example, on a CGA in 320*200 mode, getmaxx returns 319. getmaxx is invaluable for centering, determining the boundaries of a region onscreen, and so on.

The header file graphics.h contains line() function which is used to draw a line from a point(x1, y1) to point(x2, y2) i.e. (x1, y1) and (x2, y2) are end points of the line. The function line() draws a line on the graphics screen between two specified points. So this function requires four parameters namely x1, y1, x2, and y2 to represent two points. This function draws a line from (x1, y1) coordinates to (x2, y2) coordinates on the graphics screen.

delay() function is used to hold the program's execution for given number of milliseconds, it is declared in dos.h header file. There can be many instances when we need to create a delay in our programs. C++ provides us with an easy way to do so. We can use a delay() function for this purpose in our code. We can run the code after a specific time in C++ using delay() function.

#include is a way of including a standard or user-defined file in the program and is mostly written at the beginning of any C/C++ program. This directive is read by the preprocessor and orders it to insert the content of a user-defined or system header file into the following program. These files are mainly imported from an outside source into the current program. The process of importing such files that might be system-defined or user-defined is known as File Inclusion. This type of preprocessor directive tells the compiler to include a file in the source code program.











In the C++ Programming, The static keyword allows a variable to maintain its value among different function calls. If the value of a static variable changes when the variable has been