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++ > Miscellaneous Code Examples

Cement Inventry System (Project)

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 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632
/* Cement Inventry System (Project) */ //header files used #include<dos.h> #include <fstream.h> #include <string.h> #include <stdio.h> #include <conio.h> #include <graphics.h> #include<iostream.h> #include<iomanip.h> //global var. int choice,y_n=1; int c; int R_opt;char ch,a; char as= NULL; int ans; //to show the initial help void help() { gotoxy(33,1); cout<<"W E L C O M E"; gotoxy(33,2); cout<<"*************"; gotoxy(10,4); cout<<"############################################################"; gotoxy(10,6); cout<<" This project can keep record of daily cement transiction."; gotoxy(10,7); cout<<" This program is capable of holding any no. daily profile."; gotoxy(10,8); cout<<" In first option you can open cement inward entry form."; gotoxy(10,9); cout<<" In second option you can open cement outward entry form."; gotoxy(10,10); cout<<" In third option you can see status report"; gotoxy(10,12); cout<<"############################################################ "; cout<<"a Press any key to continue........."; getch(); } //to show the main menu void show_menu() { clrscr(); gotoxy(60,1); cout<<"Date :"<<__DATE__; // to show the system date gotoxy(32,3); cout<<"M A I N - M E N U"; gotoxy(32,4); cout<<"-----------------"; gotoxy(2,5); cout<<"***************************************************************"; gotoxy(15,6); cout<<"1. Cement Inward Entry"; gotoxy(15,8); cout<<"2. Cement Outward Entry"; gotoxy(15,10); cout<<"3. Cement Status Report"; gotoxy(15,12); cout<<"4. Exit"; gotoxy(2,13); cout<<"***************************************************************"; } // class contain the data of cement stock class cement { protected: struct info { char flage; long int R_challan; int dd1,mm1,yy1; char truck_no[15]; int dd2,mm2,yy2; int qtt; }f; fstream file; //creating object of fstream class }; //class for inward cement data class cement_in:public cement { public: cement_in(); void get_inward() ;// to get the inward cement information void inward_report() ;// to get inward cement report int stock_in(); void stock_date(); }; //class cement_in close //class for outward cement data class cement_out:public cement { public: cement_out(); void del_data(); //to get the data about delivery void outward_report(); //to get the outward cement report int stock_out(); //to get the total cement out }; //function to get the inward cement entry void cement_in :: get_inward() { file.seekp(0L,ios::end); do { clrscr(); gotoxy(25,3); cout<<"C E M E N T - I N W O R D - E N T R Y"; gotoxy(2,5); cout<<"==============================================================="; gotoxy(5,8); cout<<"Receipt Challan No.: "; gotoxy(5,10); cout<<"Challan Date:"; gotoxy(5,12); cout<<"Truck No.:"; gotoxy(5,14); cout<<"Receipt Date:"; gotoxy(5,16); cout<<"Quantity:"; gotoxy(22,16); cout<<"M.T"; gotoxy(2,19); cout<<"==============================================================="; gotoxy(2,22) ; cout<<"Enter the recieve challan no................"; turn:gotoxy(28,8); cin>>f.R_challan; if(f.R_challan>999999) { gotoxy(28,8); cout<<" "; gotoxy(2,22); cout<<"aChallan no. should not greater then 6 dig."; goto turn; } gotoxy(2,22); cout<<"Enter the challan date......................."; turn1:gotoxy(20,10); cin>>f.dd1; gotoxy(22,10); cout<<"-"; gotoxy(23,10); cin>>f.mm1; gotoxy(25,10); cout<<"-"; gotoxy(26,10); cin>>f.yy1; if(f.dd1>31||f.mm1>12||f.yy1>99) { gotoxy(20,10); cout<<" "; gotoxy(2,22); cout<<"aEnter the valid date........................"; goto turn1; } gotoxy(2,22); cout<<"Enter the truck no. ........................"; gotoxy(17,12); cin>>f.truck_no; gotoxy(2,22); cout<<"Enter the recieving date......................"; // for putting recieving date turn2:gotoxy(22,14); cin>>f.dd2; gotoxy(24,14); cout<<"-"; gotoxy(25,14); cin>>f.mm2; gotoxy(27,14); cout<<"-"; gotoxy(28,14); cin>>f.yy2; if(f.dd2>31||f.mm2>12||f.yy2>99) { gotoxy(22,14); cout<<" "; gotoxy(2,22); cout<<"aPlease enter the valid date ................."; goto turn2; } // quantity of cement gotoxy(2,22); cout<<"Enter the cement quantity.."; gotoxy(15,16); cin>>f.qtt; f.flage=NULL; file.write((char*)&f,sizeof(f)); gotoxy(2,22); cout<<"Enter another .......................yes-1/no-0 :"; cin>>ans; } while(ans==1); } //function for returning the total stock in store int cement_in::stock_in() { int temp=0; file.seekg(0L,ios::beg); while(file.read((char*)&f,sizeof(f))) { if(f.flage!='*') temp=temp+f.qtt; } file.clear(); return(temp); } /* function which gives the info of cement status at the particular date */ void cement_in::stock_date() { clrscr(); gotoxy(25,4); cout<<"R E C I E V E D - S T O C K"; gotoxy(25,5); cout<<"***************************"; int dd,mm,yy; gotoxy(4,10); cout<<"Please enter the date: "; gotoxy(30,10); cin>>dd; gotoxy(32,10); cout<<"-"; gotoxy(33,10); cin>>mm; gotoxy(35,10); cout<<"-"; gotoxy(36,10); cin>>yy; file.seekg(0L,ios::beg); while(file.read((char*)&f,sizeof(f))) { if(dd==f.dd1&&mm==f.mm1&&yy==f.yy1) { gotoxy(20,12); cout<<"************************************"; gotoxy(20,14); cout<<"aTotal recieved cement :"<<f.qtt<<" M.T"; gotoxy(20,15); cout<<"aChallan No. : "<<f.R_challan; gotoxy(20,16); cout<<"aTruck No. : "<<f.truck_no; gotoxy(20,17); cout<<"Challan date : "<<f.dd1<<"-"<<f.mm1<<"-"<<f.yy1; gotoxy(20,19); cout<<"*******************************"; } } } //function for inward cement report void cement_in::inward_report() { gotoxy(28,2); cout<<"I N W A R D - R E P O R T "; gotoxy(28,3); cout<<"-------------------------"; gotoxy(3,5); cout<<"*****************************************************"; gotoxy(3,6); cout<<"Challan No. Challan-Date Truck-No. Date of Receiv Quantity"; gotoxy(3,7); cout<<"********************************************************"; file.seekg(0L,ios::beg); while(file.read((char*)&f,sizeof(f))) { if(f.flage!='*') cout<<" "<<setw(10)<<f.R_challan<<setw(13)<<f.dd1<<"/"<<f.mm1<<"/"<<f.yy1 <<setw(12)<<f.truck_no<<setw(10)<<f.dd2<<"/"<<f.mm2<<"/"<<f.yy2<<setw(10)< <f.qtt; delay(200); } cout<<" ****************************************************"; file.clear(); } /* costructor of cement_in class which initialise the opening file cement.dat */ cement_in::cement_in() { file.open("cement.dat",ios::binary|ios::in|ios::out); if(!file) { cout<<"ERROR" ; getch(); } } // function of class delivery data , to get the entries of outward cement void cement_out::del_data() { file.seekp(0L,ios::end); do { clrscr(); gotoxy(28,5); cout<<"* O U T W A R D - E N T R Y *"; gotoxy(28,6); cout<<"------------------------------"; gotoxy(3,8); cout<<"*********************************************************"; gotoxy(3,9) ; cout<<"Delivery Challan No.:"; gotoxy(3,11); cout<<"Challan Date:"; gotoxy(3,13); cout<<"Dlivery Truck No.:"; gotoxy(3,15); cout<<"Date of Dispatch:"; gotoxy(3,17); cout<<"Quantity:"; gotoxy(26,17); cout<<"M.T."; gotoxy(3,18); cout<<"*********************************************************"; gotoxy(2,22); cout<<"Enter the delivery challan no......"; turn:gotoxy(25,9); cin>>f.R_challan; if(f.R_challan>999999) { gotoxy(25,9); cout<<" ";//to clear this line gotoxy(2,22); cout<<"aChallan no. should not greater then 6 dig."; goto turn; } gotoxy(2,22); cout<<"Enter the delivery challan date...."; turn1: gotoxy(25,11); cin>>f.dd1; //date of challan gotoxy(27,11) ; cout<<"-"; gotoxy(28,11); cin>>f.mm1; gotoxy(30,11); cout<<"-"; gotoxy(31,11); cin>>f.yy1; if(f.dd1>31||f.mm1>12||f.yy1>99) { gotoxy(25,11); cout<<" "; gotoxy(2,22); cout<<"aEnter the valid date........................"; goto turn1; } gotoxy(2,22); cout<<"Enter the delivery truck no. ....."; gotoxy(25,13); cin>>f.truck_no; gotoxy(2,22); cout<<"Enter the cement delivery date...."; turn2: gotoxy(25,15); cin>>f.dd2; //for date of deliver gotoxy(27,15) ; cout<<"-"; gotoxy(28,15); cin>>f.mm2; gotoxy(30,15); cout<<"-"; gotoxy(31,15); cin>>f.yy2; if(f.dd2>31||f.mm2>12||f.yy2>99) { gotoxy(25,15); cout<<" "; gotoxy(2,22); cout<<"aEnter the valid date........................"; goto turn2; //cursor again reset } gotoxy(2,22); cout<<"Enter the delivard cement.Qtt......."; gotoxy(20,17); cin>>f.qtt; f.flage=NULL; file.write((char*)&f,sizeof(f)); gotoxy(2,22); cout<<"aAdd more? Y/N.................."; cin>>a; }while(a=='y'||a=='Y'); } //end of function // function for outward cement menu display void report_menu(void) { clrscr(); gotoxy(31,3); cout<<" REPORT-MENU " ; gotoxy(31,4); cout<<"__________"; gotoxy(4,7); cout<<"*********************************************************"; gotoxy(10,9); cout<<"1.Daily Inward Cement Report."; gotoxy(10,11); cout<<"2.Daily Outward Cement Report."; gotoxy(10,13); cout<<"3.Stock."; gotoxy(10,15); cout<<"4.Exit."; gotoxy(4,17); cout<<"******************************************************** "; } //function for outward cement report void cement_out::outward_report() { gotoxy(30,3); cout<<"O U T W A R D - R E P O R T"; gotoxy(3,6); cout<<"**********************************************************"; gotoxy(3,7); cout<<"Challan Chl_date Truck_no Dispatch_date Quantity "; gotoxy(3,8); cout<<"*********************************************"; file.seekg(0L,ios::beg); while(file.read((char*)&f,sizeof(f))) { if(f.flage!='*') cout<<endl<<setw(5)<<f.R_challan<<setw(10)<<f.dd1<<"/"<<f.mm1<<"/"<<f.yy1<<setw(10); cout<<f.truck_no<<setw(10)<<f.dd2<<"/"<<f.mm2<<"/"<<f.yy2<<setw(10)<<f.qtt<<setw(12); delay(200); } cout<<" ********************************************************"; file.clear(); cout<<endl<<"Press any key to continue......"; getch(); } /*constructor of class cement_out which initialise the opening file ocem.dat*/ cement_out::cement_out() { file.open("ocem.dat",ios::binary|ios::in|ios::out); if(!file) { cout<<"ERROR" ; getch(); } } //function which returns the total qautity of outward cement int cement_out::stock_out() { int temp=0; gotoxy(28,1); cout<<"T O T A L - S T O C K"; gotoxy(28,2); cout<<"*********************"; file.seekg(0L,ios::beg); while(file.read((char*)&f,sizeof(f))) { if(f.flage!='*') temp=temp+f.qtt; } file.clear(); return(temp); } void stock_menu() { gotoxy(28,4); cout<<"S T O C K - S T A T U S "; gotoxy(28,5); cout<<"***********************"; gotoxy(17,7); cout<<"****************************************"; gotoxy(24,8); cout<<"1.Stock Today."; gotoxy(24,10); cout<<"2.Stock At Recieve Date."; gotoxy(17,11); cout<<"***************************************"; } void main() { for(int s=1000;s>100;s+50) { sound(s); delay(50); } nosound(); textcolor(5); clrscr(); long int passu; gotoxy(20,10); cout<<"Enter the password : "; cin>>passu ; if(passu==654321) { clrscr(); help(); do { cement_in obj1; //class objects cement_out obj2; clrscr(); show_menu(); cout<<endl<<"Enter your choice:"; cin>>choice; switch(choice) // main choice { //for inward cement entry case 1: clrscr(); obj1.get_inward(); break; // for outward cement entry case 2: clrscr(); obj2.del_data(); break; //for cement outward & inward report case 3: clrscr(); report_menu(); gotoxy(35,45); cout<<"Enter the choice:"; gotoxy(36,35); cin>>R_opt; switch(R_opt) { // for showing the inward cement report case 1: clrscr(); obj1.inward_report(); break; // for showing outward cement report case 2: clrscr(); obj2.outward_report(); break; // for stock status case 3: clrscr(); stock_menu(); cout<<endl<<"Enter your choice:"; cin>>c; switch(c) { case 1: clrscr(); int p= obj1.stock_in(); int q=obj2.stock_out(); gotoxy(50,5); cout<<"Date:"<<__DATE__; gotoxy(4,8); cout<<" aTotal present stock today :"<<p-q<<" M.T. "; getch(); break; case 2: clrscr(); obj1.stock_date(); getch(); break; } } //internal switch closed } //top switch closed cout<<endl<<" aDo you want to quit:-"; cin>>ch; }while(ch!='y'&&ch!='Y'); textcolor(6); } /*if password is not correct*/ else { gotoxy(20,12); cout<<"a Password is not correct" ; gotoxy(20,13); cout<<"a You are not authorised person"; getch(); } }

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.

