Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 49

Project Report

ON
Institute Management System in C Language

Project report submitted to SLIET In partial fulfillment of the requirement of the CCA

Under the expert guidance of :Mrs. Neha Chugh

Submitted to:SLIET

Submitted by:Sidhant Bansal(090201) Sunmeet Singh(090207)

Acknowledgement
It gives us pleasure to put on my records our regards and gratitude to Mr. Birmohan Singh, HOD of Computer Department Guider our project report SLIET College Longowal. And detailed guidance, patience and helping attitude in the completion of the project in hand. his gentle and persuasive ways have been a great source of inspiration for which we shall be grateful to him. We owe our thanks also to other members of the faculty for their inspiration and encouragement which helped a lot during our project. Some of close friends have always been at our back to see the completion of the project in hand. We are beholden to all of them. Last but not least, we wish to extend our sincere thanks and gratitude to every person who directly or indirectly helped us to create a congenial and inspiring atmosphere for the successful completion of our project.

Sidhant Bansal Sunmeet Singh

PROBLEM ANALYSIS
Problem analysis is done in order to understand the problem the software system is to solve. The problem can be automating an existing manual process, developing a new automated process or a combination of two. The emphasis in requirements analysis is on identifying what is needed from the system, not how the system will achieve its goals. The goal of problem analysis phase to produce the requirements specification document. There are two major activities in this phase : Problem understanding and requirement specification. In problem analysis, the analyst has to understand the problem and its context. The goal of this activity is to understand the requirements of the new system to be developed. Once the problem is analyzed and the essentials understood, the requirements must be specified in the requirements specification document. The basic aim of problem analysis is to obtain the clear understanding of the needs of the clients and the users, what exactly is desired from software and what the constraints on the solution are. It is essential that during analysis a complete and consistent set of specifications emerge for the system. There are some problems for achieving this. The first major problem is to obtain the necessary information. During analysis, a massive amount of information is collected in the form of answers to questions, questionnaires, information from documentation and ideas.As it is important to have complete set of requirements, it is essential that is gathered information be organized so that it can be evaluated for completeness. The second major problem of analysis is how to organize the information obtained so the information can be effectively evaluated for completeness and consistency. The third major problem during analysis is resolving the contradictions that may exist in the information from different parties. This is essential to ensure that the final specifications are consistent. The fourth major problem is avoiding internal design. A good structuring of information can guide the analyst and help him determine the areas of

incompleteness. The basic principle used in analysis is same as in any complex task : divide and conquer. That is, partition the problem into sub problems and then try to understand each sub problem and its relationship to other sub problems in an effort to understand the total problem. During analysis, partitioning is done with respect to objects and functions.The concepts of state and partitioning process. A state of a system represents some conditions about the system. While using projection, different viewpoints of the system are defined and the system is analyzed from these perceptive separately using an object based and function based approach. The different projections obtained are combined to form the analysis for the complete system. The advantage of using projection is that trying to analyze the system from a global viewpoint is difficult and error-prone. The informal approach to analysis is one where no defined methodology is used. The information about the system is obtained by the interaction with the client, endusers, questionnaires, study of existing documents. In this approach no formal model is built of the system. Any documents describing the work or the organization may be given along with the outputs of the existing methods to perform the tasks. The structured analysis technique uses function-based decomposition while modeling the problem. It focuses on the functions performed in the problem domain and the data consmed and produced by these functions. It is a top-down refinement approach which was originally called structured analysis and specifications. The limitation of the existing system is that if we want to open any file then we first have to open it and have to give proper path where the file is residing or if we dont know the proper path then we have to search the file. The system which we are going to develop is the system in which we need not to go in tc directory ,we can perform various operations such as read, write, append, copy, delete, cut-paste, overwrite, rename, list etc. on the files in tc directly.

REQUIRMENT
1)The system should be user friendly. 2)The system should be completely menu driven system. 3)The system should be efficient . 4)The system should be fastly responding by careful programming. 5)The system should avoid delays. 6)The system should be completely usable. 7)The system should be fully perfect by giving the system to users and then make appropriate modifications according to the enhanced needs of the users. 8)The system should be able to perform all the operations in a correct manner and display all the outputs according to the requirement of the user. In our system, there are different operations to be performed on files which are as follows:1)OPEN 2)WRITE 3)RENAME 4)APPEND 5)CUT-PASTE 6)DELETE 7)COPY 8)LIST 9)OVERWRITE 10) HELP 11) EXIT OPEN:This function is used to open an existing an file in tc directory i.e. we can only read the contents of the file. We can neither write into this existing file noe can perform any operation on this file. We are just asked to enter a file name .After entering this file name that particular file will be displayed on the screen otherwise there will be message that

the file does not exists. WRITE:This is a function used to write in a new file .When we run this module, the name of file which we want to create is entered. If the file name which we have entered already exists then there will be a message that this file already exists otherwise it will give a message that a file is created successfully. RENAME:If there is a need to change the name of the existing file then this function is activated or used. This process includes entering the old file name and then entering the new file name with which we want to change the previous one .If the new name is already given to any file that is already existing then there will be a message of already existence of this file. APPEND:This is a module used to add some more information in the existing file. Users are asked to enter the file name to which changes are made. Then the contents of that file are shown on the screen and it allows the users to add some more statements. If the file name entered is not found then the error message of file not found is displayed on the screen. CUT-PASTE:This module is used when we want to remove a file from one place and want to copy it to another place. We can perform this operation in moving file from one folder to another. We enter the name of the file which we want to move and also give the path where we want to paste this file. DELETE:If a file seemed to be not so useful ,there is no need to keep it. So, in this system, this module is used to remove the unwanted files. When we run this module, name of the file which we want to delete will be asked. On entering the name,if the file has been deleted

