C++ Programming Code Examples
C++ > Beginners Lab Assignments Code Examples
Banking Project
/* Banking Project */
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<iostream.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
void punit (void);
void deposit(void);
void addrecord();
void delrecord();
void modrecord();
void disprecord();
void dispall();
void withdraw();
float w,z;
class account
{
int accountno,cls;
char name[30],type;
float deposit,withdraw;
public:
account()
{
deposit=withdraw=0;
}
int giveaccountno()
{
return accountno;
}
void getdata(int mrno)
{
accountno=mrno+1;
cout<<"ACCOUNT NUMBER :: ";
cout<<accountno<<"
";
cout<<"ENTER YOUR NAME :: ";
gets(name);
cout<<"
";
cout<<"ENTER TYPE OF ACCOUNT SAVING(s)/CURRENT(c) :: ";
cin>>type;
cout<<"
";
cout<<"ENTER INITIAL AMOUNT ::Rs ";cin>>deposit;
cout<<"
";
}
void withdrawal(int m)
{
cout<<"AMOUNT BEFORE WITHDRAWING::Rs "<<deposit<<"
";
deposit=deposit-m;
cout<<"AMOUNT AFTER WITHDRAWING::Rs "<<deposit;
}
void deposital(int m)
{
cout<<"AMOUNT BEFORE DEPOSIT::Rs "<<deposit<<"
";
deposit=deposit+m;
cout<<"AMOUNT AFTER DEPOSIT ::Rs "<<deposit;
}
void dispdata()
{
int scrnt=0;
if(scrnt==1)
{
clrscr();
cout<<"DISPLAY ALL MENU
";
scrnt=0;
}
cout<<"
ACCOUNT NUMBER ::";
cout<<accountno;
cout<<"
NAME OF DEPOSITER ::";
cout<<name;
cout<<"
TYPE OF ACCOUNT SAVING(s)/CURRENT(c) :: ";
cout<<type;
cout<<"
BALANCE ::Rs ";
cout<<deposit;
scrnt++;
}
};
void main()
{
int menuch;
punit();
do
{
clrscr();
textcolor(14);
textbackground(1);
cout<<"
MAIN MENU
";
cout<<"
1.NEW ACCOUNT ";
cout<<"
2.CLOSE AN ACCOUNT ";
cout<<"
3.MODIFY AN ACCOUNT ";
cout<<"
4.DISPLAY AN ACCOUNT ";
cout<<"
5.DISPLAY ALL RECORDS ";
cout<<"
6.WITHDRAW AMOUNT";
cout<<"
7.DEPOSIT AMOUNT";
cout<<"
8.EXIT ";
cout<<"
ENTER YOUR CHOICE ";
cin>>menuch;
switch(menuch)
{
case 1:addrecord();break;
case 2:delrecord();break;
case 3:modrecord();break;
case 4:disprecord();break;
case 5:dispall();break;
case 6:withdraw();break;
case 7:deposit();break;
}
}
while(menuch!=8);
}
void addrecord()
{
account obj_1,obj_2;
fstream fout;
fout.open("banking.txt",ios::in|ios::binary);
if(!fout)
{
cout<<"FILE OPEN ERROR ";getch();return;}
int recsize=sizeof(account);
fout.seekg(0,ios::end);
fout.seekg(-1*recsize,ios::cur);
fout.read((char*)&obj_1,recsize);
int mrno=obj_1.giveaccountno();
fout.close();
clrscr();
cout<<"ADD MENU
";
obj_2.getdata(mrno);
fout.open("banking.txt",ios::app|ios::binary);
if(!fout)
{
cout<<"FILE OPEN ERROR ";getch();return;}
fout.write((char*)&obj_2,recsize);
cout<<"
RECORD ADDED TO DATABASE"<<"
Press any key to
continue... ";
getch();
fout.close();
}
void dispall()
{
account obj_3;
fstream fout;
int recsize=sizeof(account);
int countrec=0;
clrscr();
cout<<"
DISPLAY ALL MENU
";
fout.open("banking.txt",ios::in);
if(!fout)
{
cout<<"FILE OPEN ERROR ";getch();return;}
while(fout.read((char*)&obj_3,recsize))
{
obj_3.dispdata();
countrec++;
cout<<"
PRESS ANY KEY FOR NEXT....";
getch();
}
clrscr();
cout<<"
END OF FILE.TOTALNUMBER OF RECORDS..."<<countrec;
cout<<"
Press any key......";
getch();
fout.close();}
void disprecord()
{
account obj_4;
fstream fout;
int mrno,flag=0;
int recsize=sizeof(account);
clrscr();
cout<<"
DISPLAY A RECORD MENU
";
fout.open("banking.txt",ios::in);
if(!fout)
{
cout<<"FILE OPEN ERROR ";getch();return;}
cout<<"
ENTER THE ACCOUNT NUMBER ";cin>>mrno;
while(fout.read((char*)&obj_4,recsize))
{
if (obj_4.giveaccountno()==mrno)
{
obj_4.dispdata();
cout<<"
Press any key.....";
flag=1;break;
}
}
if(flag==0)
{
cout<<"
NO SUCH ACCOUNT EXIST ";
cout<<"
Press any key......";
}
getch();
fout.close();
}
void delrecord()
{
account obj_5;
fstream fout,temp;
int mrno,flag;
int recsize=sizeof(account);
clrscr();
cout<<"
CLOSE ACCOUNT MENU
";
fout.open("banking.txt",ios::in);
if(!fout)
{
cout<<"FILE OPEN ERROR ";
getch();
return;
}
temp.open("temp.txt",ios::app|ios::binary);
if(!temp)
{
cout<<"FILE OPEN ERROR ";
getch();
return;
}
cout<<"
ENTER THE ACCOUNT NUMBER ";
cin>>mrno;
while(fout.read((char*)&obj_5,recsize))
{
if(obj_5.giveaccountno()==mrno)
{
obj_5.dispdata();
char confirm;
cout<<"
ARE YOU SURE TO DELETE IT(Y/N)..";cin>>confirm;
if(confirm=='Y'||confirm=='y')
{
fout.read((char*)&obj_5,recsize);
cout<<"
RECORD DELETED FORM DATABASE
";
cout<<"press any key....";
flag=1;
if(!fout)
break;
}
flag=1;
}
temp.write((char*)&obj_5,recsize);}
fout.close();
temp.close();
remove("banking.txt");
rename("temp.txt","banking.txt");
if(flag==0)
{
cout<<"
NO SUCH ACCOUNT EXIST";
cout<<"Press any key.....";
}
getch();
}
void modrecord()
{
account obj_6;
fstream fout;
int mrno,flag=0;
int recsize=sizeof(account);
clrscr();
cout<<"
MODIFY RECORD MENU
";
fout.open("banking.txt",ios::in|ios::out|ios::binary);
if(!fout)
{
cout<<"FILE OPEN ERROR ";
getch();
return;
}
fout.seekg(ios::beg);
cout<<"
ENTER RECORD NUMBER ";
cin>>mrno;
while(fout.read((char*)&obj_6,recsize))
{
if(obj_6.giveaccountno()==mrno)
{
clrscr();
cout<<"
MODIFY MENU
";
obj_6.dispdata();
int tmprno=obj_6.giveaccountno()-1;
account obj_7;
cout<<"
ENTER NEW DATA
";
obj_7.getdata(tmprno);
char confirm;
cout<<"
ARE YOU SURE(Y/N)
";
cin>>confirm;
if(confirm=='Y'||confirm=='y')
{
fout.seekg(-1*recsize,ios::cur);
fout.write((char*)&obj_7,recsize);
cout<<"
RECORD MODIFIED
";
cout<<"Press any key.....";
flag=1;
}
}
if(flag==0)
{
cout<<"NO SUCH RECORD EXIST
";
cout<<"Press any key.....";
}
}
fout.close();
getch();
}
void withdraw()
{
account obj_9;
fstream fout;
int mrno=0;
int recsize=sizeof(account);
clrscr();
cout<<"
WITHDRAWAL MENU
";
fout.open("banking.txt",ios::in|ios::out|ios::binary);
if(!fout)
{
cout<<"FILE OPEN ERROR ";getch();return;}
fout.seekg(ios::beg);
cout<<"
ENTER ACCOUNT NUMBER ";
cin>>mrno;
while(fout.read((char*)&obj_9,recsize))
{
if(obj_9.giveaccountno()==mrno)
{
clrscr();
cout<<"
ENTER THE AMOUNT TO BE WITHDRAWED::Rs ";
cin>>w;
obj_9.withdrawal(w);
fout.seekg(-1*recsize,ios::cur);
fout.write((char*)&obj_9,recsize);
}
}
fout.close();
getch();
}
void punit(void)
{
int gd=5, gm, errorcode;
int col,i=0,j;
initgraph(&gd, &gm, "c:\tc\bgi");
while(5*i<=700)
{
setbkcolor(1);
setcolor(3);
rectangle(0+5*i,0+5*i,getmaxx()-5*i,getmaxy()-5*i);
i++;
}
i=0;
setcolor(4);
settextstyle(1,0,6);
sleep(5);
cleardevice();
while(5*i<=700)
{
setbkcolor(1);
setcolor(3);
circle(getmaxx()/2,getmaxy()/2,i*5);
i++;
}
setcolor(4);
settextstyle(0,0,6);
outtextxy(190 ,getmaxy()/2-85,"PROJECT");
outtextxy(300,getmaxy()/2-25,"ON");
outtextxy(190,getmaxy()/2+25,"BANKING");
sleep(3);
i=0;
while(i<=130)
{
setbkcolor(1);
setcolor(3);
line(i*3,0,i*3,getmaxy());
line(getmaxx()-i*3,0,getmaxx()-i*3,getmaxy());
i++;
}
sleep(1);
i=getmaxy();
while(i>0)
{
line(getmaxx()/2,getmaxy(),getmaxx(),i-=10);
delay(10);
}
i=getmaxx();
while(i>0)
{
line(getmaxx()/2,getmaxy(),i-=10,0);
delay(10);
}
i=0;
while(i<getmaxy())
{
line(getmaxx()/2,getmaxy(),0,i+=10);
delay(10);
}
closegraph();
flushall();
}
void deposit(void)
{
account obj_10;
fstream fout;
int mrno=0;
int recsize=sizeof(account);
clrscr();
cout<<"
DEPOSITAL MENU
";
fout.open("banking.txt",ios::in|ios::out|ios::binary);
if(!fout)
{
cout<<"FILE OPEN ERROR ";getch();return;}
fout.seekg(ios::beg);
cout<<"
ENTER ACCOUNT NUMBER ";
cin>>mrno;
while(fout.read((char*)&obj_10,recsize))
{
if(obj_10.giveaccountno()==mrno)
{
clrscr();
cout<<"
ENTER THE AMOUNT TO BE DEPOSITED ::Rs ";
cin>>w;
obj_10.deposital(w);
fout.seekg(-1*recsize,ios::cur);
fout.write((char*)&obj_10,recsize);
}
}
fout.close();
getch();
}
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.
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.
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:
The flushall() function clears all buffers associated with input streams, and writes any buffers associated with output streams. A subsequent read operation on an input file causes new data to be read from the associated file or device. Calling the flushall() function is equivalent to calling the fflush() for all open stream files. The number of open streams. When an output error occurs while writing to a file, the global variable errno is set.
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.
The header file graphics.h contains closegraph() function which closes the graphics mode, deallocates all memory allocated by graphics system and restores the screen to the mode it was in before you called initgraph. closegraph() function is used to re-enter in the text mode and exit from the graphics mode. If you want to use both text mode and graphics mode in the program then you have to use both initgraph() and closegraph() function in the program. This function deallocates all memory allocated by graphics system and restores the screen to that mode in which it was presented before you called the initgraph() function.
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).
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 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.
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.
C programming language provides sleep() function in order to wait for a current thread for a specified time. slepp() function will sleep given thread specified time for the current executable. Of course, the CPU and other processes will run without a problem. The sleep() function shall cause the calling thread to be suspended from execution until either the number of realtime seconds specified by the argument seconds has elapsed or a signal is delivered to the calling thread and its action is to invoke a signal-catching function or to terminate the process. The suspension time may be longer than requested due to the scheduling of other activity by the system. The sleep() function shall cause the calling thread to be suspended from execution until either the number of realtime seconds specified by the argument seconds has elapsed or a signal is delivered to the calling thread and its action is to invoke a signal-catching function or to terminate the process. The suspension time may be longer than requested
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.
Rename file. Changes the name of the file or directory specified by oldname to newname. This is an operation performed directly on a file; No streams are involved in the operation. If oldname and newname specify different paths and this is supported by the system, the file is moved to the new location. If newname names an existing file, the function may either fail or override the existing file, depending on the specific system and library implementation. Proper file access shall be available.
#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.
rectangle() is used to draw a rectangle. Coordinates of left top and right bottom corner are required to draw the rectangle. 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.
This library function is declared in graphics.h and used to draw a circle; it takes centre point coordinates and radius. Circle function is used to draw a circle with center (x,y) and third parameter specifies the radius of the circle. The code given below draws a circle. Where, (x, y) is center of the circle. 'radius' is the Radius of the circle.
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.
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.
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.
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.
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.
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 remove() function in C++ deletes a specified file. Deletes the file whose name is specified in filename. The remove() function takes a single argument filename and returns an integer value. It deletes the file pointed by the parameter. This is an operation performed directly on a file identified by its filename; No streams are involved in the operation. Proper file access shall be available. Incase the file to be deleted is opened by a process, the behaviour of remove() function is implementation-defined. It is defined in <cstdio> header file.
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.
Function textbackground is used to change current background color in text mode. To use the textbackground() function all you need to do is before printing any text call this function with a parameter defining the color in capital letters. That will be enough to change the background color of the text.
Get string from stdin. Reads characters from the standard input (stdin) and stores them as a C string into str until a newline character or the end-of-file is reached. The newline character, if found, is not copied into str. A terminating null character is automatically appended after the characters copied to str. Notice that gets is quite different from fgets: not only gets uses stdin as source, but it does not include the ending newline character in the resulting string and does not allow to specify a maximum size for str (which can lead to buffer overflows). On success, the function returns str.
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.
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
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.
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)
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.
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.
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.
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.
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.
setbkcolor() function is used to set the background color in graphics mode. The default background color is black and default drawing color as we know is white. setbkcolor() function takes only one argument it would be either the name of color defined in graphics.h header file or number associated with those colors. If we write setbkcolor(yellow) it changes the background color in Green. The possible color values are from 0 - 15 black, blue, green, cyan, red, magenta, brown, lightgray, darkgray, lightblue, lightgreen, lightcyan, lightred, lightmagenta, yellow, white and blink (128).
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.
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.
A function is block of code which is used to perform a particular task, for example let's say you are writing a "Larger C++ Program", in that program you want to do a particular