In C++, classes and structs are blueprints that are used to create the instance of a class. Structs are used for lightweight objects such as Rectangle, color, Point, etc. Unlike class, structs in C++ are value type than reference type. It is useful if you have data that is not intended to be modified after creation of struct. C++ Structure is a collection of different data types. It is similar to the class that holds different types of data. A structure is declared by preceding the struct keyword followed by the identifier(structure name). Inside the curly braces, we can declare the member variables of different types.

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.

Execute system command. Invokes the command processor to execute a command. If command is a null pointer, the function only checks whether a command processor is available through this function, without invoking any command. The effects of invoking a command depend on the system and library implementation, and may cause a program to behave in a non-standard manner or to terminate.

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.

In C++, goto is a jump statement and sometimes also referred as unconditional jump statement. It can be used to jump from goto to a labeled statement within the same function. The target label must be within the same file and context. Please note that the use of goto statement is highly discouraged in any programming language because it makes difficult to trace the control flow of a program, making hard to understand and modify the program.

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.

Switch statement in C tests the value of a variable and compares it with multiple cases. Once the case match is found, a block of statements associated with that particular case is executed. Each case in a block of a switch has a different name/number which is referred to as an identifier. The value provided by the user is compared with all the cases inside the switch block until the match is found. If a case match is NOT found, then the default statement is executed, and the control goes out of the switch block. • The expression can be integer expression or a character expression. • Value-1, 2, n are case labels which are used to identify each case individually. Remember that case labels should not be same as it may create a problem while executing a program. Suppose we have two cases with the same label as '1'. Then while executing the program, the case that appears first will be executed even though you want the program to execute a second case. This creates problems in the program and

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.

