PST UnitV

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

UNIT V

DATA FLOW DIAGRAMS

DFD is the abbreviation for Data Flow Diagram. The flow of data of a system or a process is
represented by DFD.

It also gives insight into the inputs and outputs of each entity and the process itself. DFD does
not have control flow and no loops or decision rules are present. Specific operations depending
on the type of data can be explained by a flowchart.

It is a graphical tool, useful for communicating with users ,managers and other personnel. it is
useful for analyzing existing as well as proposed system.

It provides an overview of
 What data is system processes.
 What transformation are performed.
 What data are stored.
 What results are produced , etc.

Characteristics of DFD
 DFDs are commonly used during problem analysis.
 DFDs are quite general and are not limited to problem analysis for software requirements
specification.
 DFDs are very useful in understanding a system and can be effectively used during analysis.
 It views a system as a function that transforms the inputs into desired outputs.
 The DFD aims to capture the transformations that take place within a system to the input
data so that eventually the output data is produced.
 The processes are shown by named circles and data flows are represented by named arrows
entering or leaving the bubbles.
 A rectangle represents a source or sink and it is a net originator or consumer of data. A
source sink is typically outside the main system of study.

Rules for creating DFD


 The name of the entity should be easy and understandable without any extra assistance(like
comments).
 The processes should be numbered or put in ordered list to be referred easily.
 The DFD should maintain consistency across all the DFD levels.
 A single DFD can have a maximum of nine processes and a minimum of three processes.
Symbols Used in DFD
 Square Box: A square box defines source or destination of the system. It is also called
entity. It is represented by rectangle.
 Arrow or Line: An arrow identifies the data flow i.e. it gives information to the data that is
in motion.
 Circle or bubble chart: It represents as a process that gives us information. It is also called
processing box.
 Open Rectangle: An open rectangle is a data store. In this data is store either temporary or
permanently.

Levels of DFD
DFD uses hierarchy to maintain transparency thus multilevel DFD’s can be created. Levels of
DFD are as follows:
 0-level DFD: It represents the entire system as a single bubble and provides an overall
picture of the system.
 1-level DFD: It represents the main functions of the system and how they interact with each
other.
 2-level DFD: It represents the processes within each function of the system and how they
interact with each other.
 3-level DFD: It represents the data flow within each process and how the data is
transformed and stored.

Advantages of DFD
 It helps us to understand the functioning and the limits of a system.
 It is a graphical representation which is very easy to understand as it helps visualize
contents.
 Data Flow Diagram represent detailed and well explained diagram of system components.
 It is used as the part of system documentation file.
 Data Flow Diagrams can be understood by both technical or nontechnical person because
they are very easy to understand.

Disadvantages of DFD
 At times DFD can confuse the programmers regarding the system.
 Data Flow Diagram takes long time to be generated, and many times due to this reasons
analysts are denied permission to work on it.
 DFD Level 0 is also called a Context Diagram. It’s a basic overview of the whole system or
process being analyzed or modeled. It’s designed to be an at-a-glance view, showing the
system as a single high-level process, with its relationship to external entities. It should be
easily understood by a wide audience, including stakeholders, business analysts, data analysts
and developers.

 DFD Level 1 provides a more detailed breakout of pieces of the Context Level Diagram. You
will highlight the main functions carried out by the system, as you break down the high-level
process of the Context Diagram into its subprocesses.
 DFD Level 2 then goes one step deeper into parts of Level 1. It may require more text to reach
the necessary level of detail about the system’s functioning.
 Progression to Levels 3, 4 and beyond is possible, but going beyond Level 3 is uncommon.
Doing so can create complexity that makes it difficult to communicate, compare or model
effectively.

MODULE

A module is defined as a part of a software program that contains one or more routines. When
we merge one or more modules, it makes up a program.

Whenever a product is built on an enterprise level, it is a built-in module, and each module
performs different operations and business.

Modules are implemented in the program through interfaces. The introduction of modularity
allowed programmers to reuse prewritten code with new applications. Modules are created and
merged with compilers, in which each module performs a business or routine operation within
the program.

For example - SAP(System, Applications, and Products) comprises large modules like finance,
payroll, supply chain, etc. In terms of softwares example of a module is Microsoft Word which
uses Microsoft paint to help users create drawings and paintings.

SUBPROGRAMS

A subprogram is defined as a set of statements that can be reused at multiple places in a program
when convenient. This reuse results in multiple types of savings, from memory space to coding
time. Such reuse is also an abstraction, for the analysis of subprograms computations are restored
in a program by a statement that calls the subprogram.