then there will be a message that the file is deleted successfully otherwise if the file does not exists message is displayed. COPY:In this copy module, we can copy a file i.e. we can make a copy of the existing file.The input of copy module is the old file name and the new name of the file. The old file name is the file name which is to be copied and new file name is the file name where it is to be copied. we can a file from one directory to another directory. The output of the copy module is that the file is copied successfully other the error message of file does not exists is displayed. LIST:In the list module, we can see the list of all the files and the sub-directories existing in tc directory. The output will be the list of all the files residing in tc directory. OVERWRITE:In overwrite module, we can overwrite a file i.e. we can write in that file without deleting it. The contents of the file are deleted but name remains present and we can write into it whatever we want. HELP:The function help is very useful in understanding the system. It provides us with the information about how to use the system, which keys are used for which purpose. EXIT:With the help of exit ,we can come out of the system. 1)Hardware Requirements RAM MEMORY PROCESSOR 64MB 10.2MB Pentium-3 processor

2)Software Rrequirements We have used C++ language in our system which is an object oriented programming language. We have also used MS-word software for our system documentation and report completion.

PROJECT PLAN
The project planning can take into account the following phases. 1)Analysis Phase 2)Design Phase 3)Testing 4) 1) Analysis phase Analysis phase includes the study of the problem and the creation of the requirements specification document. It also involves the study of the various tools required for implementing the problem .The analysis is basically concerned with the decomposition of a problem into its component parts and establishing a logical model to describe the system functions. The analysis consists of following steps: 1) Understanding the problem. 2)Drawing the specifications of requirements of the user and the software. 3)Identifying the objects and their attributes. 4)Identifying the services that each object is expected to provide. 5)Establishing inter-connections between the objects in terms of services required and the services rendered. Problem Understanding The first step in analysis phase is to understand the problem of the user The problem should be refined and defined .The problem statement provide the basis for Maintenance

drawing the requirements specification of both the user and the software. Requirement Specification Once the problem is clearly defined, the next step is to understand what the proposed system is required to do. A clear understanding should exists between the user and the developer of what is required. Based on the user requirements, the specification for the software should be drawn. It should be clear: 1)What outputs are required. 2)What processes are involved to produce these outputs. 3)What inputs are necessary. 4)What resources are required. 2) Design phase Design is concerned with the mapping of the objects in the problem space into objects in the solution space and creating an overall structure and computational models of the system. It is important to construct structured hierarchies, to identify abstract classes and to simplify the inter-object communications. The design involves following steps: 1)Review of the objects created in the analysis phase. 2)Specifications of class dependencies. 3)Organisations of class hierarchies. 4)Design of classes. 5)Design of member functions. 6)Design of driver program. 3) Testing During testing, the program to be tested is executed with a set of test cases and

the output of the program for the test cases is evaluated to determine if the program is performing as expected. Testing is the major quality control measure used during software development. after coding phase, computer programs are available that can be executed for testing purposes. It implies that testing not only has to uncover errors introduced during coding, but also errors introduced during the previous phases. Different levels if testing are used. 1) 2) 3) Unit testing Integration testing System testing

In unit testing, modules are tested separately and is often performed by the coder himself simultaneously along with the coding of the module. The purpose is to exercise the different parts of the module code to detect coding errors. After this, the modules are gradually integrated into subsystems, which are then integrated to eventually form the entire system. During integration, testing is performed to detect design errors by focusing on testing of interconnection between of modules. After the system is put together, system testing is performed. The system is tested against the system requirements to see if all the requirements are met and if the system performs as specified by the requirements. Then acceptance testing is performed to demonstrate to the client, the operation of the system. Testing is a software development project, errors can be injected at any stage during development. 1)Testing fundamentals 2)Functional Testing 3)Structural Testing Testing Fundamentals 1)Error, Fault and Failure The term error is used in two different ways. It refers to the discrepancy between a

computed, observed or measured value and the true specified or theoretically correct value. That is, error refers to the difference between the actual output of software and the correct output. Error is also used to refer to human action that results in software containing a defect or fault. Fault is a condition that causes a system to fail in performing its required function. A fault is the basic reason for software malfunction and is synonymous with the commonly used term bug. It should be noted that the only faults that software has are design faults; there is no wear and tear in the software. Failure is the inability of a system or component to perform a required function according to its specifications. A software failure occurs if the behavior of the software is different from specified behavior. Failures may be caused due to functional or performance reasons. A failure is produced only when there is a fault in a system. However, presence of a fault does not guarantee a failure. In other words, faults have the potential to cause failure and their presence is a necessary but not a sufficient condition for a failure to occur. It is possible that a failure may occur but not necessary. 2) Test Oracles To test any program, we need to have a description of its expected behavior and a method of determining whether the observed behavior confirms to the expected behavior. For this we need test oracle. A test oracle is a mechanim, different from the program itself, that can be used to check the correctness of the output of the program for the test cases. We can consider testing a process in which the test cases are given to the test oracle and program under testing. The output of the two is then compared to determine if the program behaved correctly for the test cases. Test oracles are necessary for testing. There are some systems where oracles are automatically generated from specifications of program or modules. With such oracles, we are assured that the output of the oracle is consistent with the specifications. 3) Top-down and Bottom-up Approaches

