project report on second final main online library management system with 60 pages

of 81 /81
Table of Contents S.N o Name Pages Remarks 1. Introduction 4-5 2. Feasibility Study 6-7 3. Drawbacks Of Present System 8 4. Proposed System 8 5. DFDs 9-9 6. E-R Diagrams 9-10 7. Programming concepts used in project 8. Data Types 11-17 9. Loops 18-22 10.Functions 23-29 11.String Handling 30-36 12.Opps Concepts 37-43 13.Graphics in C 59-68 14.C File I/O and Binary File I/O 69-71 15.Future Scope 72-73 16.Conclusion 74-74 1

Upload: rajiv-kumar-garg

Post on 18-Apr-2015




5 download

Embed Size (px)


Page 1: Project Report on Second Final Main Online Library Management System With 60 Pages

Table of Contents

S.No Name Pages Remarks

1. Introduction 4-5

2. Feasibility Study 6-7

3. Drawbacks Of Present System 8

4. Proposed System 8

5. DFDs 9-9

6. E-R Diagrams 9-10

7. Programming concepts used in project

8. Data Types 11-17

9. Loops 18-22

10. Functions 23-29

11. String Handling 30-36

12. Opps Concepts 37-43

13. Graphics in C 59-68

14. C File I/O and Binary File I/O 69-71

15. Future Scope 72-73

16. Conclusion 74-74

17. Bibilography 75


Page 2: Project Report on Second Final Main Online Library Management System With 60 Pages






“Library ManagementSystem”

Submitted To: Submitted By:


Page 3: Project Report on Second Final Main Online Library Management System With 60 Pages


The satisfaction that accompanies that the successful completion of any task would be incomplete without the mention of people whose ceaseless cooperation made it possible, whose constant guidance and encouragement crown all efforts with success.

I am grateful to my project guide Er. Rajiv Kumar for the guidance,inspiration and constructive suggestions that

helped me lot in the preparation of this project.

I also thank our colleagues who have helped in successful completion of the project.



Page 4: Project Report on Second Final Main Online Library Management System With 60 Pages

Lib r a r y Manag e men t S ys te m

1. I n t r odu c t i on :-

1.1 P u r po se :-

The purposes of this application are as follows:

• The software is for automation of library.• It provides following facilities to

O pe r ator :

• Can enter details related to a particular book.• Can provide membership to members.

A d mi n :

• Can read and write information about any member.• Can update, create, and delete the record of

membership as per requirement and implementation plants.


Page 5: Project Report on Second Final Main Online Library Management System With 60 Pages

1.) S c ope :

The different areas where we can use this application


Page 6: Project Report on Second Final Main Online Library Management System With 60 Pages


• Any education institute can make use of it for providing information about author, content of the available books.

• It can be used in offices and modifications can be easily done according to requirements.

2.) Te c hno l o g y U s e d:

* C Language * C++ * Concept of Files

4.) A ss u m pt i ons

• This application is used to convert the manual application to the online application.• Customized data will be used in this application.• User does not have right to enter information about books.

5.) O v er v i e w :

Project is related to library management which provides reading services to its members. Any person can become a member of the library by filling a prescribed form.

They can get the book issued, so that they cab take home and return them.

6.) Fun c t i ona li t y :

• Keeps the track of issues and submission of books.


Page 7: Project Report on Second Final Main Online Library Management System With 60 Pages

Feas i b ilit y S t u d y

In feasibility study phase we had undergone through various steps which are describe as under:

1. Identify the origin of the information at different level.2. Identify the expectation of user from computerized

system.3. Analyze the draw back of existing system (manual)



The staffs of library are involved in the following tasks.

1. M e m ber s h i p pr o c e s s : person have to fill membership form and they are provided with member id.

2. Manually book finding : the student have to find the books manually by searching in whole library

Page 8: Project Report on Second Final Main Online Library Management System With 60 Pages


Some of the problems being faced in manual system are as follows:

1. Fast report generation is not possible.2. Tracing a book is difficult.3. Information about issue/return of the books is not

properly maintained.4. No central database can be created as information is not

available in database.


There will be three major components:

1. Stock maintenance.2. Transaction entry.3. Reports.

Proposed system provides with following solutions:

1. It provides "better and efficient" service to members.2. Reduce the workload of employee.3. Faster retrieval of information about the desired book.4. Provide facility for proper monitoring reduces paper work and

provide data security.5. All details will be available on a click.

Page 9: Project Report on Second Final Main Online Library Management System With 60 Pages

D at a Fl o w D i ag ra m (D FD )







Penalty Report



Book IssueBooks



Book Issue


Page 10: Project Report on Second Final Main Online Library Management System With 60 Pages


It is clear that the physical objects from the previous section– the member, books, library – correspond to entities in the Entity-Relationship model, and the operations to be done on those entities – holds, checkouts, and so on – correspond to relationships. However, a good design will minimize redundancy and attempt to store all the required informationin as small a space as possible.

Page 11: Project Report on Second Final Main Online Library Management System With 60 Pages
Page 12: Project Report on Second Final Main Online Library Management System With 60 Pages

Programming concepts used in project

C Programming Language - Data Types

A C language programmer has to tell the system before-hand, the type of numbers or characters he is using in his program. These are data types. There are many data types in C language. A C programmer has to use appropriate data type as per his requirement.

C language data types can be broadly classified as Primary data type Derived data type User-defined data type

Primary data type

All C Compilers accept the following fundamental data types

The size and range of each data type is given in the table below


char -128 to 127

Int -32768 to +32767

float 3.4 e-38 to 3.4 e+38

double 1.7 e-308 to 1.7 e+308

Page 13: Project Report on Second Final Main Online Library Management System With 60 Pages

Integer Type :

Integers are whole numbers with a machine dependent range of values. A good programming language as to support the programmer by giving a control on a range of numbers and storage space. C has 3 classes of integer storage namely short int, int and long int. All of these data types have signed and unsigned forms. A short int requires half the space than normal integer values. Unsigned numbers are always positive and consume all the bits for the magnitude of the number. The long and unsigned integers are used to declare a longer range of values.

Floating Point Types :

Floating point number represents a real number with 6 digits precision. Floating point numbers are denoted by the keyword float. When the accuracy of the floating point number is insufficient, we can use the double to define the number. The double is same as float but with longer precision. To extend the precision further we can use long double which consumes 80 bits of memory space.

Void Type :

Using void data type, we can specify the type of a function. It is a good practice to avoid functions that does not return any values to the calling function.

Character Type:

A single character can be defined as a defined as a character type of data. Characters are usually stored in 8 bits of internal storage. The qualifier signed or unsigned can be explicitly applied to char. While unsigned characters have values between 0 and 255, signed characters have values from –128 to 127.

Size and Range of Data Types on 16 bit machine.

TYPE SIZE (Bits) Range

Char or Signed Char 8 -128 to 127

Unsigned Char 8 0 to 255

Int or Signed int 16 -32768 to 32767

Unsigned int 16 0 to 65535

Page 14: Project Report on Second Final Main Online Library Management System With 60 Pages

Short int or Signed short int 8 -128 to 127

Unsigned short int 8 0 to 255

Long int or signed long int 32 -2147483648 to 2147483647

Unsigned long int 32 0 to 4294967295

Float 32 3.4 e-38 to 3.4 e+38

Double 64 1.7e-308 to 1.7e+308

Long Double 80 3.4 e-4932 to 3.4 e+4932

Declaration of Variables

Every variable used in the program should be declared to the compiler. The declaration does two things.

1. Tells the compiler the variables name. 2. Specifies what type of data the variable will hold.