Features of Subprograms

The features of subprograms are as follows −

 A subprogram has a single entry point.


 The caller is suspended during the implementation of the called subprogram.
 Control repeatedly returns to the caller when the called subprogram’s execution
eliminates.

Types of Subprograms

There are two types of subprograms which are as follows −

 Procedures − A procedure is defined as a subprogram that defines parameterized


computations. These computations are executed by an individual call statement.
Procedures represent new statements. For example, because Pascal does not have a sort
statement, a user can develop a procedure to sort arrays of records and use a call to that
procedure in place of the unavailable sort statement.
The general syntax of a procedure in Pascal is given as

PROCEDURE Name of Procedure (formal parameter list); {local declaration section}


BEGIN
{instruction sequence}
END;
{end of procedure}

 Functions − A function is a subprogram that evaluates a value. Functions and procedures


are structured identical, except that
o Functions are semantically modeled on mathematical functions.
o Functions have a RETURN clause.
o Functions produce no side effects i.e., it changes neither its parameters nor any
variables defined outside the function.

The general syntax of a function in C is given as

RETURN TYPE Name of Function (formal parameter list)


{
local declaration section
……………….
……………….
instruction sequence
}

VALUE AND REFERENCE PARAMETER

Value parameters

The value parameters copy 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.

This is the default mechanism for passing parameters to a method. In this mechanism, when a
method is called, a new storage location is created for each value parameter.

The values of the actual parameters are copied into them. Hence, the changes made to the
parameter inside the method have no effect on the argument.

Reference Parameters

A reference parameter is a reference to a memory location of a variable. When you pass


parameters by reference, unlike value parameters, a new storage location is not created for these
parameters. The reference parameters represent the same memory location as the actual
parameters that are supplied to the method.
You can declare the reference parameters using the ref keyword.

SCOPE OF VARIABLE

A variable is only available from inside the region it is created. This is called scope.

Local Scope

A variable created inside a function belongs to the local scope of that function, and can only be
used inside that function.

Example

A variable created inside a function is available inside that function:

def myfunc():
x = 300
print(x)

myfunc()

output:

300

Global Scope

A variable created in the main body of the Python code is a global variable and belongs to the
global scope.

Global variables are available from within any scope, global and local.

Example

A variable created outside of a function is global and can be used by anyone:

x = 300

def myfunc():
print(x)

myfunc()

print(x)

Output
300

300

FUNCTIONS

A function is a block of code that performs a specific task.


It can be called and reused multiple times. You can pass information to a function and it can send
information back. Many programming languages have built-in functions that you can access in
their library, but you can also create your own functions.

Types of Functions

There are two types of functions in C programming:

1. Library Functions: are the functions which are declared in the C header files such as
scanf(), printf(), gets(), puts(), ceil(), floor() etc.
2. User-defined functions: are the functions which are created by the C programmer, so
that he/she can use it many times. It reduces the complexity of a big program and
optimizes the code.

here are three aspects of a C function.

o Function declaration A function must be declared globally in a c program to tell the


compiler about the function name, function parameters, and return type.

o Function call Function can be called from anywhere in the program. The parameter list
must not differ in function calling and function declaration. We must pass the same
number of functions as it is declared in the function declaration.
o Function definition It contains the actual statements which are to be executed. It is the
most important aspect to which the control comes when the function is called. Here, we
must notice that only one value can be returned from the function.

SN C function aspects Syntax

1 Function declaration return_type function_name (argument list);


2 Function call function_name (argument_list)
3 Function definition return_type function_name (argument list) {function body;}

RECURSION

Recursion is the technique of making a function call itself. This technique provides a way to
break complicated problems down into simple problems which are easier to solve.

Basic Structure of Recursive Functions


The basic syntax structure of the recursive functions is:
type function_name (args)
{
// function statements
// base condition
// recursion case (recursive call)
}

Example:

void recursion() {
recursion(); /* function calls itself */
}

int main() {
recursion();
}

Number Factorial

The following example calculates the factorial of a given number using a recursive function −

#include <stdio.h>

unsigned long long int factorial(unsigned int i)


{

if(i <= 1) {
return 1;
}
return i * factorial(i - 1);
}

int main() {
int i = 12;
printf("Factorial of %d is %d\n", i, factorial(i));
return 0;
}

When the above code is compiled and executed, it produces the following result −

Factorial of 12 is 479001600

FILE

A file is a named collection of related information that is recorded on secondary storage such as
magnetic disks, magnetic tapes and optical disks.