Generally, parts of the program are tested before testing the entire program. Besides partitioning the problem of testing, another reason for testing parts separately is that if a test case detects an error in a large program, it will be extremely difficult to pinpoint the source of error. In many cases, it is even difficult to construct test cases so that all the modules will be executed. There are two common ways modules can be combined, as they are tested, to form a working program : top-down and bottom-up. In top down strategy, we start by testing the top of the hierarchy and we incrementally add modules that it calls and then test the new combined system. This approach of testing requires stubs to be written. A stub is a dummy routine that simulates a module. In top-down approach, a module can not be tested in isolation because they invoke some other modules. The bottom-up approach starts from the bottom of hierarchy. First the modules at the very bottom, which have no subordinates, are tested. Then the modules are combined with higher-level modules for testing. To perform bottom-up testing, drivers are needed to set up the appropriate environment and invoke the module. It is the job of the driver to invoke the module under testing with the different set of test cases. 4)Test Cases and Test criteria There are two fundamental goals of the practical testing activity: maximize the number of errors and minimize the number of test cases. While selecting the test cases, the primary objective is ti ensure that if there is an error or fault in a program, it is exercised by one of the test cases. An ideal test case set is one that succeeds only if there are no errors in the program. This is often called exhaustive testing. Hence, realistic goal for testing is to select a set of test cases that is close to ideal. For this test selection criterion can be used. For a given program P and its specifications S,a test selection criterion specifies the conditions that must be satisfied by a set of the test cases. The criterion becomes a basis for test case selection. There are two aspects of test case selection-specifying a criterion for evaluating a set of test cases and generating a set of test cases that satisfy a given criterion. There are two fundamental properties for a

test criterion: reliability and validity. A criterion is reliable if all the sets that satisfy the criterion detect the same errors. A criterion is calid if for any error in the program there is some set satisfying the criterion that will reveal error. The first axiom is the application axiom, which states that for every program there exists a test set T that satisfies the criterion. The antiextensionality axoim states that there are programs P and Q, both of which implement the same specifications, such that test set T satisfies the criterion for P but does not satisfy the criterion for Q. The antidecomposition axiom states that a program P and its component Q such that a test case set T satisfies the criterion for P and T is the set of the values that variables can assume on entering Q for some test case in T and T does not satisfy the criterion for Q. The anticomposition axiom states that there exists programs P and Q such that T satisfies The criterion for P and the outputs of P for T satisfy the criterion for Q but T does not satisfy the criterion for P,Q.

Functional testing
There are two basic approaches to testing : functional structuring and structural testing. In functional testing, the structure of the program is not considered. Test cases are decided solely on the basis of requirements or specifications of the program or module, and the internals of the module or the program are not considered for selection of tests cases. Due to this, functional testing is called as black box testing. In trucural approach, test cases are generated based one actual code of the program or module to be tested. This structural approach is also known as glass box testing. The basis for deciding test cases in functional testing is the requirements or specifications of the system or module. There are number of techniques that can be used to select test cases are: 1)Equivalence Class Partitioning

Because we cannot do exhaustive testing ,the next natural approach is to divide the domain of all the inputs into a set of equivalence classes, so that if any test in an equivalence class succeeds, then every test in that class will succeed. That is want to identify classes of tests cases such that the success of one test case in class implies the success of others. Without looking at the internal structure of the program, it is impossible to determine such ideal equivalence classes. Equivalence classes are usually formed by considering each condition specified on input as specifying a valid equivalence class and one or more invalid equivalence classes. For example, if an input condition specifies a range of values, then form a valid equivalence class with that range and two invalid equivalence classes, one with values less than the lower bound of range and the other with value higher than the higher bound. 2) Boundary Value Analysis It has been observed that programs that works correctly for a set of values in an equivalence class will fail on some special values. These values often lie on the boundary of the equivalence class. In boundary analysis, we choose an input for a test case from an equivalence class, such that the input lies at the edge of the equivalence class. Boundary value test cases are called extreme cases. Hence, boundary value test case is a set of input data that lies on the edge or boundary of a class of input data or that generates output that lies at the boundary of a class of output data. 3) Cause-Effect Graphing One weakness with the equivalence class partitioning and boundary value methods is that they consider each input separately. That is, both concentrate on the conditions and classes of one input. They do not consider combinations of

input circumstances that may form interesting situations that should be tested. Cause-Effect graphing is a technique that aids in selecting combinations of input conditions in a systematic way, such that the number of test cases does not become unmanageably large. The technique starts with identifying causes and effects of the system under testing. A cause is a distinct input condition and an effect is a distinct output condition. 4)Special Cases It has been seen that programs often produce incorrect behaviour when inputs from some special cases. The reason is that in programs, some combinations of inputs need special treatment and providing proper handling for these special cases is easily overlooked. For example, in an arithmetic routine, if there is a division and the divisor is zero, some special action has to be taken, which could easily be forgotten by the programmer. Structural Testing The functional testing is concerned with functionality rather than implementation of the program whereas structural testing is concerned with testing the implementation of the program. To tests the structure of the program, structural testing aims to achieve test cases that will force the desired coverage of different structures. 1)Control-Flow Based criteria Let the control flow graph of a program P be G,A node in this graph represents a block of statements that is always executed together, i.e. whenever the first statement is executed, all other statements are also executed. An edge (I,j)

represents a possible transfer of control after executing the last statement of the block represented by node I to the first statement of the block represented by node j.A node corresponding to a block whose first statement is the start statement of P is called the start node of G and a node corresponding to a block whose last statement is an exit statement is called an exit node. A path is a finite sequence of nodes (n1,n2,n3.nk),k>1,such that there is an edge(n(1),n(I+1)) for all nodes ni in the sequence. A complete path is a path whose first node is the start node and the last node is the exit node. Now let us consider control-flow based criteria. The simplest coverage criteria is statement coverage, which requires that such statement of the program be executed at least once during testing. A little more general coverage criteria is branch coverage ,which requires that edge in the control flow graph be traversed atleast once during testing. In other words, branch coverage requires that each decision in the program be evaluated to true and false values at least once during testing. Testing branch based on branch coverage is called branch testing. A more general coverage criteria is one that requires all possible paths in the control flow graph be executed during testing. This is called the path coverage criterion or the all path criterion and the testing based on the criterion is often called path testing. The difficulty with this criterion is that programs that contain loops can have an infinity number of possible paths. Another such approach based on the cyclometric complexity has been proposed in the test criterion is that if the cyclomatric complexity of the module is V, then at least V distinct paths must be executed during testing. We have seen that cyclomatric complexity V of a module is the number of independent paths in the flow graph of a module. 2)Data Flow Based Testing The basic idea behind data flow based testing is to make sure that during

testing, the definitions of variables and their subsequent use is tested. A variable occurrence can be one of the following three types: 1.Def represents the definition of a variable. The variable on the left hand side of an assignment statement is the one getting defined. 2.C-use represents computational use of variable. Any statement that uses the value of variables for computational purposes is said to be making c-use of the variables. 3. P-use represents predicate use. These are all the occurrences of the variables an a predicate, which is used for transfer of control. 3) Mutation Testing Mutation testing does not take a path based approach. Instead, it takes the program and creates many mutants of it by making simple changes to the program. The goal of testing is to make sure that during the course of testing, each mutant produces an output different from the output of the original program. Let us discuss the mutation testing approach in bit more detail. For a program under a test P, mutation testing prepares a set of mutants by applying mutation operators an the text of P. The set of mutation operators depends on the language in which P is written. A mutation operator makes a small unit change in program to produce a mutant. Examples of mutation operators are :replace an arithmetic operator with some other arithmetic operator, change an array reference, replace a constant with another constant of the same type. One of the main problem of mutation testing relates to its performance. The number of mutants that can be generated by applying first-order mutation operators is quite large and depends on the language and the size of mutation operator set. 3)Test Case Generation and Tool Support

Once a coverage criterion is decided on, two problems have to be solved to use the chosen criterion for testing. The first is to decide if a set of test cases satisfy the criterion and the second is to generate a set of test cases for a given criterion. 5) Maintenance Bugs are not the only reason that you will work on a program after you think you are completely done with it. Program maintenance is necessary because requirements change, companies change, and laws change. You must also change the programs you write so that they remain viable programs; you will need to update your programs periodically to reflect changes that impact the program. In addition, users will think of new things that they want the program to do. In todays fast changing world, program maintenance is more critical than ever before. The computer programs of today must be fluid and maintainable so that programmers can quickly change the program to meet the needs of a changing environment in which the programs are used. Program maintenance is the term used for updating of a program after the program is put into use. This update may be the result of a users request or a change in a way the program needs to operate. It is said that a program is written once but updates many times and you can ease the burden of program maintenance by following a few general guidelines when you write your program. The more program maintenance you perform, the more likely that your program will be up-to-date and in use. You may want to release new versions of your program so that users can, with a different version number on the opening screen that you place there, keep track if the latest version installed on their system. Documentation is comprised of descriptions of the program. You can place documentation inside the program itself so that when you(or someone else)later make a change to the program, you will read what sections of the program are for

without having to figure out what the codes purpose is. Internal program descriptions are called remarks. The more remarks you put in your program and the clearer you write the program code instead of using tedious, complicated, tricky program statements, the easier it will be for you and others to track errors and maintain the program later. Add program remarks as you write your program because it is at that time that you understand the program the best. If you wait until after you complete an application, as many programmers do, your application might never be properly documented because other projects cam take over your time, and the documentation is often pished aside once a project is completed. In addition, you may want to write the external documentation with screen shots of the programs different screens and descriptions of what the user must do to start, use, and terminate the program. The better your users documentation is, more likely your user will master your program and want to use more programs that you write. Limitations of this system The limitations of our system is that we can not perform these operations on some part of the files. If we want to change two or three lines in a file then we cannot do this with append command, with write command or with overwrite command. Whole of the contents are changed with these commands. Implementation Implementation includes coding and testing. Coding includes writing codes for classes, member functions and the main program that acts as a driver in the program. Coding becomes easy once a detailed design has been done. The goal of coding phase is to translate the design of the system produced during the design

phase into code in a given programming language. The coding phase effects both testing and maintenance profoundly. The programs should not be constructed so that they are easy to write, but so that they are easy to read and understand. Testing the program before using is an essential part of the software development process. The final goal of testing is to see that the system performs its intended job satisfactory. The program to be tested is executed with a set of test cases and the output of the program for the test cases is evaluated to determine if the program is performing as expected.

