Calculator
Calculator
1. Introduction
2. Objective
3. Hardware requirements
4. Software requirements
5. flowchart
7. Pseudocode
8. Technology used
10. output
11. conclusion
12 references
INTRODUCTION
The first step was seen in 1961 with the arrival of ANITA (A New
Inspiration To Arithmetic/Accounting). This was the world's first all-
electronic desktop calculator and it was developed in Britain by
Control Systems Ltd., marketed under its Bell Punch and Sumlock
brands.
The above advantages help students to avoid boredom, and it does not
demoralize their mathematical understanding. If mathematics is not made
entertaining, pupils can feel bored, and it can demoralize their mathematical
understanding.
Thirdly, when teachers realize that the mathematical capacity of some of their
pupils are not so great, using this handheld device or the online calculator
platforms, helps them manage addition, subtraction, multiplication and
division problems in an efficient manner. Teachers understand that the student
would not have learned mathematical table of 20x, or would be well versed in
solving the problem without the help of a mathematical device or paper. They
would make fewer mistakes and will be more comfortable in solving tough
problems. If a student is confident about his or her ability, then the problem
seems halfway solved.
Most handheld or online calculators are relatively cheap, various designs and
functionality suitable for various budgets. They are also inexpensive to
maintain once handled with care.
As a professional, in any field, the Calculator save time, energy and increases
efficiency in workplace.
. Disadvantages of Calculator
The Calculator is available in variety of brands, and each brand and model requires a
specific set of instructions. It is a proven fact that many of us do not bother to read these
manual, and it gets lost. Although the instructions are quite simple, there are chances that
students might make mistake. A small mistake is sufficient to lead to the wrong answer. A
student must have the ability of estimating the correct answers or the student would not
cross check the problem. It is in the best interest of students to repeat all the mathematical
calculation once. Alternatively, if there is difference in answers between the first and
second calculation, the student must repeat the operations again.
Cheating:The availability of graphic calculators has made it easier for students to cheat
during their tests. Besides letting you perform basic mathematical operations, these
calculators allow you to store information like notes, formulas etc. This gives students an
opportunity to store unauthorized information to cheat on the test. This is one of the
major disadvantages of a calculator.
High cost:While the cost of a simple calculator is not that high, calculators like the
graphing calculator is of high cost. In addition to that, these calculators need batteries to
operate which is again a recurring cost. However, you have the option to use online
calculators for the purpose which gives you access to all the functionality of a physical
calculator.
Lastly, some research have it that if the use of this handheld device is not stopped in the
near future, we might lack quality scientists with great computational skills in the near
future. There must be rules and guidelines framed by the top educational institutions to
make sure that the students are not deprived of their own skills.
Objectives
OBJECTIVE: We will learn how to apply the concepts learned in this course to develop a simple
command-line calculator using programming language C.
[1] 1+5=6
[2] 4-2=2
[3] 5*6=30
[4] 10/2=5
[5] square of 9=81
FLOWCHART
SOFTWARE REQUIRED :
HARDWARE REQUIRED :
RAM 2 GB 3 GB OR More
Processor Intel i3 10th gen, AMD Intel i5 10th gen, i5 11th gen,
Ryzen 3…… i7, AMD Ryzen 5, Ryzen
7…..
C programming language
C programming is considered as the base for other programming languages, that is why it is
known as mother language.
1. Mother language
2. System programming language
3. Procedure-oriented programming language
4. Structured programming language
5. Mid-level programming language
1) C as a mother language
C language is considered as the mother language of all the modern programming languages
because most of the compilers, JVMs, Kernels, etc. are written in C language, and most of
the programming languages follow C syntax, for example, C++, Java, C#, etc.
It provides the core concepts like the array, strings, functions, file handling, etc. that are being
used in many languages like C++, Java, C#, etc.
It can't be used for internet programming like Java, .Net, PHP, etc.
3) C as a procedural language
A procedural language breaks the program into functions, data structures, etc.
In the C language, we break the program into parts using functions. It makes the program
easier to understand and modify.
A High-Level language is not specific to one machine, i.e., machine independent. It is easy to
understand.
C Program
In this tutorial, all C programs are given with C compiler so that you can quickly change the C
program code
1. #include <stdio.h>
2. int main() {
3. printf("Hello C Programming\n");
4.return 0;
5. }
Features of C programming language
1. Procedural Language
2. Fast and Efficient
3. Modularity
4. Statically Type
5. General-Purpose Language
6. Rich set of built-in Operators
7. Libraries with rich Functions
8. Middle-Level Language
9. Portability
10. Easy to Extend
Let us see the features one by one:
Procedural Language:
In a procedural language like C step by step predefined instructions are carried out. C
program may contain more than one function to perform a particular task. New people
to programming will think that this is the only way a particular programming language
works. There are other programming paradigms as well in the programming world.
Most of the commonly used paradigm is an object-oriented programming language.
Newer languages like java, python offer more features than c programming language
but due to additional processing in these languages, their performance rate gets down
effectively. C programming language as the been middle-level language provides
programmers access to direct manipulation with the computer hardware but higher-
level languages do not allow this. That’s one of the reasons C language is considered
the first choice to start learning programming languages. It’s fast because statically
typed languages are faster than dynamically typed languages.
Modularity:
The concept of storing C programming language code in the form of libraries for
further future uses is known as modularity. This programming language van does very
little on its own most of its power is held by its libraries. C language has its own
library to solve common problems like in this we can use a particular function by
using a header file stored in its library.
Statically Type:
Operating systems:
It is a diversified language with a rich set of built-in operators which are used in
writing complex or simplified C programs.
Robust libraries and functions in C help even a beginner coder to code with ease.
Middle-Level Language:
Portability:
C language is lavishly portable as programs that are written in C language can run and
compile on any system with either none or small changes.
Easy to Extend:
Before starting the abcd of C language, you need to learn how to write, compile and run the
first c program.
To write the first c program, open the C console and write the following code
#include<stdio.h>
Int main()
printf(“Hello to c language”);
return 0;}
#include<stdio.h> includes the standard input output library functions. The printf() function
is defined in stdio.h .
int main() The main() function is the entry point of every program in c language
return 0 The return 0 statement, returns execution status to the OS. The 0 value is used for
successful execution and 1 for unsuccessful execution.
There are 2 ways to compile and run the c program, by menu and by shortcut.
By menu
Now click on the compile menu then compile sub menu to compile the c program.
Then click on the run menu then run sub menu to run the c program.
By shortcut
Or, press ctrl+f9 keys compile and run the program directly.
Compilation process in c
What is a compilation?
The compilation is a process of converting the source code into object code. It is done with
the help of the compiler. The compiler checks the source code for the syntactical or structural
errors, and if the source code is error-free, then it generates the object code.
The c compilation process converts the source code taken as input into the object code or
machine code. The compilation process can be divided into four steps, i.e., Pre-processing,
Compiling, Assembling, and Linking.
The preprocessor takes the source code as an input, and it removes all the comments from the
source code. The preprocessor takes the preprocessor directive and interprets it. For example,
if <stdio.h>, the directive is available in the program, then the preprocessor interprets the
directive and replace this directive with the content of the 'stdio.h' file.
The following are the phases through which our program passes before being transformed
into an executable form.
o Preprocessor
o Compiler
o Assembler
o Linker
Preprocessor
The source code is the code which is written in a text editor and the source code file is given
an extension ".c". This source code is first passed to the preprocessor, and then the
preprocessor expands this code. After expanding the code, the expanded code is passed to the
compiler.
Compiler
The code which is expanded by the preprocessor is passed to the compiler. The compiler
converts this code into assembly code. Or we can say that the C compiler converts the pre-
processed code into assembly code.
Assembler
The assembly code is converted into object code by using an assembler. The name of the
object file generated by the assembler is the same as the source file. The extension of the
object file in DOS is '.obj,' and in UNIX, the extension is 'o'. If the name of the source file is
'hello.c', then the name of the object file would be 'hello.obj'.
Linker
Mainly, all the programs written in C use library functions. These library functions are pre-
compiled, and the object code of these library files is stored with '.lib' (or '.a') extension. The
main working of the linker is to combine the object code of library files with the object code of
our program. Sometimes the situation arises when our program refers to the functions defined
in other files; then linker plays a very important role in this. It links the object code of these
files to our program. Therefore, we conclude that the job of the linker is to link the object code
of our program with the object code of the library files and other files. The output of the linker
is the executable file. The name of the executable file is the same as the source file but differs
only in their extensions. In DOS, the extension of the executable file is '.exe', and in UNIX, the
executable file can be named as 'a.out'. For example, if we are using printf() function in a
program, then the linker adds its associated code in an output file.
Int main()
C has a formal grammar specified by the C standard.[26] Line endings are generally not
significant in C; however, line boundaries do have significance during the preprocessing phase.
Comments may appear either between the delimiters /* and */, or (since C99) following //
until the end of the line. Comments delimited by /* and */ do not nest, and these sequences of
characters are not interpreted as comment delimiters if they appear inside string or character
literals.[27]
C source files contain declarations and function definitions. Function definitions, in turn,
contain declarations and statements. Declarations either define new types using keywords such
as struct, union, and enum, or assign types to and perhaps reserve storage for new variables,
usually by writing the type followed by the variable name. Keywords such as char and int
specify built-in types. Sections of code are enclosed in braces ({ and }, sometimes called
"curly brackets") to limit the scope of declarations and to act as a single statement for control
structures.
As an imperative language, C uses statements to specify actions. The most common statement
is an expression statement, consisting of an expression to be evaluated, followed by a
semicolon; as a side effect of the evaluation, functions may be called and variables may be
assigned new values. To modify the normal sequential execution of statements, C provides
several control-flow statements identified by reserved keywords. Structured programming is
supported by if ... [else] conditional execution and by do ... while, while, and for iterative
execution (looping). The for statement has separate initialization, testing, and reinitialization
expressions, any or all of which can be omitted. break and continue can be used to leave the
innermost enclosing loop statement or skip to its reinitialization. There is also a non-structured
goto statement which branches directly to the designated label within the function. switch
selects a case to be executed based on the value of an integer expression.
Expressions can use a variety of built-in operators and may contain function calls. The order in
which arguments to functions and operands to most operators are evaluated is unspecified.
The evaluations may even be interleaved. However, all side effects (including storage to
variables) will occur before the next "sequence point"; sequence points include the end of
each expression statement, and the entry to and return from each function call. Sequence
points also of
evaluation occur during containing certain operators (&&, ?: and the comma operator).
expressions
||, This
permits a high degree of object code optimization by the compiler, but requires C programmers
to take more care to obtain reliable results than is needed for other programming languages.
Kernighan and Ritchie say in the Introduction of The C Programming Language: "C, like any
other language, has its blemishes. Some of the operators have the wrong precedence; some
parts of the syntax could be better."[28] The C standard did not attempt to correct many of these
blemishes, because of the impact of such changes on already existing software.
CHARACTER SET:
● Lowercase and uppercase letters of ISO Basic Latin Alphabet: a–z A–Z
● Decimal digits: 0–9
● Graphic characters: ! " # % & ' ( ) * + , - . / : ; < = > ? [ \ ] ^ _ { | } ~
● Whitespace characters: space, horizontal tab, vertical tab, form feed, newline
Newline indicates the end of a text line; it need not correspond to an actual single character,
although for convenience C treats it as one.
Additional multi-byte encoded characters may be used in string literals, but they are not
entirely portable. The latest C standard (C11) allows multi-national Unicode characters to be
embedded
portably within C source text by using encoding (where theX denotes a hexadecimal
character), although this feature is not yet widely implemented.
The basic C execution character set contains the same characters, along with representations
for alert, backspace, and carriage return. Run-time support for extended character sets has
increased with each revision of the C standard.
KEYWORDS:
C89 has 32 reserved words, also known as keywords, which are the words that cannot be used
for any purposes other than those for which they are predefined:
● auto
● break
● case
● char
● const
● continue
● default
● do
● double
● else
● enum
● extern
● float
● for
● goto
● if
● int
● long
● register
● return
● short
● signed
● sizeof
● static
● struct
● switch
● typedef
● union
● unsigned
● void
● volatile
● while
● _Bool
● _Complex
● _Imaginary
● inline
● restrict
● _Alignas
● _Alignof
● _Atomic
● _Generic
● _Noreturn
● _Static_assert
● _Thread_local
Most of the recently reserved words begin with an underscore followed by a capital letter,
because identifiers of that form were previously reserved by the C standard for use only by
implementations. Since existing program source code should not have been using these
identifiers, it would not be affected when C implementations started supporting these
extensions to the programming language. Some standard headers do define more convenient
synonyms for underscored identifiers. The language previously included a reserved word
called entry, but this was seldom implemented, and has now been removed as a reserved
word.
OPERATORS:
C supports a rich set of operators, which are symbols used within an expression to specify the
manipulations to be performed while evaluating that expression. C has operators for:
● arithmetic: +, -, *, /, %
● assignment: =
● augmented assignment: +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=
● bitwise logic: ~, &, |, ^
● bitwise shifts: <<, >>
● boolean logic: !, &&, ||
● conditional evaluation: ? :
● equality testing: ==, !=
● calling functions: ( )
● increment and decrement: ++, --
● member selection: ., ->
● object size: sizeof
● order relations: <, <=, >, >=
● reference and dereference: &, *, [ ]
● sequencing: ,
● subexpression grouping: ( )
● type conversion: (typename)
The C operator precedence is not always intuitive. For example, the operator == binds more
tightly than (is executed prior to) the operators & (bitwise AND) and | (bitwise OR)
in
expressions such as x & 1 == 0, which must be written as (x & 1) == 0 if that is the coder's
intent.
DATA TYPES:
The type system in C is static and weakly typed, which makes it similar to the type system of
ALGOL descendants such as Pascal.[35] There are built-in types for integers of various sizes,
both signed and unsigned, floating-point numbers, and enumerated types (enum). Integer type
char is often used for single-byte characters. C99 added a boolean datatype. There are also
derived types including arrays, pointers, records (struct), and unions (union).
C is often used in low-level systems programming where escapes from the type system may be
necessary. The compiler attempts to ensure type correctness of most expressions, but the
programmer can override the checks in various ways, either by using a type cast to explicitly
convert a value from one type to another, or by using pointers or unions to reinterpret the
underlying bits of a data object in some other way.
Some find C's declaration syntax unintuitive, particularly for function pointers. (Ritchie's idea
was to declare identifiers in contexts resembling their use: "declaration reflects use".)[36]
C's usual arithmetic conversions allow for efficient code to be generated, but can sometimes
produce unexpected results. For example, a comparison of signed and unsigned integers of
equal width requires a conversion of the signed value to unsigned. This can generate
unexpected results if the signed value is negative.
POINTERS:
C supports the use of pointers, a type of reference that records the address or location of an
object or function in memory. Pointers can be dereferenced to access data stored at the address
pointed to, or to invoke a pointed-to function. Pointers can be manipulated using assignment or
pointer arithmetic. The run-time representation of a pointer value is typically a raw memory
address (perhaps augmented by an offset-within-word field), but since a pointer's type includes
the type of the thing pointed to, expressions including pointers can be type-checked at compile
time. Pointer arithmetic is automatically scaled by the size of the pointed-to data type.
Pointers are used for many purposes in C. Text strings are commonly manipulated using
pointers into arrays of characters. Dynamic memory allocation is performed using pointers; the
result of a malloc is usually cast to the data type of the data to be stored. Many data types,
such
as trees, are commonly implemented as dynamically allocated struct objects linked together
using pointers. Pointers to other pointers are often used in multi-dimensional arrays and arrays
of struct objects. Pointers to functions (function pointers) are useful for passing functions as
arguments to higher-order functions (such as qsort or bsearch), in dispatch tables, or as
callbacks to event handlers .
A null pointer value explicitly points to no valid location. Dereferencing a null pointer value is
undefined, often resulting in a segmentation fault. Null pointer values are useful for indicating
special cases such as no "next" pointer in the final node of a linked list, or as an error
indication from functions returning pointers. In appropriate contexts in source code, such as
for assigning to a pointer variable, a null pointer constant can be written as 0, with or without
explicit
to casting
a pointer type, or as the NULL macro defined by several standard headers. In conditional
contexts, null pointer values evaluate to false, while all other pointer values evaluate to true.
Void pointers (void *) point to objects of unspecified type, and can therefore be used as
"generic" data pointers. Since the size and type of the pointed-to object is not known, void
pointers cannot be dereferenced, nor is pointer arithmetic on them allowed, although they can
easily be (and in many contexts implicitly are) converted to and from any other object pointer
type.
Careless use of pointers is potentially dangerous. Because they are typically unchecked, a
pointer variable can be made to point to any arbitrary location, which can cause undesirable
effects. Although properly used pointers point to safe places, they can be made to point to
unsafe place, by using invalid pointer arithmetic; the objects they point to may continue to be
used after deallocation (dangling pointers); they may be used without having been initialized
(wild pointers); or they may be directly assigned an unsafe value using a cast, union, or
through another corrupt pointer. In general, C is permissive in allowing manipulation of and
conversion between pointer types, although compilers typically provide options for various
levels of checking. Some other programming languages address these problems by using more
restrictive reference types.
ARRAY:
Array types in C are traditionally of a fixed, static size specified at compile time. The more
recent C99 standard also allows a form of variable-length arrays. However, it is also possible
to allocate a block of memory (of arbitrary size) at run-time, using the standard malloc
library's function, and treat it as an array.
Since arrays are always accessed (in effect) via pointers, array accesses are typically not
checked against the underlying array size, although some compilers may provide bounds
checking as an option. Array bounds violations are therefore possible and can lead to various
repercussions, including illegal memory accesses, corruption of data, buffer overruns, and run-
time exceptions.
C does not have a special provision for declaring multi-dimensional arrays, but rather relies on
recursion within the type system to declare arrays of arrays, which effectively accomplishes
the same thing. The index values of the resulting "multi-dimensional array" can be thought of
as increasing in row-major order. Multi-dimensional arrays are commonly used in numerical
algorithms (mainly from applied linear algebra) to store matrices. The structure of the C array
is well suited to this particular task. However, in early versions of C the bounds of the array
must be known fixed values or else explicitly passed to any subroutine that requires them, and
dynamically sized arrays of arrays cannot be accessed using double indexing. (A workaround
for this was to allocate the array with an additional "row vector" of pointers to the columns.)
C99 introduced "variable-length arrays" which address this issue.
MEMORY MANAGEMENT:
One of the most important functions of a programming language is to provide facilities for
managing memory and the objects that are stored in memory. C provides three principal ways
to allocate memory for objects:
● Static memory allocation: space for the object is provided in the binary at compile-
time; these objects have an extent (or lifetime) as long as the binary which contains
them is loaded into memory.
● Automatic memory allocation: temporary objects can be stored on the stack, and
this space is automatically freed and reusable after the block in which they are
declared is exited.
● Dynamic memory allocation: blocks of memory of arbitrary size can be requested
at run-time using library functions such as malloc from a region of memory called
the heap; these blocks persist until subsequently freed for reuse by calling the
library
function realloc or free
These three approaches are appropriate in different situations and have various trade-offs. For
example, static memory allocation has little allocation overhead, automatic allocation may
involve slightly more overhead, and dynamic memory allocation can potentially have a great
deal of overhead for both allocation and deallocation. The persistent nature of static objects is
useful for maintaining state information across function calls, automatic allocation is easy to
use but stack space is typically much more limited and transient than either static memory or
heap space, and dynamic memory allocation allows convenient allocation of objects whose
size is known only at run-time. Most C programs make extensive use of all three.
Where possible, automatic or static allocation is usually simplest because the storage is
managed by the compiler, freeing the programmer of the potentially error-prone chore of
manually allocating and releasing storage. However, many data structures can change in size at
runtime, and since static allocations (and automatic allocations before C99) must have a fixed
size at compile-time, there are many situations in which dynamic allocation is necessary. Prior
to the C99 standard, variable-sized arrays were a common example of this. (See the article on
malloc for an example of dynamically allocated arrays.) Unlike automatic allocation, which
can
fail at run time with uncontrolled consequences, the dynamic allocation functions return an
indication (in the form of a null pointer value) when the required storage cannot be allocated.
(Static allocation that is too large is usually detected by the linker or loader, before the program
can even begin execution.)
Unless otherwise specified, static objects contain zero or null pointer values upon program
startup. Automatically and dynamically allocated objects are initialized only if an initial value
is explicitly specified; otherwise they initially have indeterminate values (typically, whatever
bit pattern happens to be present in the storage, which might not even represent a valid value
for that type). If the program attempts to access an uninitialized value, the results are
undefined. Many modern compilers try to detect and warn about this problem, but both false
positives and false negatives can occur.
LIBRARIES:
The C programming language uses libraries as its primary method of extension. In C, a library
is a set of functions contained within a single "archive" file. Each library typically has a header
file, which contains the prototypes of the functions contained within the library that may be
used by a program, and declarations of special data types and macro symbols used with these
functions. In order for a program to use a library, it must include the library's header file, and
the library must be linked with the program, which in many cases requires compiler flags (e.g.,
-lm, shorthand for "link the math library").
The most common C library is the C standard library, which is specified by the ISO and ANSI
C standards and comes with every C implementation (implementations which target limited
environments such as embedded systems may provide only a subset of the standard library).
This library supports stream input and output, memory allocation, mathematics, character
strings, and time values. Several separate standard headers (for example, stdio.h) specify the
interfaces for these and other standard library facilities.
Another common set of C library functions are those used by applications specifically targeted
for Unix and Unix-like systems, especially functions which provide an interface to the kernel.
These functions are detailed in various standards such as POSIX and the Single UNIX
Specification.
Since many programs have been written in C, there are a wide variety of other libraries
available. Libraries are often written in C because C compilers generate efficient object code;
programmers then create interfaces to the library so that the routines can be used from higher-
level languages like Java, Perl, and Python.[34]
SOME LIBRARY FILES IN C:
FILE HANDLING IN C:
So far the operations using C program are done on a prompt / terminal which is not stored
anywhere. But in the software industry, most of the programs are written to store the
information fetched from the program. One such way is to store the fetched information in a
file. Different operations that can be performed on a file are:
1. Creation of a new file (fopen with attributes as “a” or “a+” or “w” or “w+”)
2. Opening an existing file (fopen)
3. Reading from file (fscanf or fgets)
4. Writing to a file (fprintf or fputs)
5. Moving to a specific location in a file (fseek, rewind)
6. Closing a file (fclose)
The text in the brackets denotes the functions used for performing those operations.
Functions in File Operations:
For opening a file, the fopen function is used with the required access modes. Some of the
commonly used file access modes are mentioned below.
● “r” – Searches file. If the file is opened successfully, fopen( ) loads it into memory
and sets up a pointer which points to the first character in it. If the file cannot be
opened, fopen( ) returns NULL.
● “rb” – Open for reading in binary mode. If the file does not exist, fopen( ) returns
NULL.
● “w” – Searches file. If the file exists, its contents are overwritten. If the file
doesn’t exist, a new file is created. Returns NULL, if unable to open the file.
● “wb” – Open for writing in binary mode. If the file exists, its contents are
overwritten. If the file does not exist, it will be created.
● “a” – Searches file. If the file is opened successfully, fopen( ) loads it into
memory and sets up a pointer that points to the last character in it. If the file
doesn’t exist, a new file is created. Returns NULL, if unable to open the file.
● “ab” – Open for append in binary mode. Data is added to the end of the file. If the
file does not exist, it will be created.
● “r+” – Searches file. If it is opened successfully, fopen( ) loads it into memory and
sets up a pointer which points to the first character in it. Returns NULL, if unable
to open the file.
● “rb+” – Open for both reading and writing in binary mode. If the file does not
exist, fopen( ) returns NULL.
● “w+” – Searches file. If the file exists, its contents are overwritten. If the file
doesn’t exist a new file is created. Returns NULL, if unable to open the file.
● “wb+” – Open for both reading and writing in binary mode. If the file exists, its
contents are overwritten. If the file does not exist, it will be created.
● “a+” – Searches file. If the file is opened successfully fopen( ) loads it into
memory and sets up a pointer which points to the last character in it. If the file
doesn’t exist, a new file is created. Returns NULL, if unable to open file.
● “ab+” – Open for both reading and appending in binary mode. If the file does not
exist, it will be created.
As given above, if you want to perform operations on a binary file, then you have to append
‘b’ at the end. For example, instead of “w”, you have to use “wb”, instead of “a+” you have to
use “a+b”. For performing the operations on the file, a special pointer called File pointer is
used which is declared as
FILE *filePointer;
The second parameter can be changed to contain all the attributes listed in the above table.
FILE * filePointer;
FILE *filePointer ;
Closing a file –:
After every successful file operations, you must always close a file. For closing a file, you
have to use fclose function. The snippet for closing a file is given as :
FILE *filePointer ;
fclose(filePointer)
FUNCTIONS OF FILE HANDLING:
used to set the file pointer to the intended file position fseek()
Structure in c is a user-defined data type that enables us to store the collection of different data
types. Each element of a structure is called a member. Structures ca; simulate the use of classes
and templates as it can store various information
Structures (also called structs) are a way to group several related variables into one place. Each
variable in the structure is known as a member of the structure.
Unlike an array, a structure can contain many different data types (int, float, char, etc.).
You can create a structure by using the struct keyword and declare each of its members inside
curly braces:
struct Person {
// code
};
int main() {
struct Person person1, person2, p[20];
return 0;
struct Person {
// code
In both cases,
We can declare a variable for the structure so that we can access the member of the structure
easily. There are two ways to declare structure variable:
3) The case value can be used only inside the switch statement.
4)The break statement in the switch case is not necessary. It is optional. If there is no break
statement found in the case, all the cases will be executed present after the matched case. It is
known as fall through the state of C switch statement.
First, the integer expression specified in the switch statement is evaluated. This value is then
matched one by one with the constant values given in the different cases. If a match is found,
then all the statements specified in that case are executed along with the all the cases present
after that case including the default statement. No two cases can have similar values. If the
matched case contains a break statement, then all the cases present after that will be skipped,
and the control comes out of the switch. Otherwise, all the cases following the matched case
will be executed.
Switch flow chart
Technology used
include<stdio.h>
Is a header file which has necessary information to include the input related
function in our program . Example printf ,scanf, etc. if we want to use printf or scanf function in
our program , we should include the stdio.h header file in our source code.
#include<conio.h>
It is used to include the console input output library function. The qetch()
function is defined in conio.
#include<math.h> - is a header file in the standard library of the C
programming language designed for basic mathematical operations. Most of the functions
involve the use of floating point numbers. C++ also implements these functions for
compatibility reasons and declares them in the header.
Printf()- printf is a formatting function that is used to print a string to stdout. The
basic idea to call in C++ is to provide a string of characters that need to be
printed as it is in the program. The printf in C++ also contains a format specifier that
is replaced by the actual value during execution.
Char-Char- is the most basic data type in C. It stores a single character and requires
a single byte of memory in almost all compilers
. ❖ Int-The int type in C is a signed integer, which means it can represent both negative and
positive numbers. This is in contrast to an unsigned integer (which can be used by declaring a
variable unsigned int), which can only represent positive numbers
❖Int x[][]-It is used to store array. An arrays are used to store multiple values in a single
variable, instead of declaring separate variables for each value. 40.
❖\n-The newline character ( \n ) is called an escape sequence, and it forces the cursor to
change its position to the beginning of the next line on the screen. This results in a new line.
❖\t- \t refers to one tab horizontal space. Both \n and \t fall under category Escape
sequences in C , and are used for formatting output of the program.
❖Scanf-In C programming language, scanf is a function that stands for Scan Formatted
String. It reads data from stdin (standard input stream i.e. usually keyboard) and then writes
the result into the given arguments. It accepts character, string, and numeric data from the
user using standard input.
❖%d-%d tells printf that the corresponding argument is to be treated as an integer value;
the type of the corresponding argument must be int .
❖%s-The %s means, "insert the first argument, a string, right here." The %d indicates that
the second argument (an integer) should be placed there. There are different %- codes for
different variable types, as well as options to limit the length of the variables and whatnot.
Control Character. 41
❖Case-A case or switch statement is a type of selection control mechanism used to allow
the value of a variable or expression to change the control flow of program execution via a
multiway branch.
❖Break-The break command allows you to terminate and exit a loop (that is, do , for , and
while ) or switch command from any point other than the logical end. You can place a break
command only in the body of a looping command or in the body of a switch command.
❖For-The for statement lets you repeat a statement or compound statement a specified
number of times. The body of a for statement is executed zero or more times until an optional
condition becomes false.
❖&-The & is a unary operator in C which returns the memory address of the passed
operand.
❖Return-A return statement ends the execution of a function, and returns control to the calling
function. Execution resumes in the calling function at the point immediately following the call. A
return statement can return a value to the calling function
FUNCTIONS:
A function is a block of code which only runs when it is called. You can pass data, known as
parameters, into a function. Functions are used to perform certain actions, and they are
important for reusing code: Define the code once, and use it many times.
A function is a group of statements that together perform a task. Every C program has at least
one function, which is main(), and all the most trivial programs can define additional
functions.
You can divide up your code into separate functions. How you divide up your code among
different functions is up to you, but logically the division is such that each function performs a
specific task.
A function declaration tells the compiler about a function's name, return type, and parameters.
A function definition provides the actual body of the function.
The C standard library provides numerous built-in functions that your program can call. For
example, strcat() to concatenate two strings, memcpy() to copy one memory location to
another location, and many more functions.
● Return Type − A function may return a value. The return_type is the data type
of the value the function returns. Some functions perform the desired operations
without returning a value. In this case, the return_type is the keyword void.
● Function Name − This is the actual name of the function. The function name
and the parameter list together constitute the function signature.
● Parameters − A parameter is like a placeholder. When a function is invoked,
you
pass a value to the parameter. This value is referred to as an actual parameter or
argument. The parameter list refers to the type, order, and number of the
● parameters of a function. Parameters are optional; that is, a function may
contain no parameters.
● Function Body − The function body contains a collection of statements that
define what the function does.
So it turns out you already know what a function is. You have been using it the whole time
while studying this tutorial!
For example, main() is a function, which is used to execute code, and printf() is a function;
used to output/print text to the screen:
int main() {
printf("Hello World!");
return 0;
To create (often referred to as declare) your own function, specify the name of the function,
followed by parentheses () and curly brackets {}:
void myFunction() {
// code to be executed
● void means that the function does not have a return value. You will learn more about
return values later in the next chapter
● Inside the function (the body), add code that defines what the function should do
Call a Function:
While creating a C function, you give a definition of what the function has to do. To use a
function, you will have to call that function to perform the defined task.
When a program calls a function, the program control is transferred to the called function. A
called function performs a defined task and when its return statement is executed or when its
function-ending closing brace is reached, it returns the program control back to the main
program.
If a function is to use arguments, it must declare variables that accept the values of the
arguments. These variables are called the formal parameters of the function.
Formal parameters behave like other local variables inside the function and are created upon
entry into the function and destroyed upon exit.
While calling a function, there are two ways in which arguments can be passed to a function −
Declared functions are not executed immediately. They are "saved for later use", and will be
executed when they are called.
To call a function, write the function's name followed by two parentheses () and a semicolon ;
Sr.No Call Type & Description
.
1 Call by value
This method copies the actual value of an argument into the formal parameter of the
function. In this case, changes made to the parameter inside the function have no
effect on the argument.
2 Call by reference
This method copies the address of an argument into the formal parameter. Inside the
function, the address is used to access the actual argument used in the call. This means
that changes made to the parameter affect the argument.
Function declaration is required when you define a function in one source file and you call that
function in another file. In such a case, you should declare the function at the top of the file
calling the function.
A function declaration tells the compiler about a function name and how to call the function.
The actual body of the function can be defined separately.
By default, C uses call by value to pass arguments. In general, it means the code within a
function cannot alter the arguments used to call the function.
In the following example, myFunction() is used to print a text (the action), when it is called:
void myFunction() {
printf("I just got executed!");
int main() {
return 0;
}
C Programming Software
Before you start writing in C, you will need some C programming software. Let's see exactly
what you need!
Before you can write a program, you need an editor and a compiler.
Code editor
The editor is a program where you write the source code of your program. You want to use a
smart editor that helps with coding. Such editors will use different colors for keywords, values
and variables. It is also desired that it will help with code suggestions.
There are hundreds of free editor programs. Before you go to download any of them, keep
reading.
Compiler:-
A compiler is a program that translates the source code from programming language to a
machine language. There are several good C compilers out there and we will talk about them
a little later.
A compiler is a special program that translates a programming language's source code into
machine code, bytecode or another programming language. The source code is typically
written in a high-level, human-readable language such as Java or C++. A programmer writes
the source code in a code editor or an integrated development environment (IDE) that
includes an editor, saving the source code to one or more text files. A compiler that supports
the source programming language reads the files, analyzes the code, and translates it into a
format suitable for the target platform.
Compilers that translate source code to machine code target specific operating systems and
computer architectures. This type of output is sometimes referred to as object code (which is
not related to object-oriented programming). The outputted machine code is made up entirely
of binary bits -- 1s and 0s -- so it can be read and executed by the processors on the target
computers. For example, a compiler might output machine code for the Linux x64 platform or
Linux ARM 64-bit platform.
Some compilers can translate source code to bytecode instead machine code. Bytecode, which
was first introduced in the Java programming language, is an intermediate language that can
be executed on any system platform running a Java virtual machine (JVM) or bytecode
interpreter. The JVM or interpreter converts the bytecode into instructions that can be
executed by the hardware processor. A JVM also makes it possible for the bytecode to be
recompiled by a just-in-time compiler. (See also: Java compiler)
Some compilers can translate source code into another high-level programming language,
rather than machine code or bytecode. This type of compiler might be referred to as a
transpiler, transcompiler, source-to-source translator or it might go by another name. For
example, a developer might use a transpiler to convert COBOL to Java.
Regardless of the source language or the type of output, a compiler must ensure that the logic
of the output code always matches that of the input code and that nothing is lost when
converting the code. A compiler is, in the strictest sense, a translator and must ensure that the
output is correct and preserves all the original logic.
Compilers vary in the methods they use for analyzing and converting source code to output
code. Despite their differences, they typically carry out the following steps:
Lexical analysis. The compiler splits the source code into lexemes, which are
individual code fragments that represent specific patterns in the code. The lexemes
are then tokenized in preparation for syntax and semantic analyses.
Syntax analysis. The compiler verifies that the code's syntax is correct, based on
the rules for the source language. This process is also referred to as parsing.
During this step, the compiler typically creates abstract syntax trees that represent
the logical structures of specific code elements.
Semantic analysis. The compiler verifies the validity of the code's logic. This step
goes beyond syntax analysis by validating the code's accuracy. For example, the
semantic analysis might check whether variables have been assigned the right
types or have been properly declared.
IR code generation. After the code passes through all three analysis phases, the
compiler generates an intermediate representation (IR) of the source code. The IR
code makes it easier to translate the source code into a different format. However,
it must accurately represent the source code in every respect, without omitting any
functionality.
Optimization. The compiler optimizes the IR code in preparation for the final
code generation. The type and extent of optimization depends on the compiler.
Some compilers let users configure the degree of optimization.
Output code generation. The compiler generates the final output code, using the
optimized IR co
IDE
There are programs that contain in one place both a good editor to write your code and the
compiler to translate that code to machine language. These more complex programs are called
Integrated Development Environment (IDE). Most of them also provide a convenient way to
debug your programs.
If you are just starting with programming – start with an IDE. Right now, you need to focus
on the language and programming principles. Later you can transition to another environment,
if you need to.
You can use any text editor to write code. However, most integrated development
environments (IDEs) include functionality that goes beyond text editing. They provide
a central interface for common developer tools, making the software development
process much more efficient. Developers can start programming new applications
quickly instead of manually integrating and configuring different software. They also
don't have to learn about all the tools and can instead focus on just one application.
The following are some reasons why developers use IDEs:
Programming languages have rules for how statements must be structured. Because an
IDE knows these rules, it contains many intelligent features for automatically writing
or editing the source code.
Syntax highlighting
An IDE can format the written text by automatically making some words bold or
italic, or by using different font colors. These visual cues make the source code more
readable and give instant feedback about accidental syntax errors.
Various search terms show up when you start typing words in a search engine.
Similarly, an IDE can make suggestions to complete a code statement when the
developer begins typing.
Refactoring support
Code refactoring is the process of restructuring the source code to make it more
efficient and readable without changing its core functionality. IDEs can auto-refactor
to some extent, allowing developers to improve their code quickly and easily. Other
team members understand readable code faster, which supports collaboration within
the team.
Compilation
An IDE compiles or converts the code into a simplified language that the operating
system can understand. Some programming languages implement just-in-time
compiling, in which the IDE converts human-readable code into machine code from
within the application.
Testing
The IDE allows developers to automate unit tests locally before the software is
integrated with other developers' code and more complex integration tests are run.
Debugging
Debugging is the process of fixing any errors or bugs that testing reveals. One of the
biggest values of an IDE for debugging purposes is that you can step through the code,
line by line, as it runs and inspect code behavior. IDEs also integrate several
debugging tools that highlight bugs caused by human error in real time, even as the
developer is typing.
Local IDEs
Developers install and run local IDEs directly on their local machines. They also have
to download and install various additional libraries depending on their coding
preferences, project requirements, and development language. While local IDEs are
customizable and do not require an internet connection once installed, they present
several challenges:
They consume local machine resources and can slow down machine performance
significantly.
Configuration differences between the local machine and the production environment
can give rise to software errors.
Cloud IDEs
Developers use cloud IDEs to write, edit, and compile code directly in the browser so
that they don't need to download software on their local machines. Cloud-based IDEs
have several advantages over traditional IDEs. The following are some of these
advantages:
Platform independence
Cloud IDEs work on the browser and are independent of local development
environments. This means they connect directly to the cloud vendor's platform, and
developers can use them from any machine.
Better performance
Building and compiling functions in an IDE requires a lot of memory and can slow
down the developer's computer. The cloud IDE uses compute resources from the cloud
and frees up the local machine’s resources.
You can find many modern integrated development environments (IDEs) on the
market with a range of features and different price points. Many IDEs are open source,
or free to use and configure. The following are some criteria to consider when
choosing an IDE:
The programming language you want to code in often dictates the choice of an IDE.
Dedicated IDEs have automation features that particularly suit the syntax of specific
languages. On the other hand, multi-language IDEs support multiple languages.
The operating system
While most IDEs have multiple versions for different operating systems, they might
work better on specific platforms. For example, some IDEs can perform optimally on
the Linux platform but might be slow or difficult to use on other platforms.
Automation features
The three common features in most IDES are the source code editor, build automation,
and debugger. Additional features may vary and can include the following:
Some IDEs include the ability to customize workflows to match a developer's needs
and preferences. You can download and use plugins, extensions, and add-ons to
customize your programming experience.
Dev-C++
Dev-Cpp is another IDE that is easy to get started with. You can get a distribution
with or without an integrated compiler. I recommend the distribution with the TDM-
GCC 4.9.2 32/64bit. Just download it, install and you can target both 32 and 64 bit
machines
Other popular Environments
Popular C Compilers
This is just a short list of some of the popular C compilers. There are many more, but
it is out of our scope to list them all.
Turbo C is one of the basic and popular compilers for the C programming language.
This was first introduced in 1987; it was popular for its small size, compilation speed,
and low price. Once Turbo C++ got released in 1990, both the compilers are merged
and the name Turbo C got discontinued. In 2006, Embarcadero Technologies had re-
released Turbo C as freeware. Do you remember this blue screen?
o Tiny C Compiler
The Tiny C Compiler is designed to work on slow computers with little disk space.
This is an ARM processor C compiler. This compiler started its support to Windows
from 2005. Some of its features are mentioned below.
Its file size is small and according to the owner of this compiler (Fabrice Bellard). The
fastness of this compiler is around nine times faster than GCC. The compilation,
assembling and linking of code were the main attributes considered for measuring the
fastness of this compiler.
This compiler had included many compiler-specific features to boost up the optional
memory, bound checker and had greater code stability.
This compiler allows automatic execution of programs during the compile-time only
using command line arguments. This way, programs are executed under UNIX, using
shell scripts. The latest version was released on December 2017.
o Portable C Compiler
The Portable C Compiler (PCC) was a very early used and established compiler for
the C programming language that is almost around mid-1970. This compiler had a
long life span. This was prevalent during a period in such a way that many of the C
compilers were based on it. The advantages of PCC depended on its capabilities and
probability predictions. PCC compiler was made such that source files were machine-
dependent, not all but only a few of them. It can detect syntax errors and can perform
perfect validity checks. A new version of PCC was released on 10 December 2014.
o GCC
GNU Compiler Collection is the compiler produced by the GNU Project. This
supports many programming languages and it is a free software foundation under the
General Public License. This compiler was first released in 1987 and it supported only
C- Programming language during the start. Slowly it expanded to C++, Java, Android,
and IOS. Here, each of the different language compilers has its own program that
reads the code written and sends the machine code as the output. All of these have a
common internal structure. When a high-level language is written, as per the language
it is written, the compiler parses the code in that language and produces an abstract
syntax tree. GCC uses LALR parsers, but slowly switched to recursive-descent parsers
for C in 2006. Coming to the optimization part, as already known this can occur
during any phase of the compilation. However, here the bulk optimizations are
performed before the code generation and after the syntax, semantic analysis. Below
are a few of the optimizations performed by GCC.
o Clang
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
struct books{
int id;
char bookName[50];
char authorName[50];
char date[12];
}b;
struct student{
int id;
char sName[50];
char sClass[50];
int sRoll;
char bookName[50];
char date[12];
}s;
FILE *fp;
void addBook(){
char myDate[12];
time_t t = time(NULL);
struct tm tm =
*localtime(&t);
strcpy(b.date, myDate);
fp = fopen("books.txt", "ab");
scanf("%d", &b.id);
fflush(stdin);
gets(b.bookName);
fflush(stdin);
gets(b.authorName);
fclose(fp);
void booksList(){
system("cls");
printf("<==
Available
Books ==>\n\
n");
printf("%-10s %-
30s %-20s %s\
n\n", "Book
fp = fopen("books.txt", "rb");
fclose(fp);
void del(){
system("cls");
scanf("%d", &id);
FILE *ft;
fp = fopen("books.txt", "rb");
ft = fopen("temp.txt", "wb");
if(id == b.id){
f=1;
}else{
fwrite(&b,
sizeof(b),
1, ft);
}
if(f==1){
prin
tf("\
n\
nDe
lete
d
Suc
cess
full
y.");
fclose(fp);
}else{
fclose(ft);
pri
ntf(
"\n\
remove("books.txt");
nR
eco
rename("temp.txt",
rd "books.txt");
Not
Fou
nd
} !");
void issueBook(){
char myDate[12];
time_t t = time(NULL);
struct tm tm = *localtime(&t);
strcpy(s.date, myDate);
int f=0;
system("cls");
scanf("%d", &s.id);
fp = fopen("books.txt", "rb");
if(b.id == s.id){
strcpy(s.bookName, b.bookName);
f=1;
break;
if(f==0){
return;
}
fp = fopen("issue.txt", "ab");
fflush(stdin);
gets(s.sName);
fflush(stdin);
gets(s.sClass);
scanf("%d", &s.sRoll);
fclose(fp);
void issueList(){
system("cls");
printf("<==
Book Issue
List ==>\n\
n");
printf("%-10s %-30s %-20s %-10s %-30s %s\n\n", "S.id", "Name", "Class", "Roll", "Book
Name", "Date");
fp = fopen("issue.txt", "rb");
printf("%-10d %-30s %-20s %-10d %-30s %s\n", s.id, s.sName, s.sClass, s.sRoll,
s.bookName, s.date);
fclose(fp);
int main(){
int ch;
while(1){
system("cls");
printf("1.Add Book\n");
printf("2.Books List\n");
printf("3.Remove Book\n");
printf("4.Issue Book\n");
printf("0.Exit\n\n");
printf("Enter your choice: ");
scanf("%d", &ch);
switch(ch){
case 0:
exit(0);
case 1:
addBook();
break;
case 2:
booksList();
break;
case 3:
del();
break;
case 4:
issueBook();
break;
case 5:
issueList();
break;
default:
printf("Invalid Choice...\n\n");
getch();
return 0;
}
OUTPUT
Add book..
Book list
Remove book
After removing book
Issue book
List of issue book
Conclusion
After we have completed the project we are sure the problems in the existing system would
overcome. The “LIBRARY MANAGEMENT SYSTEM” process made computerized to
reduce human errors and to increase the efficiency. The main focus of this project is to lesser
human efforts. The maintenance of the records is made efficient, as all the records are stored
in the ACCESS database, through which data can be retrieved easily . The Books and
Students are given a particular unique id no. So that they can be accessed correctly and
without errors. Our main aim of the project is to get the correct information about a particular
student and books available in the library.
This system helps educational institutes such as schools, colleges, and coaching centers to
manage library functions automatically. The prime benefits of the automated library
management system are to reduce overheads and increase productivity. The librarians can
maintain all library functions easily. In short, this system supports keeping the records of all
transactions of the books available in the library.
Future Scope of the Project:
In a nutshell, it can be summarized that the future scope of the project circles around
maintaining information regarding:
The above mentioned points are the enhancements which can be done to increase the applicability
and usage of this project. Here we can maintain the records of Student and Books. Also, as it can be
seen that now-a-days the players are versatile, Le, so there is a scope for introducing a method to
maintain the Library Management System Parkealhada can be done to maintain all the Student Book
Issues, Librarian, Member
We have left all the options open so that if there is any other future requirement in the system by the
user for the enhancement of the system then it is possible to implement them.In the last we would like
to thanks all the persons involved in the development of the system directly or indirectly. We hope that
the project will serve its purpose for which it is develop there by underlining success of process.
REFRENCES
[1]. https://www.learn-c.org
Learn C - Free Interactive C Tutorial
[2]. https://www.programiz.com
Learn C Programming – Programiz