The general format of any declaration

datatype v1, v2, v3, ……….. vn;

Where v1, v2, v3 are variable names. Variables are separated by commas. A declaration statement must end with a semicolon.


Int sum; Int number, salary; Double average, mean;

Page 15: Project Report on Second Final Main Online Library Management System With 60 Pages

Datatype Keyword Equivalent

Character char

Unsigned Character unsigned char

Signed Character signed char

Signed Integer signed int (or) int

Signed Short Integer signed short int (or) short int (or) short

Signed Long Integer signed long int (or) long int (or) long

UnSigned Integer unsigned int (or) unsigned

UnSigned Short Integer unsigned short int (or) unsigned short

UnSigned Long Integer unsigned long int (or) unsigned long

Floating Point float

Double Precision Floating Point double

Extended Double Precision Floating Point long double

Page 16: Project Report on Second Final Main Online Library Management System With 60 Pages

User defined type declaration

In C language a user can define an identifier that represents an existing data type. The user defined datatype identifier can later be used to declare variables. The general syntax is

typedef type identifier;

here type represents existing data type and ‘identifier’ refers to the ‘row’ name given to the data type.


typedef int salary; typedef float average;

Here salary symbolizes int and average symbolizes float. They can be later used to declare variables as follows:

Units dept1, dept2; Average section1, section2;

Therefore dept1 and dept2 are indirectly declared as integer datatype and section1 and section2 are indirectly float data type.

The second type of user defined datatype is enumerated data type which is defined as follows.

Enum identifier {value1, value2 …. Value n};

The identifier is a user defined enumerated datatype which can be used to declare variables that have one of the values enclosed within the braces. After the definition we can declare variables to be of this ‘new’ type as below.

enum identifier V1, V2, V3, ……… Vn

The enumerated variables V1, V2, ….. Vn can have only one of the values value1, value2 ….. value n


enum day {Monday, Tuesday, …. Sunday}; enum day week_st, week end; week_st = Monday; week_end = Friday; if(wk_st == Tuesday) week_en = Saturday;

Page 17: Project Report on Second Final Main Online Library Management System With 60 Pages

Declaration of Storage Class

Variables in C have not only the data type but also storage class that provides information about their location and visibility. The storage class divides the portion of the program within which the variables are recognized.

auto : It is a local variable known only to the function in which it is declared. Auto is the default storage class.

static : Local variable which exists and retains its value even after the control is transferred to the calling function.

extern : Global variable known to all functions in the file

register : Social variables which are stored in the register.

Defining Symbolic Constants

A symbolic constant value can be defined as a preprocessor statement and used in the program as any other constant value. The general form of a symbolic constant is

# define symbolic_name value of constant

Valid examples of constant definitions are :

# define marks 100 # define total 50 # define pi 3.14159

These values may appear anywhere in the program, but must come before it is referenced in the program.

It is a standard practice to place them at the beginning of the program.

Declaring Variable as Constant

The values of some variable may be required to remain constant through-out the program. We can do this by using the qualifier const at the time of initialization.


Const int class_size = 40;

The const data type qualifier tells the compiler that the value of the int variable class_size may not be modified in the program.

Page 18: Project Report on Second Final Main Online Library Management System With 60 Pages

Volatile Variable

A volatile variable is the one whose values may be changed at any time by some external sources.

Example: volatile int num; The value of data may be altered by some external factor, even if it does not appear on the left hand side of the assignment statement. When we declare a variable as volatile the compiler will examine the value of the variable each time it is encountered to see if an external factor has changed the value.

Page 19: Project Report on Second Final Main Online Library Management System With 60 Pages

C Programming - Decision Making - Looping

In this tutorial you will learn about C Programming - Decision Making - Looping, The While Statement, The Do while statement, The Break Statement, Continue statement and For Loop.

During looping a set of statements are executed until some conditions for termination of the loop is encountered. A program loop therefore consists of two segments one known as body of the loop and other is the control statement. The control statement tests certain conditions and then directs the repeated execution of the statements contained in the body of the loop.

In looping process in general would include the following four steps 1. Setting and initialization of a counter 2. Exertion of the statements in the loop 3. Test for a specified conditions for the execution of the loop 4. Incrementing the counter

The test may be either to determine whether the loop has repeated the specified number of times or to determine whether the particular condition has been met.

The While Statement:

The simplest of all looping structure in C is the while statement. The general format of the while statement is:

while (test condition) { body of the loop }

Here the given test condition is evaluated and if the condition is true then the body of the loop is executed. After the execution of the body, the test condition is once again evaluated and if it is true, the body is executed once again. This process of repeated execution of the body continues until the test condition finally becomes false and the control is transferred out of the loop. On exit, the program continues with the statements immediately after the body of the loop. The body of the loop may have one or more statements. The braces are needed only if the body contained two are more statements

Example program for generating ‘N’ Natural numbers using while loop:

# include < stdio.h > //include the stdio.h file void main() // Start of your program { int n, i=0; //Declare and initialize the variables printf(“Enter the upper limit number”); //Message to the user scanf(“%d”, &n); //read and store the number while(I < = n) // While statement with condition { // Body of the loop printf(“\t%d”,I); // print the value of i

Page 20: Project Report on Second Final Main Online Library Management System With 60 Pages

I++; increment I to the next natural number. } }

In the above program the looping concept is used to generate n natural numbers. Here n and I are declared as integer variables and I is initialized to value zero. A message is given to the user to enter the natural number till where he wants to generate the numbers. The entered number is read and stored by the scanf statement. The while loop then checks whether the value of I is less than n i.e., the user entered number if it is true then the control enters the loop body and prints the value of I using the printf statement and increments the value of I to the next natural number this process repeats till the value of I becomes equal to or greater than the number given by the user.

The Do while statement:

The do while loop is also a kind of loop, which is similar to the while loop in contrast to while loop, the do while loop tests at the bottom of the loop after executing the body of the loop. Since the body of the loop is executed first and then the loop condition is checked we can be assured that the body of the loop is executed at least once.

The syntax of the do while loop is:

Do { statement; } while(expression);

Here the statement is executed, then expression is evaluated. If the condition expression is true then the body is executed again and this process continues till the conditional expression becomes false. When the expression becomes false. When the expression becomes false the loop terminates.

To realize the usefulness of the do while construct consider the following problem. The user must be prompted to press Y or N. In reality the user can press any key other than y or n. IN such case the message must be shown again and the user should be allowed to enter one of the two keys, clearly this is a loop construct. Also it has to be executed at least once. The following program illustrates the solution.

/* Program to illustrate the do while loop*/ #include < stdio.h > //include stdio.h file to your program void main() // start of your program { char inchar; // declaration of the character do // start of the do loop { printf(“Input Y or N”); //message for the user scanf(“%c”, &inchar); // read and store the character } while(inchar!=’y’ && inchar != ‘n’); //while loop ends

Page 21: Project Report on Second Final Main Online Library Management System With 60 Pages

if(inchar==’y’) // checks whther entered character is y printf(“you pressed u\n”); // message for the user else printf(“You pressed n\n”); } //end of for loop

The Break Statement:

Sometimes while executing a loop it becomes desirable to skip a part of the loop or quit the loop as soon as certain condition occurs, for example consider searching a particular number in a set of 100 numbers as soon as the search number is found it is desirable to terminate the loop. C language permits a jump from one statement to another within a loop as well as to jump out of the loop. The break statement allows us to accomplish this task. A break statement provides an early exit from for, while, do and switch constructs. A break causes the innermost enclosing loop or switch to be exited immediately.

Example program to illustrate the use of break statement.

/* A program to find the average of the marks*/ #include < stdio.h > //include the stdio.h file to your program void main() // Start of the program { int I, num=0; //declare the variables and initialize float sum=0,average; //declare the variables and initialize printf(“Input the marks, -1 to end\n”); // Message to the user while(1) // While loop starts { scanf(“%d”,&I); // read and store the input number if(I==-1) // check whether input number is -1 break; //if number –1 is input skip the loop sum+=I; //else add the value of I to sum num++ // increment num value by 1 }} end of the program

Continue statement:

During loop operations it may be necessary to skip a part of the body of the loop under certain conditions. Like the break statement C supports similar statement called continue statement. The continue statement causes the loop to be continued with the next iteration after skipping any statement in between. The continue with the next iteration the format of the continue statement is simply:


Consider the following program that finds the sum of five positive integers. If a negative number is entered, the sum is not performed since the remaining part of the loop is skipped using continue statement.

Page 22: Project Report on Second Final Main Online Library Management System With 60 Pages

#include < stdio.h > //Include stdio.h file void main() //start of the program { int I=1, num, sum=0; // declare and initialize the variables for (I = 0; I < 5; I++) // for loop { printf(“Enter the integer”); //Message to the user scanf(“%I”, &num); //read and store the number if(num < 0) //check whether the number is less than zero { printf(“You have entered a negative number”); // message to the user continue; // starts with the beginning of the loop } // end of for loop sum+=num; // add and store sum to num } printf(“The sum of positive numbers entered = %d”,sum); // print thte sum. } // end of the program.

For Loop:

The for loop provides a more concise loop control structure. The general form of the for loop is:

for (initialization; test condition; increment) { body of the loop }

When the control enters for loop the variables used in for loop is initialized with the starting value such as I=0,count=0. The value which was initialized is then checked with the given test condition. The test condition is a relational expression, such as I < 5 that checks whether the given condition is satisfied or not if the given condition is satisfied the control enters the body of the loop or else it will exit the loop. The body of the loop is entered only if the test condition is satisfied and after the completion of the execution of the loop the control is transferred back to the increment part of the loop. The control variable is incremented using an assignment statement such as I=I+1 or simply I++ and the new value of the control variable is again tested to check whether it satisfies the loop condition. If the value of the control variable satisfies then the body of the loop is again executed. The process goes on till the control variable fails to satisfy the condition.

Additional features of the for loop:

We can include multiple expressions in any of the fields of for loop provided that we separate such expressions by commas. For example in the for statement that begins

For( I = 0; j = 0; I < 10, j=j-10)

Sets up two index variables I and j the former initialized to zero and the latter to 100 before the loop begins. Each time after the body of the loop is executed, the value of I will be incremented by 1 while the value of j is decremented by 10.

Page 23: Project Report on Second Final Main Online Library Management System With 60 Pages

Just as the need may arise to include more than one expression in a particular field of the for statement, so too may the need arise to omit on or more fields from the for statement. This can be done simply by omitting the desired filed, but by marking its place with a semicolon. The init_expression field can simply be “left blank” in such a case as long as the semicolon is still included:


The above statement might be used if j were already set to some initial value before the loop was entered. A for loop that has its looping condition field omitted effectively sets up an infinite loop, that is a loop that theoretically will be executed for ever.

For loop example program:

/* The following is an example that finds the sum of the first fifteen positive natural numbers*/ #include < stdio.h > //Include stdio.h file void main() //start main program { int I; //declare variable int sum=0,sum_of_squares=0; //declare and initialize variable. for(I=0;I < = 30; I+=2) //for loop { sum+=I; //add the value of I and store it to sum sum_of_squares+=I*I; //find the square value and add it to sum_of_squares } //end of for loop printf(“Sum of first 15 positive even numbers=%d\n”,sum); //Print sum printf(“Sum of their squares=%d\n”,sum_of_squares); //print sum_of_square }

Page 24: Project Report on Second Final Main Online Library Management System With 60 Pages

C Programming - Functions

In this tutorial you will learn about C Programming - Functions (Part II) Nesting of functions, Recursion, Functions and arrays, The scope and lifetime of variables in functions, Automatic variables, External variables, Multi-file programs, Static variables and Register variables.

Nesting of functions:

C permits nesting of two functions freely. There is no limit how deeply functions can be nested. Suppose a function a can call function b and function b can call function c and so on. Consider the following program:

main() { int a,b,c; float ratio(); scanf(“%d%d%d”,&a,&b,&c); printf(“%f\n”,ratio(a,b,c)); } float ratio(x,y,z) int x,y,z; { if(difference(y,z)) return(x/y-z)); else return(0,0); } difference(p,q) { int p,q; { if(p!=q) return(1); else return(0); }

the above program calculates the ratio a/b-c; and prints the result. We have the following three functions:

main() ratio() difference()

main reads the value of a,b,c and calls the function ratio to calculate the value a/b-c) this ratio cannot be evaluated if(b-c) is zero. Therefore ratio calls another function difference to test whether the difference(b-c) is zero or not.

Page 25: Project Report on Second Final Main Online Library Management System With 60 Pages


Recursive function is a function that calls itself. When a function calls another function and that second function calls the third function then this kind of a function is called nesting of functions. But a recursive function is the function that calls itself repeatedly.

A simple example:

main() { printf(“this is an example of recursive function”); main(); }

when this program is executed. The line is printed reapeatedly and indefinitely. We might have to abruptly terminate the execution.

Functions and arrays:

We can pass an entire array of values into a function just as we pass indiviual variables. In this task it is essential to list the name of the array along with functions arguments without any subscripts and the size of the array as arguments

For example: The call


Will pass all the elements contained in the array a of size n. the called function expecting this call must be appropriately defined. The largest function header might look like:

float smallest(array,size); float array[]; int size;

The function smallest is defined to take two arguments, the name of the array and the size of the array to specify the number of elements in the array. The declaration of the formal argument array is made as follows:

float array[];

The above declaration indicates to compiler that the arguments array is an array of numbers. It is not necessary to declare size of the array here. While dealing with array arguments we should remember one major distinction. If a function changes the value the value of an array elements then these changes will be made to the original array that passed to the function. When the entire array is passed as an argument, the contents of the array are not copied into the formal parameter array instead information about the address of the array elements are passed on to the function. Therefore any changes introduced to array elements are truly reflected in the original array in the calling function.

Page 26: Project Report on Second Final Main Online Library Management System With 60 Pages

The scope and lifetime of variables in functions:

The scope and lifetime of the variables define in C is not same when compared to other languages. The scope and lifetime depends on the storage class of the variable in c language the variables can be any one of the four storage classes:

1. Automatic Variables 2. External variable 3. Static variable 4. Register variable.

The scope actually determines over which part or parts of the program the variable is available. The lifetime of the variable retains a given value. During the execution of the program. Variables can also be categorized as local or global. Local variables are the variables that are declared within that function and are accessible to all the functions in a program and they can be declared within a function or outside the function also.

Automatic variables:

Automatic variables are declared inside a particular function and they are created when the function is called and destroyed when the function exits. Automatic variables are local or private to a function in which they are defined by default all variable declared without any storage specification is automatic. The values of variable remains unchanged to the changes that may happen in other functions in the same program and by doing this no error occurs.

/* A program to illustrate the working of auto variables*/ #include void main() { int m=1000; function2(); printf(“%d\n”,m); }

function1() { int m=10; printf(“%d\n”,m); } function2() { int m=100; function1(); printf(“%d\n”,m); }

A local variable lives through out the whole program although it accessible only in the main. A program with two subprograms function1 and function2 with m as automatic variable and is initialized to 10,100,1000 in function 1 function2 and function3 respectively. When executes main calls function2 which in turns calls function1. When main is active m=1000. But when function2 is called, the main m is temporarily put on the shelf and the

Page 27: Project Report on Second Final Main Online Library Management System With 60 Pages

new local m=100 becomes active. Similarly when function1 is called both previous values of m are put on shelf and latest value (m=10) become active, a soon as it is done main (m=1000) takes over. The output clearly shows that value assigned to m in one function does not affect its value in the other function. The local value of m is destroyed when it leaves a function.

External variables:

Variables which are common to all functions and accessible by all functions of aprogram are internal variables. External variables can be declared outside a function.


int sum; float percentage; main() { ….. ….. } function2() { …. …. } The variables sum and percentage are available for use in all the three functions main, function1, function2.  Local variables take precedence over global variables of the same name.

For example:

int i = 10; void example(data) int data; { int i = data; }

main() { example(45); }

In the above example both the global variable and local variable have the same name as i. The local variable i take precedence over the global variable. Also the value that is stored in integer i is lost as soon as the function exits.

A global value can be used in any function all the functions in a program can access the global variable and change its value the subsequent functions get the new value of the global variable, it will be inconvenient to use a variable as global because of this factor

Page 28: Project Report on Second Final Main Online Library Management System With 60 Pages

every function can change the value of the variable on its own and it will be difficult to get back the original value of the variable if it is required.

Global variables are usually declared in the beginning of the main program ie., before the main program however c provides a facility to declare any variable as global this is possible by using the keyword storage class extern. Although a variable has been defined after many functions the external declaration of y inside the function informs the compiler that the variable y is integer type defined somewhere else in the program. The external declaration does not allocate storage space for the variables. In case of arrays the definition should include their size as well. When a variable is defined inside a function as extern it provides type information only for that function. If it has to be used in other functions then again it has to be re-declared in that function also.


main() { int n; out_put(); extern float salary[]; …… ….. out_put(); }

void out_put() { extern float salary[]; int n; …. ….. } float salary[size];

a function when its parameters and function body are specified this tells the compiler to allocate space for the function code and provides type info for the parameters. Since functions are external by default we declare them (in calling functions) without the qualifier extern.

Multi-file programs:

Programs need not essentially be limited into a single file, multi-file programs is also possible, all the files are linked later to form executable object code. This approach is very useful since any change in one file does not affect other files thus eliminating the need for recompilation of the entire program. To share a single variable in multiple programs it should be declared, as external variables that are shared by two or more files are obviously global variables and therefore we must declare them accordingly in one file and explicitly define them with extern in other file. The example shown below illustrates the use of extern declarations in multi-file programs


Page 29: Project Report on Second Final Main Online Library Management System With 60 Pages

main() { extern int j; int k; }

function1() { int z; … …. } file2.c

function2() { int k; } function3() { int num; … …. }

the function in main file1 reference the variable j that is declared as global in file 2. Here function1() cannot access j if the statement extern int k is places before main then both the functions could refer to j. this can also be achieved by using extern int j statement inside each function in file1.

The extern specifier tells the compiler that the following variables types and names have already been declared elsewhere and no need to create storage space for them. It is the responsibility of the linker to resolve the reference problem. It is important to note that a multi-file global variable should be declared without extern in one of the files.

Static variables:

The value given to a variable declared by using keyword static persistes until the end of the program. A static variable is initialized only once, when the program is compiled. It is never initialized again. During the first call to stat in the example shown below x is incremented to 1. because x is static, this value persists and therefore the next call adds another 1 to x giving it a value of 2. The value of x becomes 3 when third call is made. If we had declared x as an auto then output would here been x=1 all the three times.

main() { int j; for(j=1;j&lt;3;j++) stat(); }

Page 30: Project Report on Second Final Main Online Library Management System With 60 Pages

stat(); { static int x=0; x=x+1;

printf(“x=%d\n”,x); }

Register variables:

A variable is usually stored in the memory but it is also possible to store a varible in the compilers register by defining it as register variable. The registers access is much faster than a memory access, keeping the frequently accessed variables in the register will make the execution of the program faster.

This is done as follows:

register int count;

Since only a few variables can be placed in a register, it is important to carefully select the variables for this purpose. However c will automatically convert regisdter variables into normal variables once the limit is exceeded.

Page 31: Project Report on Second Final Main Online Library Management System With 60 Pages

String Handling in CThere is no such thing as a string type in c. Other languages - C++, Delphi, C#, Java etc, all support a string type but C doesn't. In C, if you want to process text, you have to treat it as an array of char with a terminating \0. To define say a buffer big enough for 80 chars, this definition works.

char buffer[81];

Write this rule down and memorize it. Don't forget the terminating 0 (DFTTZ). That's why the 80 char buffer is 81 chars in size. You can't assign a text string directly, so

buffer = "a test string";

does not work, but a char pointer string initialization is allowed.

char * myName = "David";

We'll see later how to assign a string at runtime using a built in function called strcpy(). Don't be tempted to add [] to the definition - this will create an array of pointers to a char, not a pointer to a char array! The code below allocates 3 strings and then prints them to the console.

char * name[3]={"alpha","beta","gamma"};printf("%s %s %s",name[0],name[1],name[2]) ;

This printouts out

alpha beta gamma

One of the big problems with text processing in C is that you have to code every last detail and it's easy to make mistakes. Also, because you are generally working with pointers, it doesn't take too much effort to get a buffer overflow. Many vulnerabilities and exploits in operating system software have been due to buffer overflow exploits.

Unicode and C

C was written at a time when foreign characters were not much of a consideration. There were a couple of main character encodings in use- ASCII and EBCDIC. It wasn't until the 90s that Unicode started appearing and standard C does not work easily with Unicode. If you go on down that route, forget one char = one byte. It's two bytes or in some cases four bytes per character. This tutorial is not going to dwell on Unicode or use it; that's for a future tutorial but I wanted you to be aware of it. One good resource for anyone using Unicode in Visual C++ is Tex Texin's Unicode enabling Microsoft C/C++ Source Code.

Text Processing is by the Char

Page 32: Project Report on Second Final Main Online Library Management System With 60 Pages

There is a <string.h> library that provides a set of string functions and well come to those shortly. If you choose not to use them, then you have to process text strings char by char. For some small applications that can be fun and very fast.

If you grew up with Basic, you might be familiar with Left(), Right() and Mid() functions as described below.I've used a simple typedef string as an alias for char * to improve readability.

Left(string Source,int NewLen) returns a string that is NewLen characters long, starting at the left

Right(string Source,int NewLen) returns a string that is NewLen characters long, starting at the right

Mid(string Source,int Start,int Length) returns a string that starts at Start and is Length characters long. Start is 0 based.

Writing your own Text Handling Functions

If you write your own functions, be sure to include error checking as I have done. All parameters should be sanity checked. A negative or zero length string doesn't make sense so the length is guaranteed to be 1. If the Source string is null then it returns a single space. The strings c and d check this.

Mid() is a little complicated and very hard to understand if you miss that there is a semi-colon at the end of first while! This is the complete loop. It moves Source forward character by character until it reaches the end of the string or Start becomes 0.

while (*Source++ && --Start) ;

When this starts, Source points to the A in "A Long string". When it exits, Source points to the L at position 2. The *Source is included so that it doesn't index past the end of a shorter string. Don't forget as well that in an &&, if the left hand is false, the right hand is not executed.