Types of Files

 Text file – It has a sequence of characters.


 Image file – It has visual information such as photographs, vectors art and so on.
 Source file – It has subroutines and function that are compiled later.
 Object file – It has a sequence of bytes, organized into bytes and used by the linker.
 Executable file – The binary code that the loader brings to memory for execution is
stored in an exe file.

File Attributes
A file has a single e editable name given by its creator. The name never changes unless a user
has necessary permission to change the file name. The names are given because it is humanly
understandable.

The properties of a file can be different on many systems, however, some of them are common:

1. Name – unique name for a human to recognize the file.


2. Identifier – A unique number tag that identifies the file in the file system, and non-human
readable.
3. Type – Information about the file to get support from the system.
4. Size – The current size of the file in bytes, kilobytes, or words.
5. Access Control – Defines who could read, write, execute, change, or delete the file in the
system.
6. Time, Date, and User identification – This information kept for date created, last
modified, or accessed and so on.
File Operations
The operating system performs the following file operations using various system calls:
1. Create
2. Read
3. Write
4. Delete
5. Reposition
6. Truncate files
Create Files – User must have necessary disk space on the file system to create a file. A
directory entry is required where the file is created.

Read Files – The system call requires file name and next block in memory to be read. The
system needs a read pointer to read the file from a specific location in the file and this pointer is
updated for the next read from the file.

Write Files – The system call uses same file pointers of the process to write to a file. This saves
space and reduces complexity.

Repositioning within a file – The current-file-position pointer is repositioned to a given value. It


does not involve an I/O, and known as file seek operation.

Deleting a file – We look into the directory for the file name, if a file is found, release the space
occupied by the file and remove directory entries for the deleted file.

Truncating a file – Sometimes the user does not want to delete a file, but remove some
information from it. This will change file length attribute, however, other attributes remain
unchanged.

CREATING AND READING A SEQUESTIAL FILE

Sequential files

A sequential file is an ordinary text file. Each character in the file is assumed to be either a text
character or some other ASCII control character such as newline

Creating a Sequential-Access File


This program assumes the user enters the records in account-number order. The records would
be sorted and written to the file.

// Creating a sequential file


#include <stdio.h>
int main( void ) {
unsigned int account; // account number
char name[ 30 ]; // account name
double balance; // account balance
FILE *cfPtr; // cfPtr = clients.dat file pointer
// fopen opens file. Exit program if unable to create file
if ( ( cfPtr = fopen( "clients.dat", "w" ) ) == NULL ) {
puts( "File could not be opened" );
} // end if
else {
puts( "Enter the account, name, and balance." );
puts( "Enter EOF to end input." );
printf( "%s", "? " );
scanf( "%d%29s%lf", &account, name, &balance );

// write account, name and balance into file with fprintf


while ( !feof( stdin ) ) {
fprintf( cfPtr, "%d %s %.2f\n", account, name, balance );
printf( "%s", "? " );
scanf( "%d%29s%lf", &account, name, &balance );
} // end while

fclose( cfPtr ); // fclose closes file


} // end else
} // end main

Output:
Enter the account, name, and balance.
Enter EOF to end input.
100 Jones 24.98
200 Doe 345.67
300 White 0.00
400 Stone -42.16
500 Rich 224.62
^Z

Reading Data from a Sequential-Access File


Function fscanf receives a file pointer for the file being read. When the program reaches the end
of the file, the file is closed and the program terminates.

Function feof returns true only after the program attempts to read the nonexistent data following
the last line.

// Reading and printing a sequential file


#include <stdio.h>
int main( void ) {
unsigned int account; // account number
char name[ 30 ]; // account name
double balance; // account balance
FILE *cfPtr; // cfPtr = clients.dat file pointer

// fopen opens file; exits program if file cannot be opened


if ( ( cfPtr = fopen( "clients.dat", "r" ) ) == NULL ) {
puts( "File could not be opened" );
} // end if
else {

// read account, name and balance from file


printf( "%-10s%-13s%s\n", "Account", "Name", "Balance" );
fscanf( cfPtr, "%d%29s%lf", &account, name, &balance );

// while not end of file


while ( !feof( cfPtr ) ) {
printf( "%-10d%-13s%7.2f\n", account, name, balance );
fscanf( cfPtr, "%d%29s%lf", &account, name, &balance );
} // end while
fclose( cfPtr ); // fclose closes the file
} // end else
} // end main

Program output:
Account Name Balance
100 Samuel 24.98
200 Martin 345.67
300 White 0.00
400 Stone -42.16
500 Rich 224.62

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy