Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Experiment 1

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

Experiment 1:

Start Raspberry Pi and try various Linux commands in command terminal


window: ls, cd, touch, mv, rm, man, mkdir, rmdir, tar, gzip, cat, more, less, ps, sudo, cron, chown,,chgrp,
ping etc

The Raspberry Pi is a low cost, credit-card sized computer that plugs into a computer monitor or TV,
and uses a standard keyboard and mouse. It is a capable little device that enables people of all ages to
explore computing, and to learn how to program in languages like Scratch and Python.
The Raspberry Pi device looks like a motherboard, with the mounted chips and ports exposed (something
you'd expect to see only if you opened up your computer and looked at its internal boards), but it has all
the components you need to connect input, output, and storage devices and start computing.

Here are the various components on the Raspberry Pi board:


 ARM CPU/GPU -- This is a Broadcom BCM2835 System on a Chip (SoC) that's made up of an
ARM central processing unit (CPU) and a Videocore 4 graphics processing unit (GPU). The CPU
handles all the computations that make a computer work (taking input, doing calculations and
producing output), and the GPU handles graphics output.
 GPIO -- These are exposed general-purpose input/output connection points that will allow the
real hardware hobbyists the opportunity to tinker.
 RCA -- An RCA jack allows connection of analog TVs and other similar output devices.
 Audio out -- This is a standard 3.55-millimeter jack for connection of audio output devices such
as headphones or speakers. There is no audio in.
 LEDs -- Light-emitting diodes, for all of your indicator light needs.
 USB -- This is a common connection port for peripheral devices of all types (including your
mouse and keyboard). Model A has one, and Model B has two. You can use a USB hub to expand
the number of ports or plug your mouse into your keyboard if it has its own USB port.
 HDMI -- This connector allows you to hook up a high-definition television or other compatible
device using an HDMI cable.
 Power -- This is a 5v Micro USB power connector into which you can plug your compatible
power supply.
 SD cardslot -- This is a full-sized SD card slot. An SD card with an operating system (OS)
installed is required for booting the device. They are available for purchase from the
manufacturers, but you can also download an OS and save it to the card yourself if you have a
Linux machine and the wherewithal.
 Ethernet -- This connector allows for wired network access and is only available on the Model B.
Commands
ls : The “ls” command lists the content of current directory.
Syntax: ls [options] [paths]
The ls supports following options
 ls -a: list all files including hidden files. These are files that start with “.”.
 ls -A: list all files including hidden files except for “.” and “..” – these refer to the entries for the
current directory, and for the parent directory.
 ls -R: list all files recursively, descending down the directory tree from the given path.
 ls -l: list the files in long format i.e. with an index number, owner name, group name, size, and
permissions.
 ls – o: list the files in long format but without the group name.
 ls -g: list the files in long format but without the owner name.
 ls -i: list the files along with their index number.
 ls -s: list the files along with their size.
 ls -t: sort the list by time of modification, with the newest at the top.
 ls -S: sort the list by size, with the largest at the top.
 ls -r: reverse the sorting order

ex : List all non-hidden files in the current directory


$ ls
o/p : dir1 dir2 file1 file2

CD: Using cd changes the current directory to the one specified. You can use relative (i.e. cd
directoryA ) or absolute (i.e. cd /home/pi/directoryA ) paths.
cd [option] [directory]
ex: cd /usr/sbin
touch: It is used to create a file without any content. The file created using touch command is empty.
This command can be used when the user doesn’t have data to store at the time of file creation
syntax: touch [option] [file_name]
Touch Command options
-a, change the access time only
-c, if the file does not exist, do not create it
-d, update the access and modification times
-m, change the modification time only
-r, use the access and modification times of file
-t, creates a file using a specified time
mv: mv stands for move. mv is used to move one or more files or directories from one place to
another in file system.
Syntax: mv [Option] source destination
mv -f force move by overwriting destination file without prompt
mv -i interactive prompt before overwrite
mv -u update - move when source is newer than destination
mv -v verbose - print source and destination files
man mv help manual

Ex : $ mv a.txt geek.txt
rm : rm stands for ‘remove‘ as the name suggests rm command is used to delete or remove files and
directory
syntax: rm [options] [files]
remove command options
-f, --force
ignore nonexistent files, never prompt
-i
prompt before every removal
-I
prompt once before removing more than three files, or when removing recursively. Less intrusive
than -i, while still giving protection against most mistakes
--interactive[=WHEN]
prompt according to WHEN: never, once (-I), or always (-i). Without WHEN, prompt always
--one-file-system
when removing a hierarchy recursively, skip any directory that is on a file system different from
that of the corresponding command line argument
--no-preserve-root
do not treat '/' specially
--preserve-root
do not remove '/' (default)
-r, -R, --recursive
remove directories and their contents recursively
-v, --verbose
explain what is being done
--help
display this help and exit
--version
output version information and exit

man : man command in Linux is used to display the user manual of any command

syntax: man [option] [command_name]

ex: $ man - lsmkdir: You can use mkdir to create a new directory.
Syntax: mkdir [options...] [directories ...
Ex: $ mkdir mydir
rmdir: The rmdir command removes each directory specified on the command line, if they are
empty. That is, each directory removed must contain no files or directories, or it cannot be removed
by rmdir
syntax: rmdir [-p] [-v | --verbose] [--ignore-fail-on-non-empty] directory ...
tar: the Linux “tar” stands for tape archive
syntax: tar [options] [archive-file] [file or directory to be archived]

gZip: gzip command compresses files. Each single file is compressed into a single file. The compressed
file consists of a GNU zip header and deflated data.

Syntax: gzip [Options] [filenames]

Cat: Cat(concatenate) command is very frequently used in Linux. It reads data from the file and gives
their content as output. It helps us to create, view, concatenate files. So let us see some frequently used cat
commands.
Syntax: $cat filename
More: more command is used to view the text files in the command prompt, displaying one screen at a
time
Sytax: more [-options] [-num] [+/pattern] [+linenum] [file_name]

Less: Less command is linux utility which can be used to read contents of text file one page(one screen)
per time
Syntax: less filename
Ps: Linux provides us a utility called ps for viewing information related with the processes on a system
which stands as abbreviation for “Process Status”

Syntax: ps [options]
Sudo: sudo (Super User DO) command in Linux is generally used as a prefix of some command that
only superuser are allowed to run. If you prefix “sudo” with any command, it will run that command with
elevated privileges
Syntax: sudo -V | -h | -l | -v | -k | -K | -s | [ -H ] [-P ] [-S ] [ -b ] |
[ -p prompt ] [ -c class|- ] [ -a auth_type ] [-r role ] [-t type ]
[ -u username|#uid ] commandsudo -V | -h | -l | -L | -v | -k | -K | -s | [ -H ] [-P ] [-S ] [ -b ] |
[ -p prompt ] [ -c class|- ] [ -a auth_type ] [-r role ] [-t type ]
[ -u username|#uid ] command
Cron: The cron is a software utility, offered by Linux-like operating system which automates the
scheduled task at a predetermined time
Syntax: cron [-f] [-l] [-L loglevel]
Chgrp: chgrp command in Linux is used to change the group ownership of a file or directory. All files in
Linux belong to an owner and a group. You can set the owner by using “chown” command, and the group
by the “chgrp” command.
Syntax: chgrp [OPTION]… GROUP FILE…
chgrp [OPTION]… –reference=RFILE FILE…
Ping: PING (Packet Internet Groper) command is used to check the network connectivity between host
and server/host.
Syntax: To get ping version installed on your system.

sudo ping –
Experiment 2: Study and Install IDE of Arduino and different types of Arduino.
Arduino :
Arduino is a prototype platform (open-source) based on an easy-to-use hardware and software. It
consists of a circuit board, which can be programed (referred to as a microcontroller) and a ready-made
software called Arduino IDE (Integrated Development Environment), which is used to write and upload
the computer code to the physical board.
Arduino provides a standard form factor that breaks the functions of the micro-controller into a more
accessible package.

The key features are −


 Arduino boards are able to read analog or digital input signals from different sensors and turn it
into an output such as activating a motor, turning LED on/off, connect to the cloud and many
other actions.
 You can control your board functions by sending a set of instructions to the microcontroller on
the board via Arduino IDE (referred to as uploading software).
 Unlike most previous programmable circuit boards, Arduino does not need an extra piece of
hardware (called a programmer) in order to load a new code onto the board. You can simply use
a USB cable.
 Additionally, the Arduino IDE uses a simplified version of C++, making it easier to learn to
program.
 Finally, Arduino provides a standard form factor that breaks the functions of the micro-controller
into a more accessible package.
Installation of Arduino

Step 1 − First you must have your Arduino board (you can choose your favorite board) and a USB cable.
In case you use Arduino UNO, Arduino Duemilanove, Nano, Arduino Mega 2560, or Diecimila, you
will need a standard USB cable (A plug to B plug), the kind you would connect to a USB printer as
shown in the following image.
In case you use Arduino Nano, you will need an A to Mini-B cable
Step 2 − Download Arduino IDE Software.
You must select your software, which is compatible with your operating system (Windows, IOS, or
Linux). After your file download is complete, unzip the file.
Step 3 − Power up your board.
The Arduino Uno, Mega, Duemilanove and Arduino Nano automatically draw power from either, the
USB connection to the computer or an external power supply. If you are using an Arduino Diecimila,
you have to make sure that the board is configured to draw power from the USB connection. The power
source is selected with a jumper, a small piece of plastic that fits onto two of the three pins between the
USB and power jacks. Check that it is on the two pins closest to the USB port.
Connect the Arduino board to your computer using the USB cable. The green power LED (labeled
PWR) should glow.
Step 4 − Launch Arduino IDE.
After your Arduino IDE software is downloaded, you need to unzip the folder. Inside the folder, you can
find the application icon with an infinity label (application.exe). Double-click the icon to start the IDE.
Step 5 − Open your first project.
Once the software starts, you have two options −
 Create a new project.
 Open an existing project example.
To create a new project, select File → New.
To open an existing project example, select File → Example → Basics → Blink.

Here, we are selecting just one of the examples with the name Blink. It turns the LED on and
off with some time delay. You can select any other example from the list.
Step 6 − Select your Arduino board.
To avoid any error while uploading your program to the board, you must select the correct
Arduino board name, which matches with the board connected to your computer.
Go to Tools → Board and select your board.
Here, we have selected Arduino Uno board according to our tutorial, but you must select the
name matching the board that you are using.
Step 7 − Select your serial port.
Select the serial device of the Arduino board. Go to Tools → Serial Port menu. This is likely to
be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find
out, you can disconnect your Arduino board and re-open the menu, the entry that disappears
should be of the Arduino board. Reconnect the board and select that serial port.
Step 8 − Upload the program to your board.
Before explaining how we can upload our program to the board, we must demonstrate the
function of each symbol appearing in the Arduino IDE toolbar.

A − Used to check if there is any compilation error.


B − Used to upload a program to the Arduino board.
C − Shortcut used to create a new sketch.
D − Used to directly open one of the example sketch.
E − Used to save your sketch.
F − Serial monitor used to receive serial data from the board and send the serial data
to the board.
Now, simply click the "Upload" button in the environment. Wait a few seconds; you will see the
RX and TX LEDs on the board, flashing. If the upload is successful, the message "Done
uploading" will appear in the status bar
Experiment 3: Study and Implement Zigbee Protocol using Arduino / RaspberryPi.

ZigBee Communication Using Raspberry Pi :

ZigBee is a communication device used for the data transfer between the controllers, computers,
systems, really anything with a serial port. As it works with low power consumption, the transmission
distances is limited to 10–100 meters line-of-sight. ZigBee devices can transmit data over long distances
by passing data through a mesh network of intermediate devices to reach more distant ones. ZigBee is
typically used in low data rate applications that require long battery life and secure netwo

rking. Its main applications are in the field of wireless sensor network based on industries as it requires
short-range low-rate wireless data transfer. The technology defined by the ZigBee specification is
intended to be simpler and less expensive than other wireless networks.

Here we make use of an interface of Zigbee with Raspberry Pi2 for a proper wireless communication.
Raspberry Pi2 has got four USB ports, so it is better to use a Zigbee Dongle for this interface. Now we
want to check the communication between the two paired ZigBee modules.

Modules Needed :
1. Raspberry Pi2
2. XBee 1mW Wire Antenna- Series 1 (2 No:)

3. XBee Explorer Dongle (2 No:)


The two Zigbee must be paired with the same baudrate (for Ex: 9600) with X-CTU Software. Attach the
two Zigbee’s to the two dongle’s and connect one pair on the USB port of the Raspberry Pi2. Connect the
other pair to the USB port of a computer or a Laptop. Install the FTDI Driver on the Computer /laptop to
provide usb communication. Create a hyperterminal, select the corresponding com port and the baudrate
for the connected device.

In the Raspberry Pi2 section open the LX terminal and type lsusb.

The response showed inside a red box indicates the presence of a usb device in the module. Write a
python script to perform Zigbee communication which is given below.

import serial

# Enable USB Communication


ser = serial.Serial('/dev/ttyUSB0', 9600,timeout=.5)

while True:
ser.write('Hello User \r\n') # write a Data
incoming = ser.readline().strip()
print 'Received Data : '+ incoming

The two zigbee must be in a line of sight and check the results in the Python shell
and in the hyperterminal of the computer.

The Communication could also be established with two Raspberry Pi or with another controller it self.
Experiment 6:
Write a program to Implement Bankers algorithm for Dead Lock Avoidance.
Program:
package computing;

import java.util.Scanner;
public class Bankers{
private int need[][],allocate[][],max[][],avail[][],np,nr;

private void input(){


Scanner sc=new Scanner(System.in);
System.out.print("Enter no. of processes and resources : ");
np=sc.nextInt(); //no. of process
nr=sc.nextInt(); //no. of resources
need=new int[np][nr]; //initializing arrays
max=new int[np][nr];
allocate=new int[np][nr];
avail=new int[1][nr];

System.out.println("Enter allocation matrix -->");


for(int i=0;i<np;i++)
for(int j=0;j<nr;j++)
allocate[i][j]=sc.nextInt(); //allocation matrix

System.out.println("Enter max matrix -->");


for(int i=0;i<np;i++)
for(int j=0;j<nr;j++)
max[i][j]=sc.nextInt(); //max matrix

System.out.println("Enter available matrix -->");


for(int j=0;j<nr;j++)
avail[0][j]=sc.nextInt(); //available matrix

sc.close();
}

private int[][] calc_need(){


for(int i=0;i<np;i++)
for(int j=0;j<nr;j++) //calculating need matrix
need[i][j]=max[i][j]-allocate[i][j];

return need;
}

private boolean check(int i){


//checking if all resources for ith process can be allocated
for(int j=0;j<nr;j++)
if(avail[0][j]<need[i][j])
return false;

return true;
}

public void isSafe(){


input();
calc_need();
boolean done[]=new boolean[np];
int j=0;

while(j<np){ //until all process allocated


boolean allocated=false;
for(int i=0;i<np;i++)
if(!done[i] && check(i)){ //trying to allocate
for(int k=0;k<nr;k++)
avail[0][k]=avail[0][k]-need[i][k]+max[i][k];
System.out.println("Allocated process : "+i);
allocated=done[i]=true;
j++;
}
if(!allocated) break; //if no allocation
}
if(j==np) //if all processes are allocated
System.out.println("\nSafely allocated");
else
System.out.println("All proceess cant be allocated safely");
}

public static void main(String[] args) {


new Bankers().isSafe();
}
}

Output: Enter no. of processes and resources : 5


3
Enter allocation matrix -->
0
1
0
2
0
0
3
0
2
2
1
1
0
0
2
Enter max matrix -->
7
5
3
3
2
2
9
0
2
2
2
2
4
3
3
Enter available matrix -->
3
3
2
Allocated process : 1
Allocated process : 3
Allocated process : 4
Allocated process : 0
Allocated process : 2

Safely allocated
Experiment 7:
Write a program to Producer-consumer problem Using semaphores
Program:
package computing;

import java.util.concurrent.Semaphore;

class Q {
// an item
int item;

// semCon initialized with 0 permits


// to ensure put() executes first
static Semaphore semCon = new Semaphore(0);

static Semaphore semProd = new Semaphore(1);

// to get an item from buffer


void get()
{
try {
// Before consumer can consume an item,
// it must acquire a permit from semCon
semCon.acquire();
}
catch (InterruptedException e) {
System.out.println("InterruptedException caught");
}

// consumer consuming an item


System.out.println("Consumer consumed item : " + item);

// After consumer consumes the item,


// it releases semProd to notify producer
semProd.release();
}

// to put an item in buffer


void put(int item)
{
try {
// Before producer can produce an item,
// it must acquire a permit from semProd
semProd.acquire();
}
catch (InterruptedException e) {
System.out.println("InterruptedException caught");
}

// producer producing an item


this.item = item;
System.out.println("Producer produced item : " + item);

// After producer produces the item,


// it releases semCon to nssotify consumer
semCon.release();
}
}

// Producer class
class Producer implements Runnable {
Q q;
Producer(Q q)
{
this.q = q;
new Thread(this, "Producer").start();
}

public void run()


{
for (int i = 0; i < 5; i++)
// producer put items
q.put(i);
}
}

// Consumer class
class Consumer implements Runnable {
Q q;
Consumer(Q q)
{
this.q = q;
new Thread(this, "Consumer").start();
}

public void run()


{
for (int i = 0; i < 5; i++)
// consumer get items
q.get();
}
}

// Driver class
class PC {
public static void main(String args[])
{
// creating buffer queue
Q q = new Q();

// starting consumer thread


new Consumer(q);

// starting producer thread


new Producer(q);
}
}

Output: Producer produced item : 0


Consumer consumed item : 0
Producer produced item : 1
Consumer consumed item : 1
Producer produced item : 2
Consumer consumed item : 2
Producer produced item : 3
Consumer consumed item : 3
Producer produced item : 4
Consumer consumed item : 4
Experiment 10:
Write a program of bit stuffing used by Data Link Layer.
Program:
package computing;

import java.io.*;

public class BitStuffing {

public static void main(String[] args)throws IOException {


int i=0,x;
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String sy="01111110",sx;
StringBuilder sby = new StringBuilder(sy);
System.out.print("ENTER THE DATA: ");
sx = br.readLine();
StringBuilder sbx = new StringBuilder(sx);
x = sx.length();
while(i+5<=x){
String s1 = sx.substring(i, i+5);
if(check(s1)){
sbx.insert(i+5,0);
i=i+6;
}
else i++;
}

System.out.print("BIT STUFFING: ");


System.out.println(sbx);
System.out.print("FINAL OUTPUT: ");
System.out.println(sby+" "+sbx+" "+sby);
System.out.println(sby.append(sbx.append(sby)));

}
private static boolean check(String s){
String s1 = "11111";
if(s.equals(s1))
return true;
else return false;
}

}
Output: ENTER THE DATA: 0111110
BIT STUFFING: 01111100
FINAL OUTPUT: 01111110 01111100 01111110
011111100111110001111110
Experiment 11:
Write a program to configure a Network using Distance Vector Routing protocol.
Program:
package computing;

import java.io.*;
public class DVR
{
static int graph[][];
static int via[][];
static int rt[][];
static int v;
static int e;

public static void main(String args[]) throws IOException


{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Please enter the number of Vertices: ");


v = Integer.parseInt(br.readLine());

System.out.println("Please enter the number of Edges: ");


e = Integer.parseInt(br.readLine());

graph = new int[v][v];


via = new int[v][v];
rt = new int[v][v];
for(int i = 0; i < v; i++)
for(int j = 0; j < v; j++)
{
if(i == j)
graph[i][j] = 0;
else
graph[i][j] = 9999;
}

for(int i = 0; i < e; i++)


{
System.out.println("Please enter data for Edge " + (i + 1) + ":");
System.out.print("Source: ");
int s = Integer.parseInt(br.readLine());
s--;
System.out.print("Destination: ");
int d = Integer.parseInt(br.readLine());
d--;
System.out.print("Cost: ");
int c = Integer.parseInt(br.readLine());
graph[s][d] = c;
graph[d][s] = c;
}

dvr_calc_disp("The initial Routing Tables are: ");


System.out.print("Please enter the Source Node for the edge whose cost has changed:
");
int s = Integer.parseInt(br.readLine());
s--;
System.out.print("Please enter the Destination Node for the edge whose cost has
changed: ");
int d = Integer.parseInt(br.readLine());
d--;
System.out.print("Please enter the new cost: ");
int c = Integer.parseInt(br.readLine());
graph[s][d] = c;
graph[d][s] = c;

dvr_calc_disp("The new Routing Tables are: ");


}

static void dvr_calc_disp(String message)


{
System.out.println();
init_tables();
update_tables();
System.out.println(message);
print_tables();
System.out.println();
}

static void update_table(int source)


{
for(int i = 0; i < v; i++)
{
if(graph[source][i] != 9999)
{
int dist = graph[source][i];
for(int j = 0; j < v; j++)
{
int inter_dist = rt[i][j];
if(via[i][j] == source)
inter_dist = 9999;
if(dist + inter_dist < rt[source][j])
{
rt[source][j] = dist + inter_dist;
via[source][j] = i;
}
}
}
}
}

static void update_tables()


{
int k = 0;
for(int i = 0; i < 4*v; i++)
{
update_table(k);
k++;
if(k == v)
k = 0;
}
}

static void init_tables()


{
for(int i = 0; i < v; i++)
{
for(int j = 0; j < v; j++)
{
if(i == j)
{
rt[i][j] = 0;
via[i][j] = i;
}
else
{
rt[i][j] = 9999;
via[i][j] = 100;
}
}
}
}

static void print_tables()


{
for(int i = 0; i < v; i++)
{
for(int j = 0; j < v; j++)
{
System.out.print("Dist: " + rt[i][j] + " ");
}
System.out.println();
}
}

Output:

Please enter the number of Vertices:


4
Please enter the number of Edges:
5
Please enter data for Edge 1:
Source: 1
Destination: 2
Cost: 1
Please enter data for Edge 2:
Source: 1
Destination: 3
Cost: 3
Please enter data for Edge 3:
Source: 2
Destination: 3
Cost: 1
Please enter data for Edge 4:
Source: 2
Destination: 4
Cost: 1
Please enter data for Edge 5:
Source: 3
Destination: 4
Cost: 4

The initial Routing Tables are:


Dist: 0 Dist: 1 Dist: 2 Dist: 2
Dist: 1 Dist: 0 Dist: 1 Dist: 1
Dist: 2 Dist: 1 Dist: 0 Dist: 2
Dist: 2 Dist: 1 Dist: 2 Dist: 0

Please enter the Source Node for the edge whose cost has changed: 2
Please enter the Destination Node for the edge whose cost has changed: 4
Please enter the new cost: 10

The new Routing Tables are:


Dist: 0 Dist: 1 Dist: 2 Dist: 6
Dist: 1 Dist: 0 Dist: 1 Dist: 5
Dist: 2 Dist: 1 Dist: 0 Dist: 4
Dist: 6 Dist: 5 Dist: 4 Dist: 0
Experiment 15:
Write C programs for implementing the Demorgan’s law.
Program:

#include "stdafx.h"

#include <stdio.h>
#include <math.h>
#include <iostream>

// start main program.


int main()
{
// variables
int a;
int b;
int g;
int i;
int j;
int x;
int y;
char ch = 'y';

do {

puts("\nShow that (!(x < 5) && !(y >= 7)) and !((x < 5) || (y >= 7))
are logically equivalent\n\n"); // Part a

// input x and y values


printf("%s", "Enter x: ");
scanf("%2u", &x);
printf("%s", "Enter y: ");
scanf("%2u", &y);

// if statement to handle logical equivalency


if ((!(x < 5) && !(y >= 7)) && !((x < 5) || (y >= 7))) {
printf("%s", "True!\n\n");
}
else {
printf("%s", "False!\n\n");
}

printf("%s", "Want more examples of this logical equivalency? ");


getchar();
scanf("%c", &ch);
}
while (ch == 'y'); // choose yes to continue with current part, or no to
move on

if (ch == 'n') {

do {
puts("\nShow that (!(a == b) || !(g != 5)) and !((a == b) && (g !=
5)) are logically equivalent\n\n");

// input a, b, and g values


printf("%s", "Enter a: ");
scanf("%2u", &a);
printf("%s", "Enter b: ");
scanf("%2u", &b);
printf("%s", "Enter g: ");
scanf("%2u", &g);

// if statement to handle logical equivalency


if ((!(a == b) || !(g != 5)) && !((a == b) && (g != 5))) {
printf("%s", "True!\n\n");
}
else {
printf("%s", "False!\n\n");
}
printf("%s", "Want more examples of this logical equivalency? ");
getchar();
scanf("%c", &ch);
}
while(ch == 'y'); // choose yes to continue with current part, or no to
move on
}

if (ch == 'n') {

do {
puts("\nShow that !((x <= 8) && (y > 4)) and (!(x <= 8) || !(y > 4))
are logically equivalent\n\n");

// input x and y values


printf("%s", "Enter x: ");
scanf("%2u", &x);
printf("%s", "Enter y: ");
scanf("%2u", &y);

// if statement to handle logical equivalency


if (!((x <= 8) && (y > 4)) && (!(x <= 8) || !(y > 4))) {
printf("%s", "True!\n\n");
}
else {
printf("%s", "False!\n\n");
}
printf("%s", "Want more examples of this logical equivalency? ");
getchar();
scanf("%c", &ch);
}
while (ch == 'y'); // choose yes to continue with current part, or no to
move on
}

if (ch == 'n') {

do {
puts("\nShow that !((i > 4) || (j <= 6)) and (!(i > 4) && !(j <= 6))
are logically equivalent\n\n");

// input i and j values


printf("%s", "Enter i: ");
scanf("%2u", &i);
printf("%s", "Enter j: ");
scanf("%2u", &j);

// if statement to handle logical equivalency


if (!((i > 4) || (j <= 6)) && (!(x <= 8) && !(y > 4))) {
printf("%s", "True!\n\n");
}
else {
printf("%s", "False!\n\n");
}
printf("%s", "Want more examples of this logical equivalency? ");
getchar();
scanf("%c", &ch);
}
while (ch == 'y'); // choose yes to continue with current part, or no to
move on
}

if (ch == 'n') {
printf("\n%s", "Now you know DeMorgan's Laws!");
}

system("pause");
return 0;
}
Experiment 12:Write a program to perform the function oriented diagram: DFD and Structured
chart.

Data Flow Diagram

Data flow diagram is graphical representation of flow of data in an information system. It is capable of
depicting incoming data flow, outgoing data flow and stored data. The DFD does not mention anything
about how data flows through the system.
There is a prominent difference between DFD and Flowchart. The flowchart depicts flow of control in
program modules. DFDs depict flow of data in the system at various levels. DFD does not contain any
control or branch elements.

Types of DFD

Data Flow Diagrams are either Logical or Physical.

 Logical DFD - This type of DFD concentrates on the system process, and flow of data in the
system. For example in a Banking software system, how data is moved between different entities.
 Physical DFD - This type of DFD shows how the data flow is actually implemented in the
system. It is more specific and close to the implementation.

DFD Components

DFD can represent Source, destination, storage and flow of data using the following set of components -

 Entities - Entities are source and destination of information data. Entities are represented by a
rectangles with their respective names.
 Process - Activities and action taken on the data are represented by Circle or Round-edged
rectangles.
 Data Storage - There are two variants of data storage - it can either be represented as a rectangle
with absence of both smaller sides or as an open-sided rectangle with only one side missing.
 Data Flow - Movement of data is shown by pointed arrows. Data movement is shown from the
base of arrow as its source towards head of the arrow as destination.

Levels of DFD

 Level 0 - Highest abstraction level DFD is known as Level 0 DFD, which depicts the entire
information system as one diagram concealing all the underlying details. Level 0 DFDs are also
known as context level DFDs.
 Level 1 - The Level 0 DFD is broken down into more specific, Level 1 DFD. Level 1 DFD
depicts basic modules in the system and flow of data among various modules. Level 1 DFD also
mentions basic processes and sources of information.

 Level 2 - At this level, DFD shows how data flows inside the modules mentioned in Level 1.
Higher level DFDs can be transformed into more specific lower level DFDs with deeper level of
understanding unless the desired level of specification is achieved
Structure Charts

Structure chart is a chart derived from Data Flow Diagram. It represents the system in more detail than
DFD. It breaks down the entire system into lowest functional modules, describes functions and sub-
functions of each module of the system to a greater detail than DFD.
Structure chart represents hierarchical structure of modules. At each layer a specific task is performed.
Here are the symbols used in construction of structure charts -

 Module - It represents process or subroutine or task. A control module branches to more than one
sub-module. Library Modules are re-usable and invokable from any module.

 Condition - It is represented by small diamond at the base of module. It depicts that control
module can select any of sub-routine based on some condition.
 Jump - An arrow is shown pointing inside the module to depict that the control will jump in the

middle of the sub-module.


 Loop - A curved arrow represents loop in the module. All sub-modules covered by loop repeat

execution of module.
 Data flow - A directed arrow with empty circle at the end represents data flow.

 Control flow - A directed arrow with filled circle at the end represents control flow.
Example

We take the same example of Customer Authentication in the online shopping environment. This
procedure to authenticate customer can be written in Structured English as:

Enter Customer_Name

SEEK Customer_Name in Customer_Name_DB file

IF Customer_Name found THEN

Call procedure USER_PASSWORD_AUTHENTICATE()

ELSE

PRINT error message

Call procedure NEW_CUSTOMER_REQUEST()

ENDIF

The code written in Structured English is more like day-to-day spoken English. It can not be
implemented directly as a code of software. Structured English is independent of programming
language.
Experiment 13:
Write a program to perform the system analysis: Requirement analysis, SRS.

Requirement Analysis

Gathering requirements from the user. Analysts and engineers communicate with the client and end-
users to know their ideas on what the software should provide and which features they want the software
to include.

Software Requirement Specification

SRS is a document created by system analyst after the requirements are collected from various
stakeholders.
SRS defines how the intended software will interact with hardware, external interfaces, speed of
operation, response time of system, portability of software across various platforms, maintainability,
speed of recovery after crashing, Security, Quality, Limitations etc.
The requirements received from client are written in natural language. It is the responsibility of system
analyst to document the requirements in technical language so that they can be comprehended and useful
by the software development team.

Requirement Elicitation Process

Requirement elicitation process can be depicted using the folloiwng diagram:

 Requirements gathering - The developers discuss with the client and end users and know their
expectations from the software.
 Organizing Requirements - The developers prioritize and arrange the requirements in order of
importance, urgency and convenience.
 Negotiation & discussion - If requirements are ambiguous or there are some conflicts in
requirements of various stakeholders, if they are, it is then negotiated and discussed with
stakeholders. Requirements may then be prioritized and reasonably compromised.
The requirements come from various stakeholders. To remove the ambiguity and conflicts, they
are discussed for clarity and correctness. Unrealistic requirements are compromised reasonably.

 Documentation - All formal & informal, functional and non-functional requirements are
documented and made available for next phase processing.
Experiment 14:
Write a program to draw the structural view diagram: Class diagram, object diagram.

Class Diagram:
Class diagram is a static diagram. It represents the static view of an application. Class diagram is not only used for
visualizing, describing, and documenting different aspects of a system but also for constructing executable code of
the software application .
Class diagram describes the attributes and operations of a class and also the constraints imposed on the
system. The class diagrams are widely used in the modeling of objectoriented systems because they are
the only UML diagrams, which can be mapped directly with object-oriented languages.
Class diagram shows a collection of classes, interfaces, associations, collaborations, and constraints. It is
also known as a structural diagram.

Procedure to draw class diagram:


Class diagrams are the most popular UML diagrams used for construction of software applications. It is
very important to learn the drawing procedure of class diagram.
Class diagrams have a lot of properties to consider while drawing but here the diagram will be
considered from a top level view.
Class diagram is basically a graphical representation of the static view of the system and represents
different aspects of the application. A collection of class diagrams represent the whole system.
The following points should be remembered while drawing a class diagram −
 The name of the class diagram should be meaningful to describe the aspect of the system.
 Each element and their relationships should be identified in advance.
 Responsibility (attributes and methods) of each class should be clearly identified
 For each class, minimum number of properties should be specified, as unnecessary properties
will make the diagram complicated.
 Use notes whenever required to describe some aspect of the diagram. At the end of the drawing it
should be understandable to the developer/coder.
 Finally, before making the final version, the diagram should be drawn on plain paper and
reworked as many times as possible to make it correct.
The following diagram is an example of an Order System of an application. It describes a particular
aspect of the entire application.
 First of all, Order and Customer are identified as the two elements of the system. They have a
one-to-many relationship because a customer can have multiple orders.
 Order class is an abstract class and it has two concrete classes (inheritance relationship)
SpecialOrder and NormalOrder.
 The two inherited classes have all the properties as the Order class. In addition, they have
additional functions like dispatch () and receive ().
The following class diagram has been drawn considering all the points mentioned above.

Object diagram:
Object diagrams are derived from class diagrams so object diagrams are dependent upon class diagrams.
Object diagrams represent an instance of a class diagram. The basic concepts are similar for class
diagrams and object diagrams. Object diagrams also represent the static view of a system but this static
view is a snapshot of the system at a particular moment.
Object diagrams are used to render a set of objects and their relationships as an instance.

Procedure to draw object diagram:


We have already discussed that an object diagram is an instance of a class diagram. It implies that an
object diagram consists of instances of things used in a class diagram.
So both diagrams are made of same basic elements but in different form. In class diagram elements are
in abstract form to represent the blue print and in object diagram the elements are in concrete form to
represent the real world object.
To capture a particular system, numbers of class diagrams are limited. However, if we consider object
diagrams then we can have unlimited number of instances, which are unique in nature. Only those
instances are considered, which have an impact on the system.
From the above discussion, it is clear that a single object diagram cannot capture all the necessary
instances or rather cannot specify all the objects of a system. Hence, the solution is −
 First, analyze the system and decide which instances have important data and association.
 Second, consider only those instances, which will cover the functionality.
 Third, make some optimization as the number of instances are unlimited.
Before drawing an object diagram, the following things should be remembered and understood clearly −
 Object diagrams consist of objects.
 The link in object diagram is used to connect objects.
 Objects and links are the two elements used to construct an object diagram.
After this, the following things are to be decided before starting the construction of the diagram −
 The object diagram should have a meaningful name to indicate its purpose.
 The most important elements are to be identified.
 The association among objects should be clarified.
 Values of different elements need to be captured to include in the object diagram.
 Add proper notes at points where more clarity is required.
The following diagram is an example of an object diagram. It represents the Order management system
which we have discussed in the chapter Class Diagram. The following diagram is an instance of the
system at a particular time of purchase. It has the following objects.
 Customer
 Order
 SpecialOrder
 NormalOrder
Now the customer object (C) is associated with three order objects (O1, O2, and O3). These order
objects are associated with special order and normal order objects (S1, S2, and N1). The customer has
the following three orders with different numbers (12, 32 and 40) for the particular time considered.
The customer can increase the number of orders in future and in that scenario the object diagram will
reflect that. If order, special order, and normal order objects are observed then you will find that they
have some values.
For orders, the values are 12, 32, and 40 which implies that the objects have these values for a particular
moment (here the particular time when the purchase is made is considered as the moment) when the
instance is captured
The same is true for special order and normal order objects which have number of orders as 20, 30, and
60. If a different time of purchase is considered, then these values will change accordingly.
The following object diagram has been drawn considering all the points mentioned above

You might also like