Set position in output sequence. Sets the position where the next character is to be inserted into the output stream. Internally, the function accesses the output sequence by first constructing a sentry object without evaluating it. Then, if member fail returns true, the function returns. Otherwise, it calls either pubseekpos (1) or pubseekoff (2) on its associated stream buffer object (if any). Finally, it destroys the sentry object before returning. Notice that the function will work even if the eofbit flag is set before the call, but it will not modify it.

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.

It is a predefined function in "conio.h" (console input output header file) used to clear the console screen. It is a predefined function, by using this function we can clear the data from console (Monitor). Using of clrscr() is always optional but it should be place after variable or function declaration only. It is often used at the beginning of the program (mostly after variable declaration but not necessarily) so that the console is clear for our output.

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.

Set error state flags. Sets a new value for the stream's internal error state flags. The clear() method of ios class in C++ is used to change the current state of the specified flag by setting it. Hence this function changes the internal state of this stream. The current value of the flags is overwritten: All bits are replaced by those in state; If state is goodbit (which is zero) all error flags are cleared. In the case that no stream buffer is associated with the stream when this function is called, the badbit flag is automatically set (no matter the value for that bit passed in argument state). Note that changing the state may throw an exception, depending on the latest settings passed to member exceptions.

#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 C++, constructor is a special method which is invoked automatically at the time of object creation. It is used to initialize the data members of new object generally. The constructor in C++ has the same name as class or structure. Constructors are special class functions which performs initialization of every object. The Compiler calls the Constructor whenever an object is created. Constructors initialize values to object members after storage is allocated to the object. Whereas, Destructor on the other hand is used to destroy the class object. • Default Constructor: A constructor which has no argument is known as default constructor. It is invoked at the time of creating object.

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 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.

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.