INTRODUCTION TO C The c language is one of the powerful languages it was developed by Dennis Ritchie at the AT & T bell laboratories. It is a combination of b& pl & b language. It has several advantages when c was invented it was mostly used as a language for developing the operating system. But now a days it is wed for different type of application due to the following reasons 1.C is portable means program written for one computer may run successfully on other computers. 2.C is fast means the executable program obtained after compiling and linking run very fast. 3.C is compact i.e the statement in c language are generally short but are very powerful several operations can recombined together in just one statement. 4.The C language has both the simplicity of high level language and low level language. HOW TO INVOKE C

C:>CD TC

<ENTER>

C:/ TC> CD BTN <ENTER> C:/ TC/ BTN>TC. <ENTER> 1.To write a new Program in c open the file menu by pressing alt and f key and then now and press enter key start writing your program. 2.Save it by pressing F2 key or go in file menu. 3.Give any file name but with extension. C 4.Now compile the program (alt and F9). 5.If it is successful then run the program by pressing ctrl & F9 key. 6.If there is any error in program it will give errors first of all remove errors and then run it. 7.To close the previous file press alt and F3 key. 8. To come out from c press Alt and X. What are key words? 1These are words which are used by compiler and has specific meaning for the compiler. 1. These are not used by user for any other purpose. 2. C language has the best key words. 3. Programs are written instructions in one line. 4. Every statement in C languages ends with a semicolon. 5. Every program has function main ( ). Print ( ) f function -- It is a built in function. it has one argument and argument es a string of characters enclosed in double quotes. We have use two print f statement to print two message if we want to print in free format means no rule to write

the message in different line or with next tab position etc we use escape sequence Display Some Message By These Escape Sequences Print your name age class roll no. and address etc. in single line and in different lines. Types of data (1) Int (2) Float (3) Double (4) Char Int Type Int type of constant is a positive or negative number without a decimal point a decimal point eg-34,506,-11,-9642.they are whole nosing the range-32768 to +32767(to define a int type data see rules at page 7) to print the value of int type of constant we use conversion specifier %d it topes two bytes of memory. Tell About include<stdio,h> clrscr ( ); getch ( ); Arithmetic operations NAME i. ADDITION ii. iii. iv. SUBSTRACTION MULTIPLICATION DIVITION SYMBOL + * \

Float Type- these are numbers either positive or negative with or without decimal

eg/ - 13.26, 45.8, 89, 89.0 etc . they lie in the range 3.4*10 -38 to 3.4*10+38 accurate up to 7 days and conversion Specifies is % f and it takes four bytes of memory. Scanf ( ) function : It is a built in function used to input the data example:- input two nos. and add them Preprocessor Directories :- written in an independent line . it starts with Symbol#. e.g.# define pi 3.141593 Double Type Of Data:- the pay board double is used to dedare variables of the double type and the value assigned is accurate up to sixteen digits it lies in the range 1.7*10-308 to 1.7*10+308 and conversion specified is % 1f. it takes 8 bytes of memory. The math. H files:mathematical function. like sqrt ( ), sin (X) pqw ( ), function etc. how to include this file # < math.h >. Hint- use power function i.e. Z = Pow(X,Z) +Pow(Y,Z) UPDATING ASSIGNMENT OPERATOR:in c programs we write statements such as X=X+4 or X=X*Y etc. They can be used a following. Operator += -= *= /= % =(used only) (with int) The increment and decrement Operator :- In c it is required to increase or decrease the value assigned to int type of variable by one in c there operator are known as increment operator. example X+=4; Y-= 3; Z*=4; P/ = 9; % =Z, P=P/9 =i %Z meaning X=X+4 Y=Y-3 Z=Z*4 this file contains the definition of several built in

eg a++ ; same as a = a+1;it is called pre increment operator we can write the increment operator before the name of the variable also like eg ++ a; it also increases the value assigned to a by one ort is called post increment and with other operator do not appear in combination with other operator is same statement then is no difference in both operators but when there are used with other operators they behave differently. Suppose we have b=7 eg a= b ++; the value a will be 7 and b will be 8 because the value of b is first assigned to a and b is incremented by one but of we write as a= ++ b; then a will be 8 become n increment its valve and then assign to a. Relational Operators :Name 1) Greater then 2)Less then 3)Equal to 4)Not equal to 5)Greater than or equal to 6)Less then or equal to <= != >= C symbol. > < ==

A relational expression represents a relation between two variables or one variable and one constant by using one of there relational operators eg a > b, = = 3 x! =5 etc Decision Making In c ;If else Statement :This used to make decision in C. The general format of the if statement is as follows :RULES TO IF STATEMENT 1.If ends with a pair of parenthesis. 2.There is no semicolon after the parenthesis. 3.When control falls to line containing if the relation at expression will be

evaluated in parenthesis it is true statement will be executed if it is false statement 3 and 4 will be executed. 4.If we want to execute more than one statement in if then curly braces arte must before and after the statement otherwise there is no need. LOGICAL OPERATOR IN C 1)AND 2) OR 3) NOT

NESTED IF ELSE STATEMENT: It is also possible to have one if else statement inside another if else statement in this case we say that if else statement are nested. Such nested statements appear when we have two or more conditions to be tested.

CONDITIONAL OPERATOR (TERNARY OPERATOR) The general format of the conditional operator is:result = ( Test expression)? Statement 1 : statement 2 Here result is variable of same type such as int. or char. The test expression will be evaluated if it is true then statement I will be executed if false then statement 2 will be executed. RELATIONAL OPERATOR AND PRPROCESSOR We can use # define directive while writing the relational operator. For e.g. we can define the symbols & and 11 by the words AND and OR. Char Type of data :- This type constants consists of a character enclosed in a pair of single quotes such as a b c even a blank space can be used as a character. This variable need only one byte of memory space the conversion specifies is % c.