Right() actually measures the length of the string in the variable Length. This is a by product of incrementing Source until it points to the terminating zero. It's then used when decrementing Source to make sure that Source doesn't end up pointing to an address before the start of the string. The example for g tests this. It correctly prints out Short.

Lessons Learnt

Sanity check all parameters.

Test with extreme and idiotic cases!

Do not allow any pointers to move before the start of a string or after the terminating zero.

Page 33: Project Report on Second Final Main Online Library Management System With 60 Pages

Of course as there is a <string.h> library provided, it makes sense not to reinvent this wheel.

Using the Mem Functions in the string.h Library

The designers of C went down a different route to that of Basic so there are no Left(), Mid() and Right() functions, apart from those I created in example 1. Instead you get lower level operations for copying and comparing strings. As you may be outputting data, I also include sprintf from <stdio.h>. This is the same as printf with an extra first parameter that is a char *.

There are two types of functions in string.h. The str... functions such as strcat() and the mem... functions like memset(). Generally the Mem... functions are for a fixed size and have an extra parameter specifying it while the str... require the terminating '\0'. The mem... functions are not for string handling but for working with structs etc. I list them here for completeness.

void * memset(void *s,int c, size_t n) - sets n bytes of *s to the value c and returns s.

void memcpy(void *to, const void* from,size_t n) - copies a block of n bytes from *from to *to. Must not overlap.

void memmove(void *to, const void* from, size_t n) - copies a block of n bytes from *from to *to. Can overlap.

int memcmp(const void *s1, const void* s2, size_t n) - compares n bytes from *s1 with *s2. 0 if identical.

void * memchr(const void *s, int c, size_t n) - Searches n bytes of *s for the value c and returns a void * pointer to it if found, null if not found.

The Char Functions in ctype.h

Using ctype.h

The ctype.h library has functions for classifying characters. Each of the functions below returns an int when passed in a char.

isalnum() Check if character is alphanumeric (isalpha) | isdigit()

isalpha() - Check if character is alphabetic

iscntrl() - Check if character is a control character

isdigit() - Check if character is decimal digit

isgraph() - Check if character has graphical representation

islower() - Check if character is lowercase letter

Page 34: Project Report on Second Final Main Online Library Management System With 60 Pages

isprint() - Check if character is printable

ispunct() - Check if character is a punctuation character

isspace() - Check if character is a white-space

isupper() - Check if character is uppercase letter

isxdigit() - Check if character is hexadecimal digit

These values returned from theese functions aren't just 0 or 1 type. 0 is returned for false but isalpha() for example returns 1 if the char is upper case and 2 if its lower case. Some of the values returned depend upon your locale so you'll get different results in different countries.

There are a couple of ancillary functions for converting upper case letter to lower case etc.

tolower() - Converts upper case letter to lower case

toupper() - Converts lower case letter to upper case

If you are doing any kind of input validation then the functions in ctype.h will simplify things for you.

Using the str Functions

There are quite a number of these but you'll probably only need these that are listed below

strcat() - concatenate two strings.

strcpy() - copy a string (handy for doing string assignments).

strcmp() - compare two strings.

strlen() - return the length of a string- this does not include the terminating zero.

strchr() - find a character in a string searching from left.