The main purpose of C++ programming is to add object orientation to the C programming language and classes are the central feature of C++ that supports object-oriented programming and are often called user-defined types. A class is used to specify the form of an object and it combines data representation and methods for manipulating that data into one neat package. The data and functions within a class are called members of the class.

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.

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.

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.

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.

Use the textcolor function to define what color you want to use for text. You can use this function to vary the text colors of your output. Colors must be written in all caps, or expressed as a numeral. Now, if you want your text to blink then while calling the textcolor() function pass the color and also say BLINK. This will like this: textcolor(BLUE+BLINK).

Set field width. Sets the field width to be used on output operations. The C++ function std::setw behaves as if member width were called with n as argument on the stream on which it is inserted/extracted as a manipulator (it can be inserted/extracted on input streams or output streams). It is used to sets the field width to be used on output operations. This manipulator is declared in header <iomanip>. This method accepts n as a parameter which is the integer argument corresponding to which the field width is to be set. This function returns an object of unspecified type. The setw function should only be used as a stream manipulator.

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.

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.

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 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.

A predefined object of the class called iostream class is used to insert the new line characters while flushing the stream is called endl in C++. This endl is similar to \n which performs the functionality of inserting new line characters but it does not flush the stream whereas endl does the job of inserting the new line characters while flushing the stream. Hence the statement cout<<endl; will be equal to the statement cout<< '\n' << flush; meaning the new line character used along with flush explicitly becomes equivalent to the endl statement in C++.

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.