Boolean functions:- The expressions involving the relational operators can have only two possible outcomes. They can be true or false. If false it is said to have an out come O if it is true it is said to have an out came different from O either a positive or even a negative integer. THE SWITCH STATEMENT:1.It can be considered as a generalization of if else statement. 2.In switch we have a multiple choice depending on the choice of the value assigned to a variable one or more statements from a group of the statements can be executed. 3.The variable used for this purpose is know as switch variable. 4. The variable in the switch statement can be int or char type only. 5. The switch statement can also contain the default statements in one of the lines. It is optional but it should be only one. LOOPS IN C Loop is a part of the program through which the control moves several times during the execution of program. The part, which is executed again and again, is known as the body of the loop. In C we have three types of loops. These are known as :a)The while loop b)The do while loop c)The for loop THE WHILE LOOP:The general format of the while loop is while (expression) { statement a; statement b; }

There will be no semicolon at the end of the line containing the key word while. LONG TYPE INTEGER These type of integer have a range 2147484648 to +21477483647. Syntax is: long int. variable name. the conversion specifier is % ld. The do while loop: the general format of the do while loop is do { statement a; statement b; } while (expression); statement c; Generally the do while loop is used to carry out the data validity test. as it is not possible to calculate the square root of a negative no. if we enter a negative no. it will again the user to enter the positive no. ASSIGNMENT:- Print the message according to your choice For example:if choice 1 if choice 2 if choice 3 if choice 4 print hello print good morning. print good bye. exit

Program should run continuously until you press 4. THE FOR LOOP:- The function for this type of loop as follows:

for (statement a; expression b; statement C) statement 1; statement 2; 1.The statement.1 forms the body of the loop. 2.When the control falls to line containing for the statement a is executed. This is a statement which assign some initial value to variable called index variable and this executed only once in the beginning of the loop. 3.The expression b is a logical expression involving some relational operator if the expression is true the body of the for loop is executed. 4.After the execution of the body of the for loop the statement c is executed. 5.Statement c alters the value of the index variable if the expression b is true the entire process is repeated again. NESTED LOOPS :It is possible o have one loop inside another loop such loops ( one inside the other) is known as the nested loop. Formatted Input And Output :(1) The VDU. screen displays the data in twenty five lines. (2) And each line can have so columns. in some cases. means to display the data we have 25rows (0to24) and 80 columns(0 to 79) (3) In some cases it is necessary to display the data on the screen in the form of a table or in some other form. (4) The print f function can be used to display the data the formatted output can be obtained by including some more characters after the % sign. . Formatted output for the float type of data

print f (%16.4f, 5678.6789); in this case the number entered by the user is printed I.in the field of sixteen columns. II.it is right justified in the field. III.the number is printed to four digits after the decimal point. Formatted input: 1. We can input several different type of data by using single scan f ( )function. For example:print f (\n enter the three sides of a triangle); scan f (%d%d%d, &a, &b, &c); 1.We can also write the scan f ( )function in different way we can write one or more characters between the conversion specifications. Example:scan f (%d:%d:%d: &a, &b, &c); now we should type the three number separated by the sign as 34:78:90 and then press <enter> key in the sane way we can used semi colon or even word and instead of colon: Functions: Why we use function I.We use functions to simplify our work that would be repetitious. II.Functions ate mostly used in c for a series of instructions that are to be executed more then once but it is not like a loop. III.A loop can repeat a series of instructions only if each statement follows the previous one by calling a function a series of instructions can be repeated at any point with in the program. IV.Thus by the used of functions the program become short which is easy to

write and debug. What is function I.A program in the c language consist of several functions. II.One such functions we have used is the main function this is in built function depending upon the user needs be can also define several function with different names. III.Every function has a name the name of function ends with a pair of parenthesis. IV.These parenthesis mayor may not- contain any thing whatever is inside the parenthesis is Known as the argument of a function. While defining function you must Know these thing. I.Function name. II.Function return type (if there is no return then used void) e.g. function retu type (void). III.Function argument (if there is no argument here also use void. ) Syntax to define a function return type function name (arguments) We can define the function in different categories I.No return no argument. II.No return with argument. III.Return without argument. IV.Return with argument. 1. Once a function is defined it can be called by any other function as many times as may be necessary. 2. Whenever a function is called the statement in the body of function are executed