You also get strn.. versions of the first three (not strlen( and strchr) with an extra parameter size_t n




These limit the operation to the first n chars. For instance strncat() appends a maximum of n chars from a string to another string.

Memory Management

Page 35: Project Report on Second Final Main Online Library Management System With 60 Pages

You are responsible for making sure that strings are properly allocated and freed. For instance this

string a="A very Long String";string b=strcat(a," and now even longer!") ;

While it looks ok is a guaranteed disaster. The first line executes fine but the second takes exception. The strcat() function does not allocate any memory. The compiler would perceive this text as being read-only so it's probably located somewhere that cannot be written to. In this case you must allocate enough space to store the combined strings.

Using the str Functions Continued

In example 4, the strlen() function counts the number of chars before the terminating zero so you must allocate enough space for the terminating zero in the combined string, hence the +1. The strcpy() function copies a into c, the strcat() appends b to c. The append starts exactly on the terminating zero of c after a was copied into it.

With strcmp(s1,s2) it returns an int result which is -1, 0 or +1. 0 is a match, i.e the same but -1 means that s1 is less than s2 and 1 means s1 is greater than s2. This comparison is based on the ASCII value of the first char of s1 compared to the first char of s2. If there are non standard letters used (i.e. foreign characters) then you should call strcoll() instead of strcmp().

This is a longer example about 140 lines long. It reads a text file into a string buffer, extracts words from the text adding them to a list of unique words and counts how many times each word was found.

How It Works

Accept the ReadFile() function for now; file handling will be covered in the next C tutorial. This function reads in the file into a string buffer and returns -1 if the file isn't found, or the size of the file in bytes if it is. The buffer was set to a size big enough to hold the test file. Of course it would be better to get the file length from the file and allocate just enough memory to hold that.

The main structure is defined in the struct wordrec.

typedef char * string;

typedef struct wordrec * wordrecptr;struct wordrec {  string word;  int count;  wordrecptr next;};

Page 36: Project Report on Second Final Main Online Library Management System With 60 Pages

This includes the next field, a pointer to another wordrec. The data structure for this application is a single linked list. If you are unfamiliar with linked lists, see the tutorial on advanced pointers which discusses single linked lists.

Tutorial on Advanced Pointers

The process() function takes the input buffer and a pointer to a pointer for the list! Personally I always find more than one *, eg ** confusing to work with. This is why I prefer to use typedefs like string or wordrecptr to minimize the number of *.

Why do I use a pointer to a pointer? Simply because the list starts empty and doesn't exist until the first word is added in the addword() function. To return the value of list from this function I had to make it a pointer! This is quite confusing- conceptually there is no list, just a pointer to the first struct. The value of this pointer is what we want to return to the caller of the function, so we need a pointer to it.

The for loop in process() uses the isalpha() function to extract characters and build up words. Anything non alphabetic ends a word and sets the inword flag to false and calls the addword() function. As soon as an alphabetic char is found it starts a new word. The function addword() does much of the work. It uses strcpy() to compare the word being added with every word in the list until it finds it or hits the end of the list.

This is a somewhat inefficient way of searching the list but it does ok. If it locates the word, it increments the count. The prev pointer variable points one structure behind the head, so that when the list is searched, when head hits the end, prev points to the last element. With the first word added, there is no list so the first structure is created and the list pointed to it.

At the end of this function, head points to the newly created struct which is populated with a copy of the word, a count of 1 and a null pointer marking the new end of the list.

Finally the DumpList() function outputs all words that occur ten or more times. You can see all of the words by commenting the line with an if statement out. This function also frees up all allocated memory, both the words and the structures and returns a count of how many unique words were found.

Using the changelog.txt file from Tortoise, (the Subversion gui) as input produced these results in under a second. It built up a linked list with 2,106 structs calling addword() 38,815 times.

File size =132097 bytesNumber of Words found = 38815Number of unique words = 2106

Other Str Functions

In these definitions, string is a synonym for char *.

strchr() - Find character in string.

Page 37: Project Report on Second Final Main Online Library Management System With 60 Pages

strrchr()- Find character in string, searching from the end.

strcspn() - Find a string in another string.

strxfrm() - Transform string using locale

strpbrk() - Find a string in another string.

strspn() - Find the first element in a string that doesn't match another string.

strstr() - Find a string in another.

strtok() - A persistent search (between calls) of one string in another. Can be called repeatedly.

strxfrm() - Translate a string according to the locale.

Why so many string search functions? Some include '\0' in the searched text, though strstr() doesn't. So far I've never written anything that needed any of these! but the most useful is possibly strtok() if you have to do multiple searches in a string.


C is probably not the best programming language for text processing as it uses pointers and needs careful coding. It is all too easy to introduce bugs if you're not careful!

Basic concepts of OOPS and Structure of C++ program

Some of the important object oriented features are namely:


Page 38: Project Report on Second Final Main Online Library Management System With 60 Pages



Data Abstraction

Data Encapsulation




In order to understand the basic concepts in C++, the programmer must have a command of the basic terminology in object-oriented programming. Below is a brief outline of the concepts of Object-oriented programming languages:


Object is the basic unit of object-oriented programming. Objects are identified by its unique name. An object represents a particular instance of a class. There can be more than one instance of an object. Each instance of an object can hold its own relevant data.

An Object is a collection of data members and associated member functions also known as methods.

Page 39: Project Report on Second Final Main Online Library Management System With 60 Pages


Classes are data types based on which objects are created. Objects with similar properties and methods are grouped together to form a Class. Thus a Class represent a set of individual objects. Characteristics of an object are represented in a class as Properties. The actions that can be performed by objects becomes functions of the class and is referred to as Methods.

For example consider we have a Class of Cars under which Santro Xing, Alto and WaganR represents individual Objects. In this context each Car Object will have its own, Model, Year of Manufacture, Colour, Top Speed, Engine Power etc., which form Properties of the Car class and the associated actions i.e., object functions like Start, Move, Stop form the Methods of Car Class.

No memory is allocated when a class is created. Memory is allocated only when an object is created, i.e., when an instance of a class is created.


Inheritance is the process of forming a new class from an existing class or base class. The base class is also known as parent class or super class, The new class that is formed is called derived class. Derived class is also known as a child class or sub class. Inheritance helps in reducing the overall code size of the program, which is an important concept in object-oriented programming.

C++ is rich in its data types. Inheritance is the concept to inherit the properties of one class to another class. This has also known as class structure again. For example, classes A contains two-member function ads and subtracts and class b contain two another functions multiply and divide.

Inheritance is the concept to inherit the properties of one class to another class. This has also known as class structure again. For example, classes A contains two-member function ads and subtracts and class b contain two another functions multiply and divide. We want to use all these function with one object then we need to use inheritance where class B inherits all the property of class, which is public, but class B cannot use the private properties of class A. There are following types of inheritance:

Page 40: Project Report on Second Final Main Online Library Management System With 60 Pages

1. Single class Inheritance:

When class a gas inherited in class has known as base class and B class is know as derived class. Here only two classes have linked to each other.

2. Multilevel Inheritance:

In this type of inheritance, there are number of level and it has used in that cases where we want to use all properties in number of levels according to the requirement. For example, class A inherited in class b and class b has inherited in class c for class b so on. Where class A is base class c. In another way we can say b is derived class a base class for c and a indirect base class for c is indirect base class for c and c indirect derived class for class A.

3. Multiple Inheritances:

In this type of inheritance, number of classes has inherited in a single class. Where two or more classes are, know as base class and one is derive class.

Page 41: Project Report on Second Final Main Online Library Management System With 60 Pages

4. Hierarchical Inheritance:

This type of inheritance helps us to create a baseless for number of classes and those numbers of classes can have further their branches of number of class.

Page 42: Project Report on Second Final Main Online Library Management System With 60 Pages

5. Hybrid Inheritance:

In this type of inheritance, we can have mixture of number of inheritances but this can generate an error of using same name function from no of classes, which will bother the compiler to how to use the functions. Therefore, it will generate errors in the program. This has known as ambiguity or duplicity.

Data Abstraction:

Data Abstraction increases the power of programming language by creating user defined data types. Data Abstraction also represents the needed information in the program without presenting the details.

Data Encapsulation:

Data Encapsulation combines data and functions into a single unit called Class. When using Data Encapsulation, data is not accessed directly; it is only accessible through the functions present inside the class. Data Encapsulation enables the important concept of data hiding possible.


Polymorphism allows routines to use variables of different types at different times. An operator or function can be given different meanings or functions. Polymorphism refers to a single function or multi-functioning operator performing in different ways.


Overloading is one type of Polymorphism. It allows an object to have different meanings, depending on its context. When an exiting operator or function begins to operate on new data type, or class, it is understood to be overloaded.


This term refers to the ability for multiple programmers to use the same written and debugged existing class of data. This is a time saving device and adds code efficiency to the language. Additionally, the programmer can incorporate new features to the existing class, further developing the application and allowing users to achieve increased performance. This time saving feature optimizes code, helps in gaining secured applications and facilitates easier maintenance on the application.

The implementation of each of the above object-oriented programming features for C++ will be highlighted in later sections. 

Page 43: Project Report on Second Final Main Online Library Management System With 60 Pages

A sample program to understand the basic structure of C++

//program to read employee details and to output the data #include <iostream.h>                      → Preprocessor directiveclass employee                             → Class Declaration     {   private:     char empname[50];     int empno;

   public:     void getvalue()     {        cout<<”INPUT EMP NAME:”;        cint>>empname;        cout<<”INPUT EMP NO:”;        cint>>empno;     }

     void displayvalue()     {        cout<<”EMP NAME:”<<empname;        coout<<EMP NO:”<<empno;     }};

main(){     employee e1;                             → Creation of Object     e1.getvalue();     e1.displayvalu();}

Page 44: Project Report on Second Final Main Online Library Management System With 60 Pages

Overview of the Basic Structure of C++ Programming

The // in first line is used for representing comment in the program. .

The second line of the program has a # symbol which represents the preprocessor directive followed by header file to be included placed between < >..

The next structure present in the program is the class definition. This starts with the keyword class followed by class name employee. Within the class are data and functions. The data defined in the class are generally private and functions are public. These explanations we will be detailed in later sections. The class declaration ends with a semicolon. .

main() function is present in all C++ programs. .

An object e1 is created in employee class. Using this e1 the functions present in the employee class are accessed and there by data are accessed. .

The input namely ename and eno is got using the input statement namely cin and the values are outputted using the output statement namely cout.

Page 45: Project Report on Second Final Main Online Library Management System With 60 Pages

Grapics in C Turbo C has a good collection of graphics libraries. If you know the basics of C, you can easily learn graphics programming. To start programming, let us write a small program that displays a circle on the screen.

/*  simple.c    example 1.0*/#include<graphics.h>#include<conio.h>

void main(){    int gd=DETECT, gm;

    initgraph(&gd, &gm, "c:\\turboc3\\bgi " );    circle(200,100,150);

    getch();    closegraph();} 

    To run this program, you need graphics.h header file, graphics.lib library file and Graphics driver (BGI file) in the program folder. These files are part of Turbo C package. In all our programs we used 640x480 VGA monitor. So all the programs are according to that specification. You need to make necessary changes to your programs according to your screen resolution. For VGA monitor, graphics driver used is EGAVGA.BGI.

    Here, initgraph() function initializes the graphics mode and clears the screen. We will study the difference between text mode and graphics mode in detail latter. 


Initializes the graphics system.

Declaration:void far initgraph(int far *graphdriver, int far *graphmode, char far *pathtodriver);

Remarks: To start the graphics system, you must first call initgraph.

initgraph initializes the graphics system by loading a graphics driver from disk (or validating a registered driver) then putting the system into graphics mode.

Page 46: Project Report on Second Final Main Online Library Management System With 60 Pages