in the sequence in which they are defined. 3. In the above program we are defining and calling the function in one program but we can define several functions in one program and call then in another program. ARRAYS Why we use arrays If we want to store large amount of data it is difficult to declare several variables independently and assign different values to them in separate statement. These difficulties can be overcome by using arrays. What is an array :_- An array is a group of elements that share a common name and that are differentiated from one another by their positions with in the array. How to declare an array :- Type of variable, variable name (size) i. ii. An array must be declared since it is a type of variable. An array containing five elements all of which are integers can be declared as follows :int x [5] iii. iv. v. vi. The name of the array cannt be same as that of any other variable declared within the function. The size of the array (the no. of elements) specified using the subscript notation. The subscript 5 indicates how many elements are to be allocated to array X.` The subscript used to declare an array are called dimension. The elements of five element array in C are numbered starting with 0 not with 1.

We will discuss single dimension array. e.g. suppose we want to store nos. 56,57,58,90,3 then the assignment statement for this should be as under X [0] =56 X [0] =57 X [0] =58 X [0] =90 *first no *second no *third no *fourth no

All elements of an array are of same type in other words if an array is declared to be of an int type cannt contain elements that are of int type.. DOUBLE DIMENSION ARRAY Problem :- User want to save the marks in 4 subjects of 10 students. How to solve it. Solution :1. 2. To solve this problem we require two dimensional array which is having 1 row to collect data of one student in separate locations. It can be declared as an array of arrays each element of five dimension array can be represented in the form of a table divided into several rows and columns for example int. a [5] [4] here 5 reprints no of rows and 4 represents column no element a [1] [3] belong to second row and fourth column Structure:1) A structure can be defined as a co lecher of variable of the same type or different types . 2) This group of variables is given a common name known as the name of the structure. 3) The individual variables in a structure are known as the name of the structure. Declaring the data in the form of a struchure has several advantages:-

1. The main advantage is that we can group together several related data items of same type. 2. The group of variables has a common name and common memory location. A structure declaration starts with the keyword struct. POINTERS 1.in c language the address of a variable can be obtained by using the address operator&. 2.the address can be assigned to another type of variable Known as pointer. 3. hence a pointer can be difined as a variable to which we can assign the address of another variable . 4. just as we declare int. float etc. type of data it is necessary to declare a pointer also. 5. a pointer of the int. type can be declared using the statement as int.*p * is used to indicate that p is a pointer type variable the pointer is also a variable hence computer Provides some space for the pointer in the memory.if we write the statement.P= &I the compiler assigns the address of I to the pointer p. DATA FILES: The fopen ( ) function. 1.before using a data file it is necessary to open that file it can be opened by using the fopen function. 2.the function take two arguments is a sting representing the mode in which the files is to be opened. The file can be opened in any of the following modes 1. The read mode. a) in this mode we can read the dta from the file when a file is opened in this

mode; b) it is not possible to write the data into the file. c) we us4e r as a parameter in fopen function 1.The write mode a)if a file in this mode is opened we can the data into the file it si snot possible to read the data from the file. b)If a file already exists is opened in the write modes the old contents of the file will be deleted and new data can be written in the file. c)We use string w in fopen ( ) function. 2.The append mode. a)if a file in this mode is opened we can add the data into the file at the end of the file. b)parameter used in fopen is a To open a file we have to use the structure file ( note that the use of uppercase letters). The structure is defined in the header file stdio.h so every program in which we use a data file should include this header file. To open the file we first declare a pointer to the structure file by using the statement such as file *fp; to open a file with the name ml we write *le fopen function as fp= fopen (ml,r); the file is opened in the read mode f close () function: the f close () function is used to close a file we will write here as f close(fp); The f puts ()function: the f puts function is used 9 0 write string into a file.

Source Code
#include<stdio.h> #include<conio.h> #include<io.h> struct student { long int roll; char name[50]; char address[50]; long int phone; }s1; int c=11; void box(int x1, int y1, int x2, int y2); void get_data(); void add(); void menu(); void search(); void show_data(); void report(); void modify(); void delete1(); FILE *stu; FILE *temp; void add() {

char ch='y'; stu=fopen("Lcollege.txt","a"); while(ch=='y' || ch=='Y') { get_data(); fwrite(&s1,sizeof(s1),1,stu); fclose(stu); gotoxy(22,20); cprintf("Enter More record : (y/n) "); scanf("%s",&ch); } if(ch=='n'||ch=='N') { gotoxy(10,21); printf("Press any key...."); menu(); } } void get_data() { clrscr(); box(10,2,67,23); gotoxy(20,2); printf("================================="); gotoxy(20,3); printf(" ::::: A D D R E C O R D :::: ");

gotoxy(20,4); printf("================================="); gotoxy(11,8); printf("Enter Roll No. scanf("%ld",&s1.roll); gotoxy(11,10); printf("Enter Student Name scanf("%s",&s1.name); gotoxy(11,12); printf("Enter Address gets(s1.address); strupr(s1.address); gotoxy(11,16); printf("Enter phone No. scanf("%ld",&s1.phone); getch(); } void report() { int c; clrscr(); stu=fopen("Lcollege.txt","r"); textcolor(CYAN); gotoxy(26,3); : "); : "); : "); : ");

cprintf("LIst of Students"); textcolor(BLUE); gotoxy(25,4); cprintf("========================="); textcolor(WHITE); gotoxy(1,8); printf("============================================= =================="); gotoxy(5,9);printf("Roll No."); gotoxy(10,9);printf("Student Name"); gotoxy(30,9);printf("Address"); gotoxy(50,9);printf("Phone_No."); gotoxy(1,10); printf("============================================= ===================="); c=11; while((fread(&s1,sizeof(s1),1,stu))==1) { gotoxy(5,c); printf("%ld",s1.roll); gotoxy(10,c); printf("%s",s1.name); gotoxy(30,c); printf("%s",s1.address); gotoxy(50,c); printf("%ld",s1.phone); c=c+2;

} fclose(stu); textcolor(LIGHTRED+BLINK); gotoxy(15,40); cprintf("Press any Key...."); textcolor(WHITE); getche(); } void show_data() { clrscr(); textcolor(CYAN); gotoxy(26,3); cprintf("LIst of Students"); textcolor(BLUE); gotoxy(25,4); cprintf("========================="); textcolor(WHITE); gotoxy(1,8); printf("============================================= =================="); gotoxy(5,9);printf("Roll No."); gotoxy(10,9);printf("Student Name"); gotoxy(30,9);printf("Address"); gotoxy(50,9);printf("Phone_No."); gotoxy(1,10);

printf("============================================= ===================="); gotoxy(5,c); printf("%ld",s1.roll); gotoxy(10,c); puts(s1.name); gotoxy(30,c); puts(s1.address); gotoxy(50,c); printf("%ld",s1.phone); } void search() { int i=0,idno; clrscr(); stu=fopen("Lcollege.txt","r"); printf("Enter the Roll No.= "); scanf("%d",&idno); //fread(&s1,sizeof(s1),1,stu) while((fread(&s1,sizeof(s1),1,stu))==1) { if(s1.roll==idno) { show_data(); c=c+2; i++;

} fclose(stu); gotoxy(20,35); textcolor(LIGHTRED+BLINK); cprintf("Press Enter to go to MAIN MENU...."); textcolor(WHITE); getche(); } } void modify() { int rec; char ans; clrscr(); stu=fopen("Lcollege.txt","r"); temp=fopen("tem.txt","a"); gotoxy(30,4); printf("FOR UPDATE RECORD"); gotoxy(23,5); printf("==========================") ; gotoxy(10,10); printf("Enter the Roll No........."); scanf("%d", &rec); //fread(&s1,sizeof(s1),1,stu) while((fread(&s1,sizeof(s1),1,stu))==1) {

if(s1.roll!=rec) { fwrite(&s1,sizeof(s1),1,stu); } else { show_data(); } fread(&s1,sizeof(s1),1,stu); break; } gotoxy(20,20); printf("Want to update the record(y/n)....."); gotoxy(55,20); scanf("%s", &ans); if(ans=='y'||ans=='Y') { clrscr(); get_data(); fwrite(&s1,sizeof(s1),1,temp); getch(); } else { if(ans=='n'||ans=='N') { //clrscr(); //file2.flush();

//file1.read((char *) &stu,sizeof(stu)); gotoxy(15,14); printf("Press any key to goto Main Menu....."); menu(); } } fclose(stu); fclose(temp); remove("Lcollege.txt"); rename("tem.txt","Lcollege.txt"); gotoxy(25,25); printf("Record has been updated....." ); getch(); } void delete1() { int rec; char ans; clrscr(); stu=fopen("Lcollege.txt","r"); temp=fopen("tem.txt","a"); gotoxy(30,4); printf("FOR UPDATE RECORD"); gotoxy(23,5); printf("==========================") ;

gotoxy(10,10); printf("Enter the Roll No........."); scanf("%d", &rec); //fread(&s1,sizeof(s1),1,stu) while((fread(&s1,sizeof(s1),1,stu))==1) { if(s1.roll!=rec) { fwrite(&s1,sizeof(s1),1,stu); } else { show_data(); } fread(&s1,sizeof(s1),1,stu); break; } gotoxy(20,20); printf("Want to update the record(y/n)....."); gotoxy(55,20); scanf("%s", &ans); if(ans=='n'||ans=='N') { //clrscr(); //file2.flush(); //file1.read((char *) &stu,sizeof(stu));

gotoxy(15,14); printf("Press any key to goto Main Menu....."); menu(); } fclose(stu); fclose(temp); remove("Lcollege.txt"); rename("tem.txt","Lcollege.txt"); gotoxy(25,25); printf("Record has been updated....." ); getch(); } void menu() { int ch; clrscr(); box(10,2,67,23); // gotoxy(15,3); //textbackground(CYAN); //textcolor(BLACK+BLINK); //cprintf(" gotoxy(22,5); textbackground(BLACK); textcolor(YELLOW); ::::: ::::: ");

cprintf("========================================"); gotoxy(22,6); textbackground(BLACK); textcolor(GREEN); cprintf(" ::::: M A I N MENU :::::" ); gotoxy(22,7); textcolor(YELLOW); cprintf("========================================"); gotoxy(27,10); printf("press: 1. ADD RECORDS"); gotoxy(27,12); printf("press: 2. MODIFY RECORDS"); gotoxy(27,14); printf("press: 3. DELETE RECORDS"); gotoxy(27,16); printf("press: 4. SEARCH RECORDS"); gotoxy(27,18); printf("press: 5. REPORT"); gotoxy(58,3); printf("<0>= EXIT"); gotoxy(22,24); printf("ENTER YOUR CHOICE............"); scanf("%d",&ch); do { switch(ch) {

case 1: add(); menu(); break; case 2: modify(); menu(); break; case 3: delete1(); menu(); break; case 4: search(); menu(); break; case 5: report(); menu(); break; case 0: clrscr();

gotoxy(25,20); textcolor(LIGHTCYAN); cprintf("Thanks to Visit............."); getch(); exit(2); } }while(ch!=0); } void box(int x1, int y1, int x2, int y2) { int col,row; for(col=x1;col<x2;col++) { gotoxy(col,y1); cprintf("%c",'*'); gotoxy(col,y2); textcolor(LIGHTGRAY); cprintf("%c",'*'); } for(row=y1;row<y2;row++) { gotoxy(x1,row); cprintf("%c",'|'); gotoxy(x2,row); cprintf("%c",'|');

} gotoxy(x1,y1); cprintf("%c",218); gotoxy(x1,y2); cprintf("%c",192); gotoxy(x2,y1); cprintf("%c",191); gotoxy(x2,y2); cprintf("%c",217); } void main() { menu() }

You might also like