initgraph also resets all graphics settings (color, palette, current position, viewport, etc.) to their defaults, then resets graphresult to 0.Arguments:

*graphdriver: Integer that specifies the graphics driver to be used. You can give graphdriver a value using a constant of the graphics drivers enumeration type.

*graphmode : Integer that specifies the initial graphics mode (unless *graphdriver = DETECT). If *graphdriver = DETECT, initgraph sets *graphmode to the highest resolution available for the detected driver. You can give *graphmode a value using a constant of the graphics_modes enumeration type.

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

    closegraph() function switches back the screen from graphcs mode to text mode. It clears the screen also. A graphics program should have a closegraph function at the end of graphics. Otherwise DOS screen will not go to text mode after running the program. Here, closegraph() is called after getch() since screen should not clear until user hits a key.

    If you have the BGI file in the same folder of your program, you can just leave it as "" only. you need not mention *graphmode if you give *graphdriver as DETECT.

    To get details of different graphics modes and graphics drivers, view appendix.

    In graphics mode, all the screen co-ordinates are mentioned in terms of pixels. Number of pixels in the screen decides resolution of the screen. In the example 1.0,  circle is drawn with x-coordinate of the center 200, y-coordinate 100 and radius 150 pixels. All the coordinates are mentioned with respect to top-left corner of the screen.

Basic Shapes and Colors:

    Now let us write a program to draw some basic shapes.

/*shapes.cexample 1.1*/


void main()

Page 47: Project Report on Second Final Main Online Library Management System With 60 Pages

{    int gd=DETECT, gm;    int poly[12]={350,450, 350,410, 430,400, 350,350, 300,430, 350,450 };    initgraph(&gd, &gm, "");          circle(100,100,50);    outtextxy(75,170, "Circle");    rectangle(200,50,350,150);     outtextxy(240, 170, "Rectangle");    ellipse(500, 100,0,360, 100,50);    outtextxy(480, 170, "Ellipse");    line(100,250,540,250);    outtextxy(300,260,"Line");

    sector(150, 400, 30, 300, 100,50);    outtextxy(120, 460, "Sector");    drawpoly(6, poly);    outtextxy(340, 460, "Polygon");    getch();    closegraph();}

Here is the screenshot of output:

Page 48: Project Report on Second Final Main Online Library Management System With 60 Pages

    Here, circle() function takes x, y coordinates of the circle with respect to left top of the screen and radius of the circle in terms of pixels as arguments. Not that, in graphics, almost all the screen parameters are measured in terms of pixels.

    Function outtextxy() displays a string in graphical mode. You can use different fonts, text sizes, alignments, colors and directions of the text that we will study later. Parameters passed are x and y coordinates of the position on the screen where text is to be displayed. There is another function outtext() that displayes a text in the current position. Current position is the place where last drawing is ended. These functions are declared as follows:

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

Circle, arc, pieslice are declared as follows:


 void far arc(int x, int y, int stangle, int endangle, int radius);

 void far circle(int x, int y, int radius);

Page 49: Project Report on Second Final Main Online Library Management System With 60 Pages

 void far pieslice(int x, int y, int stangle, int endangle, int radius);


arc draws a circular arc in the current drawing color.

circle draws a circle in the current drawing color.

pieslice draws a pie slice in the current drawing color, then fills it usingthe current fill pattern and fill color.


(x,y): Center point of arc, circlew, or pie slice

stangle: Start angle in degrees

endangle: End angle in degrees

radius: Radius of arc, circle, and pieslice

    Here, stangle and endangle are in degrees starting from the +ve x-axis in the polar coordinate system in the anti-clockwise direction. if stangle is 0, endangle is 360, it will draw a full circle. Refer this figure for clear idea: For the details of current color, fill color and fill patterns, refer the sections Lines and Colors.

    Another basic shape that we come across is a rectangle. To draw a border, use rectangle with the coordinates of outline, to draw a square use rectangle with same height and width. drawpoly() 

Page 50: Project Report on Second Final Main Online Library Management System With 60 Pages

and   fillpoly()   are   two   functions   useful   to   draw   any   polygons.   To   use   these   functions,   store coordinates of the shape in an array and pass the address of array as an argument to the function. By looking at the output of the previous program, you can understand what drawpoly is. fillpoly is similar except that it fills in the shape with current fill color.


void far rectangle(int left, int top, int right, int bottom);

void far drawpoly(int numpoints, int far *polypoints);

void far fillpoly(int numpoints, int far *polypoints);


rectangle draws a rectangle in the current line style, thickness, and drawing color.

drawpoly draws a polygon using the current line style and color.

fillpoly draws the outline of a polygon using the current line style and color, then fills the polygon using the current fill pattern and fill color.


(left,top) is the upper left corner of the rectangle, and (right,bottom) is its lower right corner.

 numpoints:  Specifies number of points

*polypoints: Points to a sequence of (numpoints x 2) integers. Each pair of integers gives the x and y coordinates of a point on the polygon.

        To draw a closed polygon with N points, numpoints should be N+1 and the array polypoints[] should contain 2(N+1) integers with first 2 integers equal to last 2 integers.

        Let us study more about shapes latter. Here is some idea about colors. There are 16 colors declared in graphics.h as listed bellow.

BLACK:                  0 BLUE:                     1 GREEN:                  2CYAN:                    3 RED:                       4 MAGENTA:            5 BROWN:                 6LIGHTGRAY:         7

Page 51: Project Report on Second Final Main Online Library Management System With 60 Pages

DARKGRAY:          8LIGHTBLUE:           9LIGHTGREEN:       10 LIGHTCYAN:         11LIGHTRED:            12 LIGHTMAGENTA: 13YELLOW:               14WHITE:                   15

        To use these colors, use functions setcolor(), setbkcolor() and setfillstyle(). setcolor() function sets the current drawing color. If we use setcolor(RED); and draw any shape, line or text after that, the  drawing  will   be   in   red   color.   You   can  either  use   color   as  defined  above  or  number   like setcolor(4);.  setbkcolor()  sets  background color   for  drawing.  Setfillstyle  sets  fill  pattern and fill colors. After calling setfillstyle, if we use functions like floodfill, fillpoly, bar etc, shpes will be filled with fill color and pattern set using setfillstyle. These function declarations are as follows.


 void far setfillstyle(int pattern, int color);

void far setcolor(int color);

void far setbkcolor(int color);


setfillstyle sets the current fill pattern and fill color.

setcolor sets the current drawing color to color, which can range from 0 to getmaxcolor.

setbkcolor sets the background to the color specified by color.

        The parameter pattern in setfillstyle is as follows:

 Names Value Means  Fill With...

EMPTY_FILL 0 Background color

SOLID_FILL 1 Solid fill



SLASH_FILL 4 ///, thick lines

Page 52: Project Report on Second Final Main Online Library Management System With 60 Pages

BKSLASH_FILL 5 \\\, thick lines


HATCH_FILL 7 Light hatch

XHATCH_FILL 8 Heavy crosshatch

INTERLEAVE_FILL 9 Interleaving lines

WIDE_DOT_FILL 10 Widely spaced dots

CLOSE_DOT_FILL 11 Closely spaced dots

USER_FILL 12 User-defined fill pattern

        Here is an example program with colors, pixels, bar, cleardevice etc. stdlib.h is used for random number generation. We have a function random(no), it returns a random number between 0 an no. The effect is by drawing random radius, random color circles with same center and random pixels. kbhit() function(defined in conio.h) returns a nonzero value when a key is pressed in the keyboard. So, the loop will continue until a key is pressed.

/*random.csome graphics effects using random numbers.example 1.2by HarshaPerla,*/

#include "graphics.h"#include "conio.h"#include "stdlib.h"

void main(){    int gd,gm;    gd=DETECT;

    initgraph(&gd, &gm, "");    setcolor(3);    setfillstyle(SOLID_FILL,RED);    bar(50, 50, 590, 430);        setfillstyle(1, 14);

Page 53: Project Report on Second Final Main Online Library Management System With 60 Pages

    bar(100, 100, 540, 380);

    while(!kbhit())    {        putpixel(random(439)+101,  random(279)+101,random(16));        setcolor(random(16));        circle(320,240,random(100));    }    getch();    closegraph();}

Page 54: Project Report on Second Final Main Online Library Management System With 60 Pages

C File I/O and Binary File I/O

When accessing files through C, the first necessity is to have a way to access the files. For C File I/O you need to use a FILE pointer, which will let the program keep track of the file being accessed. (You can think of it as the memory address of the file or the location of the file).

For example:

FILE *fp;To open a file you need to use the fopen function, which returns a FILE pointer. Once you've opened a file, you can use the FILE pointer to let the compiler perform input and output functions on the file.

FILE *fopen(const char *filename, const char *mode);In the filename, if you use a string literal as the argument, you need to remember to use double backslashes rather than a single backslash as you otherwise risk an escape character such as \t. Using double backslashes \\ escapes the \ key, so the string works as it is expected. Your users, of course, do not need to do this! It's just the way quoted strings are handled in C and C++.

The modes are as follows:

r - open for readingw - open for writing (file need not exist)a - open for appending (file need not exist)r+ - open for reading and writing, start at beginningw+ - open for reading and writing (overwrite file)a+ - open for reading and writing (append if file exists)Note that it's possible for fopen to fail even if your program is perfectly correct: you might try to open a file specified by the user, and that file might not exist (or it might be write-protected). In those cases, fopen will return 0, the NULL pointer.

Here's a simple example of using fopen:

FILE *fp;fp=fopen("c:\\test.txt", "r");This code will open test.txt for reading in text mode. To open a file in a binary mode you must add a b to the end of the mode string; for example, "rb" (for the reading and writing modes, you can add the b either after the plus sign - "r+b" - or before - "rb+")

To close a function you can use the function

int fclose(FILE *a_file);

Page 55: Project Report on Second Final Main Online Library Management System With 60 Pages

fclose returns zero if the file is closed successfully.

An example of fclose is

fclose(fp);To work with text input and output, you use fprintf and fscanf, both of which are similar to their friends printf and scanf except that you must pass the FILE pointer as first argument. For example:

FILE *fp;fp=fopen("c:\\test.txt", "w");fprintf(fp, "Testing...\n");It is also possible to read (or write) a single character at a time--this can be useful if you wish to perform character-by-character input (for instance, if you need to keep track of every piece of punctuation in a file it would make more sense to read in a single character than to read in a string at a time.) The fgetc function, which takes a file pointer, and returns an int, will let you read a single character from a file:

int fgetc (FILE *fp);Notice that fgetc returns an int. What this actually means is that when it reads a normal character in the file, it will return a value suitable for storing in an unsigned char (basically, a number in the range 0 to 255). On the other hand, when you're at the very end of the file, you can't get a character value--in this case, fgetc will return "EOF", which is a constnat that indicates that you've reached the end of the file.

The fputc function allows you to write a character at a time--you might find this useful if you wanted to copy a file character by character. It looks like this:

int fputc( int c, FILE *fp );

Note that the first argument should be in the range of an unsigned char so that it is a valid character. The second argument is the file to write to. On success, fputc will return the value c, and on failure, it will return EOF.

Binary I/O

For binary File I/O you use fread and fwrite.

The declarations for each are similar:

size_t fread(void *ptr, size_t size_of_elements, size_t number_of_elements, FILE *a_file); size_t fwrite(const void *ptr, size_t size_of_elements, size_t number_of_elements, FILE *a_file);Both of these functions deal with blocks of memories - usually arrays. Because they accept pointers, you can also use these functions with other data structures; you can even write structs to a file or a read struct into memory.

Page 56: Project Report on Second Final Main Online Library Management System With 60 Pages

Let's look at one function to see how the notation works.

fread takes four arguments. Don't by confused by the declaration of a void *ptr; void means that it is a pointer that can be used for any type variable. The first argument is the name of the array or the address of the structure you want to write to the file. The second argument is the size of each element of the array; it is in bytes. For example, if you have an array of characters, you would want to read it in one byte chunks, so size_of_elements is one. You can use the sizeof operator to get the size of the various datatypes; for example, if you have a variable int x; you can get the size of x with sizeof(x);. This usage works even for structs or arrays. Eg, if you have a variable of a struct type with the name a_struct, you can use sizeof(a_struct) to find out how much memory it is taking up.



The third argument is simply how many elements you want to read or write; for example, if you pass a 100 element array, you want to read no more than 100 elements, so you pass in 100.

The final argument is simply the file pointer we've been using. When fread is used, after being passed an array, fread will read from the file until it has filled the array, and it will return the number of elements actually read. If the file, for example, is only 30 bytes, but you try to read 100 bytes, it will return that it read 30 bytes. To check to ensure the end of file was reached, use the feof function, which accepts a FILE pointer and returns true if the end of the file has been reached.

fwrite is similar in usage, except instead of reading into the memory you write from memory into a file.

For example,

FILE *fp;fp=fopen("c:\\test.bin", "wb");char x[10]="ABCDEFGHIJ";fwrite(x, sizeof(x[0]), sizeof(x)/sizeof(x[0]), fp);

Page 57: Project Report on Second Final Main Online Library Management System With 60 Pages

Fu t u r e Sc ope


This application can be easily implemented under various situations. We can add new features as and when we require. Reusability is possible as and when require in this application. There is flexibility in all the modules.

S O F T W A R E S C O PE : • Exte n s i bi l i t y : This software is extendable in ways that its original

developers may not expect. The following principles enhances extensibility like hide data structure, avoid traversing multiple links or methods, avoid case statements on object type and distinguish public and private operations.

• R e u sa b ili t y : Reusability is possible as and when require in this application. We can update it next version. Reusable software reduces design, coding and testing cost by amortizing effort over several designs. Reducing the amount of code also simplifies understanding, which increases the likelihood that the code is correct. We follow up both types of reusability: Sharing of newly written code within a project and reuse of previously written code on new projects

Page 58: Project Report on Second Final Main Online Library Management System With 60 Pages

• Und e r sta nd a b ili t y : A method is understandable if someone other than the creator of the method can understand the code (as well as the creator after a time lapse). We use the method, which small and coherent helps to accomplish this.

• Co st-effect i v e n ess: Its cost is under the budget and make within given time period. It is desirable to aim for a system with a minimum cost subject to the condition that it must satisfy the entire requirement.

Scope of this document is to put down the requirements, clearly identifying the information needed by the user, the source of theinformation and outputs expected from the system.

Page 59: Project Report on Second Final Main Online Library Management System With 60 Pages

C onc l u s i o n

From a proper analysis of positive points and constraints on the component, it can be safely concluded that the product is a highly efficient GUI based component. This application is working properly and meeting to all user requirements. This component can be easily plugged in many other systems.

Page 60: Project Report on Second Final Main Online Library Management System With 60 Pages

Bibliog rap h y

Books: Let Us C By Yashavant Kanetkar C++ By E Balagurusamy

Web Sites:


• www . w i k i ped i a. c om