Advanced Computing Lab Manual
Advanced Computing Lab Manual
ADVANCED COMPUTING
LAB MANUAL
By
M Naresh Babu
Course Objectives:
From the course the student will learn
The student should have hands on experience in using various sensors like temperature,
humidity, smoke, light, etc. and should be able to use control web camera, network, and
relays connected to the Pi.
Course Outcomes:
After the completion of the course, student will be able to
The student should have hands on experience in using various sensors like temperature,
humidity, smoke, light, etc. and should be able to use control web camera, network, and
relays connected to the Pi.
Development and use of s IoT technology in Societal and Industrial Applications.
Skills to undertake high quality academic and industrial research in Sensors and IoT.
To classify Real World IoT Design Constraints, Industrial Automation in IoT.
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.
Experiment 2: Study and Install IDE of Arduino and different types of Arduino.
Experiment 4: Write a map reduce program that mines weather data. Weather sensors
collecting data every hour at many locations across the globe gather a large volume of log
data, which is a good candidate for analysis with Map Reduce, since it is semi structured and
record-oriented.
Experiment 5: Data analytics using Apache Spark on Amazon food dataset, find all the pairs
of items frequently reviewed together.
Write a single Spark application that
Transposes the original Amazon food dataset, obtaining a PairRDD of the
type<user_id>→ <list of the product_ ids reviewed by user_id>
Counts the frequencies of all the pairs of products reviewed together.
Writes on the output folder all the pairs of products that appear more than once and their
frequencies. The pairs of products must be sorted by frequency.
Experiment 6:
Write a program to Implement Bankers algorithm for Dead Lock Avoidance.
Experiment 7:
Write a program to Producer-consumer problem Using semaphores.
Experiment 8:
Write a program for an image enhancement using pixel operation.
Experiment 9:
Write a Program to enhance image using image arithmetic and logical operations.
Experiment 10:
Write a program of bit stuffing used by Data Link Layer.
Experiment 11:
Write a program to configure a Network using Distance Vector Routing protocol.
Experiment 12:
Write a program to perform the function oriented diagram: DFD and Structured chart.
Experiment 13:
Write a program to perform the system analysis: Requirement analysis, SRS.
Experiment 14:
Write a program to draw the structural view diagram: Class diagram, object diagram.
Experiment 15:
Write C programs for implementing the Demorgan’s law.
Aim: To Start Raspberry Pi and working with 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 terminal (or 'command-line') on a computer allows a user a great deal of control over
their system (or in this case, Pi!). Users of Windows may already have come across
Command Prompt or Powershell and Mac OS users may be familiar with Terminal. All of
these tools allow a user to directly manipulate their system through the use of commands.
These commands can be chained together and/or combined together into complex scripts (see
the linux usage page on scripting) that can potentially complete tasks more efficiently than
much larger traditional software packages.
Terminal screenshot
You should be able to see the following prompt:
pi@raspberrypi ~ $
This shows your username and the hostname of the Pi. Here the username is pi and the
hostname is raspberrypi
Now, let's try running a command. Type pwd (present working directory) followed by the
Enter key. This should display something like /home/pi
ls result
The ls command lists the contents of the directory that you are currently in (your present
working directory). The -la component of the command is what's known as a 'flag'. Flags
modify the command that's being run. In this case the l displays the contents of the directory
in a list, showing data such as their sizes and when they were last edited, and the a displays
all files, including those beginning with a ., known as 'dotfiles'. Dotfiles usually act as
configuration files for software and as they are written in text, they can be modified by
simply editing them.
In order to navigate to other directories the change directory command, cd, can be used. You
can specify the directory that you want to go to by either the 'absolute' or the 'relative' path.
So if you wanted to navigate to the python_games directory, you could either do cd
/home/pi/python_games or just cd python_games (if you are currently in /home/pi). There are
some special cases that may be useful: ~ acts as an alias for your home directory, so
~/python_games is the same as /home/pi/python_games; . and .. are aliases for the current
directory and the parent directory respectively, e.g. if you were in /home/pi/python_games, cd
.. would take you to /home/pi
If you are writing the name of a file or directory as part of a command then pressing tab will
attempt to auto-complete the name of what you are typing. For example, if you have a file in
a directory called aLongFileName then pressing tab after typing a will allow you to choose
from all file and directory names beginning with a in the current directory, allowing you to
choose aLongFileName
Sudo
Some commands that make permanent changes to the state of your system require you to
have root privileges to run. The command sudo temporarily gives your account (if you're not
already logged in as root) the ability to run these commands, provided your user name is in a
list of users ('sudoers'). When you append sudo to the start of a command and press enter you
will be asked for your password, if that is entered correctly then the command you want to
run will be run using root privileges. Be careful though, some commands that require sudo to
run can irreparably damage your system so be careful!
Further information on sudo and the root user can be found on the linux root page
There are a few other commands that you may find useful, these are listed below:
cp makes a copy of a file and places it at the specified location (essentially doing a 'copy-
paste'), for example - cp file_a /home/other_user/ would copy the file file_a from your home
directory to that of the user other_user (assuming you have permission to copy it there). Note
that if the target is a folder, the filename will remain the same, but if the target is a filename,
it will give the file the new name
mv moves a file and places it at the specified location (so where cp performs a 'copy-paste',
mv performs a 'cut-paste'). The usage is similar to cp, so mv file_a /home/other_user/ would
move the file file_a from your home directory to that of the specified user. mv is also used to
rename a file, i.e. move it to a new location, e.g. mv hello.txt story.txt
rm removes the specified file (or directory when used with -r). Warning: Files deleted in this
way are generally not restorable
mkdir: This makes a new directory, e.g. mkdir new_dir would create the directory new_dir
in the present working directory
cat lists the contents of files, e.g. cat some_file will display the contents of some_file
Other commands you may find useful can be found in the commands page
Finding out about a command
To find out more information about a particular command then you can run the man followed
by the command you want to know more about (e.g. man ls). The man-page (or manual page)
for that command will be displayed, including information about the flags for that program
and what effect they have. Some man-pages will give example usage
Aim: To Study and Install IDE of Arduino and different types of Arduino.
This document explains how to connect your Uno board to the computer and upload your
first sketch. The Arduino Uno is programmed using the Arduino Software (IDE), our
Integrated Development Environment common to all our boards and running both online and
offline. For more information on how to get started with the Arduino Software visit
the Getting Started page
The Arduino Web Editor is hosted online, therefore it will always be up-to-date with the
latest features and support for all boards. Follow this simple guide to start coding on the
browser and upload your sketches onto your board
Connect your Uno board with an A B USB cable; sometimes this cable is called a USB
printer cable
The USB connection with the PC is necessary to program the board and not just to power it
up. The Uno automatically draw power from either the USB or an external power supply.
Connect the board to your computer using the USB cable. The green power LED
(labelled PWR) should go on
If you downloaded and expanded the Zip package or, for some reason, the board wasn't
properly recognized, please follow the procedure below
While in the Control Panel, navigate to System and Security. Next, click on System. Once the
System window is up, open the Device Manager
Look under Ports (COM & LPT). You should see an open port named "Arduino UNO
(COMxx)". If there is no COM & LPT section, look under "Other Devices" for "Unknown
Device"
Right click on the "Arduino UNO (COmxx)" port and choose the "Update Driver Software"
option
Select the serial device of the board from the 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 board and re-open the menu; the entry that disappears
should be the Arduino board. Reconnect the board and select that serial port.
A few seconds after the upload finishes, you should see the pin 13 (L) LED on the board start
to blink (in orange). If it does, congratulations! You've gotten Arduino up-and-running. If
you have problems, please see the troubleshooting suggestions
ZigBee is a wireless technology which provides connection between the devices. It is the
only open global standard to fulfill the needs of low cost, low power wireless network used
for device monitoring and control. The ZigBee standard is based on IEEE 802.15.4. It
operates in ISM (Industrial, Scientific, and Medical) radio bands which include 2.4 GHz, 784
MHz, 868MHz and 915 MHz. Data rate varies from 20 Kb/s to 250 Kb/s. It supports all
network topologies such as star,tree and mesh topology. Its transmission distance is limited to
10 to 100 meters line of sight. It depends on power output and environmental factors. It can
use long distance communication using intermediate devices. The data is passed through the
mesh network of intermediate devices and it reaches the distant devices. The devices are
secured by 128 bit symmetric encryption keys. So the networking is secure. ZigBee also
provides long battery life, so it can last for several years. It can be used in several
applications such as wireless light switches, smart grid, medical devices etc. It is simpler and
less expensive than Bluetooth, Wi-Fi etc. XBee and other XBee enabled devices provide
connection to several other devices
Arduino
It is a simple microcontroller board. It is an open source computing platform and has an
environment for developing software for the Arduino board. It can be used to make
computers. It is used to create interactive projects. It takes input from sensors or switches and
controls the outputs. Arduino boards are inexpensive compared to other microcontroller
based devices. It can stand-alone or can communicate with the software of the
computer. Arduino software can run on Windows, Linux and Macintosh OSX. It provides an
Integrated Development Environment (IDE) which is written on Java for programming
microcontrollers. It supports C, C++ programming languages. So anyone who knows the
basic programming C can easily access Arduino IDE. It is very simple. Arduino has built-in
functions. It can access serial port. It does not need to access the register details. It can simply
call the functions and easily perform the functions. So the coding and debugging are fast and
efficient. Arduino IDE displays the data which is into and out of the serial port
Configuration of ZigBee
To configure the ZigBee
First the ZigBee module must be connected to the computer using its serial adapter
For windows, puTTy or virtual terminal must be downloaded
The serial port of computer is set to 9600 baud rate, 8 data bits, 1 stop bit and no parity
Then click on the LOCAL ECHO BOX and click OK
The time session must be saved. Then click the CONNECT button of virtual terminal
After connection with ZigBee, the name of session is given
After these steps; the connection is occurred with the ZigBee module
The above code helps the ZigBee module to work according to the instructions sent by
Arduino. In the same way the ZigBee modules can receive instructions from other ZigBee
module also. For this case, the instructions or data is received from one ZigBee and this data
is sent through the serial pins of the Arduino. For that, one of the ZigBee must be connected
with the Arduino, and then the code which is given above is loaded to Arduino. After
uploading the code to the Arduino board, the Arduino board can be connected with the other
ZigBee module. After these all steps, the ZigBee modules can communicate with each other
Arduino
Aim: To write a map reduce program that mines weather data. Weather sensors collecting
data every hour at many locations across the globe gather a large volume of log data, which is
a good candidate for analysis with Map Reduce, since it is semi structured and record-
oriented
Resources:
PROGRAM LOGIC:
WordCount is a simple program which counts the number of occurrences of each word in a
given text input data set. WordCount fits very well with the MapReduce programming model
making it a great example to understand the Hadoop Map/Reduce programming style. Our
implementation consists of three main parts
1. Mapper
2. Reducer
3. Main program
Pseudo-code
A Reducer collects the intermediate output from multiple map tasks and assemble a single
result. Here, the WordCount program will sum up the occurrence of each word to pairs as
<word, occurrence>
Pseudo-code
void Reduce (max_temp,<list of value>)
{
for each x in<list of value>:
sum+=x;
final_output.collect(max_temp, sum);
}
void Reduce (min_temp,<list of value )
{
for each x in <list of value>:
sum+=x;
final_output.collect(min_temp, sum);
}
3. Write Driver
The Driver program configures and run the MapReduce job. We use the main program to
perform basic configurations such as:
Job Name : name of this Job Executable (Jar)
Class: the main executable class. For here, WordCount.
Mapper Class: class which overrides the "map" function. For here, Map.
Reducer: class which override the "reduce" function. For here , Reduce.
Aim: Data analytics using Apache Spark on Amazon food dataset, find all the pairs of items
frequently reviewed together. To write a single Spark application that Transposes the original
Amazon food dataset, obtaining a PairRDD of the type<user_id>→<list of the product_ ids
reviewed by user_id> Counts the frequencies of all the pairs of products reviewed together.
Writes on the output folder all the pairs of products that appear more than once and their
frequencies. The pairs of products must be sorted by frequency
In this lab, we continue our work on the Amazon dataset, using Apache Spark. Your task is
given the original Amazon food dataset, find all the pairs of items frequently reviewed
together
Apache Spark is an open-source, distributed processing system commonly used for big data
workloads
The input Amazon food dataset (available in the HFDS shared folder of the BigData@Polito
cluster: /data/students/bigdata-01QYD/Lab3/Reviews.csv) lists all the reviews per-row (one
review per line), and is comma-separated. In each line, two of the columns represent the user
id and product id. The schema of Reviews.csv is the following:
Id,ProductId,UserId,ProfileName,HelpfulnessNumerator,HelpfulnessDenominator,Score,Tim
e,Summary,Text Inspect the output of your application to search for interesting facts, and
analyze the job execution as usual (performances, number of executors, etc…).
Pay attention that the line starting with “Id,” is the header of the file and must not be
considered. On the web site you can download the file ReviewsSample.csv. It contains a
sample of Reviews.csv. You can use it to perform some initial tests locally.
Bonus task
Extend the implemented application in order to write on the standard output the top 10, most
frequent, pairs and their frequencies.
Note that Spark 1.6, or above, provides the following actions that can be applied on an RDD
of type JavaRDD<T>:
How to access logs by using the job history web page The logs of your applications on the
cluster is available at https://ma1-bigdata.polito.it:18489/ If there is any error and you need to
analyze the content of the error log files follow these
steps:
1. Open a new terminal on your local machine (do not use the previous terminal
connected to bigdatalab.polito.it).
2. On the local terminal command line, type the command kinit sXXXXXX (then, you
will be asked for your BigDataLab password) This command is used to obtain a
Kerberos ticket (without it you cannot access the log web page)
3. Now you should have access to the spark job history and logs at https://ma1-
bigdata.polito.it:18489/
4. Select your job and click on its App ID You can use the search box to select only your
jobs
5. Click on the executor tab and analyze the stderr associated with you application. Pay
attention that there is one log file for the driver and one log file for each executor. If
you application raised an exception, analyze all the stderr files to identify the reason
of the error (depending on the error type, the log containing the needed information
can be the one associated with the driver or that of an executor)
How to access logs without the web page and the Kerberos ticket
Aim: To write a program to Implement Bankers algorithm for Dead Lock Avoidance
Program:
#include<stdio.h>
struct file
{
int all[10];
int max[10];
int need[10];
int flag;
};
int main()
{
struct file f[10];
int fl;
int i,j,k,p,b,n,r,g,cnt=0,id,newr;
int avail[10],seq[10];
printf("Enter number of processes--");
scanf("%d",&n);
printf("Enter number of resources--");
scanf("%d",&r);
for(i=0;i<n;i++)
{
printf("Enter details for P%d",i);
printf("\nEnter allocation\t--\t");
for(j=0;j<r;j++)
scanf("%d",&f[i].all[j]);
printf("EnterMax\t\t--\t");
for(j=0;j<r;j++)
scanf("%d",&f[i].max[j]);
f[i].flag=0;
}
printf("\nEnter Available Resources\t--\t");
for(i=0;i<r;i++)
scanf("%d",&avail[i]);
printf("\nEnter New Request Details--");
printf("\nEnter pid\t--\t");
scanf("%d",&id);
printf("Enter Request for Resources\t--\t");
for(i=0;i<r;i++)
{
scanf("%d",&newr);
f[id].all[i]+=newr;
avail[i]=avail[i]-newr;
}
for(i=0;i<n;i++)
for(j=0;j<r;j++)
{
f[i].need[j]=f[i].max[j]-f[i].all[j];
if(f[i].need[j]<0)
f[i].need[j]=0;
}
}
cnt=0;
fl=0;
while(cnt!=n)
{
g=0;
for(j=0;j<n;j++)
{
if(f[j].flag==0)
{
b=0;
for(p=0;p<r;p++)
{
if(avail[p]>=f[j].need[p])
b=b+1;
else
b=b-1;
}
if(b==r)
{
printf("\nP%disvisited",j);
seq[fl++]=j;
f[j].flag=1;
for(k=0;k<r;k++)
avail[k]=avail[k]+f[j].all[k];
cnt=cnt+1;
printf("(");
for(k=0;k<r;k++)
printf("%3d",avail[k]);
printf(")");
g=1;
}
}
}
if(g==0)
{
printf("\nREQUESTNOTGRANTED--DEADLOCKOCCURRED");
printf("\nSYSTEM IS IN UNSAFE STATE");
goto y;
}
}
printf("\nSYSTEMISINSAFESTATE");
printf("\nTheSafeSequenceis--(");
for(i=0;i<fl;i++)
printf("P%d",seq[i]);
printf(")");
y: printf("\nProcess\t\tAllocation\t\tMax\t\t\tNeed\n");
for(i=0;i<n;i++)
{
printf("P%d\t",i);
for(j=0;j<r;j++)
printf("%6d",f[i].all[j]);
for(j=0;j<r;j++)
printf("%6d",f[i].max[j]);
for(j=0;j<r;j++)
printf("%6d",f[i].need[j]);
printf("\n");
}
return 0;
}
Output:
Enter number of processes--5
Enter number of resources--3
Enter details for P0
Enter allocation -- 010
EnterMax -- 753
Enter details for P1
Enter allocation -- 200
EnterMax -- 322
Enter details for P2
Enter allocation -- 302
EnterMax -- 902
Enter details for P3
Enter allocation -- 211
EnterMax -- 222
Enter details for P4
Enter allocation -- 002
EnterMax -- 433
P1isvisited( 5 3 2)
P3isvisited( 7 4 3)
P4isvisited( 7 4 5)
P0isvisited( 7 5 5)
P2isvisited( 10 5 7)
SYSTEM IS IN SAFE STATE
The Safe Sequenceis--(P1P3P4P0P2)
Process Allocation Max Need
P0 0 1 0 7 5 3 7 4 3
P1 3 0 2 3 2 2 0 2 0
P2 3 0 2 9 0 2 6 0 0
P3 2 1 1 2 2 2 0 1 1
P4 0 0 2 4 3 3 4 3 1
Program:
#include<stdio.h>
int main()
{
int buffer[10],bufsize,in,out,produce,consume,choice=0;
in=0;
out=0;
bufsize=10;
while(choice!=3)
{
printf("\n1.Produce\t2.Consume\t3.Exit");
printf("\nEnteryourchoice:");
scanf("%d",&choice);
switch(choice)
{
case 1:if((in+1)%bufsize==out)
printf("\nBufferisFull");
else
{
printf("\nEnter the value:");
scanf("%d",&produce);
buffer[in]=produce;
in=(in+1)%bufsize;
}
break;
case 2:if(in==out)
printf("\nBuffer is Empty");
else
{
consume=buffer[out];
printf("\nThe consumed value is:%d",consume);
out=(out+1)%bufsize;
}
break;
}
}
return 0;
}
Output:
Buffer is Empty
1.Produce 2.Consume 3.Exit
Enteryourchoice:1
Program:
package ocv;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class Main
{
public static void main( String[] args )
{
try
{
// For proper execution of native libraries
// Core.NATIVE_LIBRARY_NAME must be loaded before
// calling any of the opencv methods
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
//input image
Mat source = Imgcodecs.imread("E:\\input.jpg",
Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
Mat destination = new Mat(source.rows(),
source.cols(), source.type());
// applying histogram equalization
Imgproc.equalizeHist(source, destination);
// writing output image
Imgcodecs.imwrite("E:\\output.jpg", destination);
}
catch (Exception e)
{
System.out.println("error: " + e.getMessage());
}
}
}
Aim: To write a Program to enhance image using image arithmetic and logical operations
Program:
Input(i):
Input(ii):
Output:
Input(i)
Image(2)
Output:
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
int a[20],b[30],i,j,k,count,n;
printf("Enter frame size (Example: 8):");
scanf("%d",&n);
printf("Enter the frame in the form of 0 and 1 :");
for(i=0; i<n; i++)
scanf("%d",&a[i]);
i=0;
count=1;
j=0;
while(i<n)
{
if(a[i]==1)
{
b[j]=a[i];
for(k=i+1; a[k]==1 && k<n && count<5; k++)
{
j++;
b[j]=a[k];
count++;
if(count==5)
{
j++;
b[j]=0;
}
i=k;
}
}
else
b[j]=a[i];
i++;
j++;
}
printf("After Bit Stuffing :");
for(i=0; i<j; i++)
printf("%d",b[i]);
return 0;
}
Output
Aim: To write a program to configure a Network using Distance Vector Routing protocol
Program:
#include<stdio.h>
struct node
{
unsigned dist[20];
unsigned from[20];
}rt[10];
int main()
{
int costmat[20][20];
int nodes,i,j,k,count=0;
printf("\nEnter the number of nodes : ");
scanf("%d",&nodes);//Enter the nodes
printf("\nEnter the cost matrix :\n");
for(i=0;i<nodes;i++)
{
for(j=0;j<nodes;j++)
{
scanf("%d",&costmat[i][j]);
costmat[i][i]=0;
rt[i].dist[j]=costmat[i][j];//initialise the distance equal to cost
matrix
rt[i].from[j]=j;
}
}
do
{
count=0;
for(i=0;i<nodes;i++)
for(j=0;j<nodes;j++)
for(k=0;k<nodes;k++)
if(rt[i].dist[j]>costmat[i][k]+rt[k].dist[j])
{
rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];
rt[i].from[j]=k;
count++;
}
}while(count!=0);
for(i=0;i<nodes;i++)
{
printf("\n\n For router %d\n",i+1);
for(j=0;j<nodes;j++)
printf("\t\nnode %d via %d Distance %d ",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
printf("\n\n");
return 0;}
Output
For router 1
For router 2
For router 3
Aim: To perform the function oriented diagram: DFD and Structured chart
Data-flow diagrams are a useful and intuitive way of describing a system. They are generally
understandable without specialized training, notably if control information is excluded. They
show end-to-end processing. That is the flow of processing from when data enters the system
to where it leaves the system can be traced.
Data-flow design is an integral part of several design methods, and most CASE tools support
data-flow diagram creation. Different ways may use different icons to represent data-flow
diagram entities, but their meanings are similar
Data Dictionaries:
A data dictionary lists all data elements appearing in the DFD model of a system. The data
items listed contain all data flows and the contents of all data stores looking on the DFDs in
the DFD model of a system.
A data dictionary lists the objective of all data items and the definition of all composite data
elements in terms of their component data items. For example, a data dictionary entry may
contain that the data grossPay consists of the parts regularPay and overtimePay.
grossPay = regularPay + overtimePay
For the smallest units of data elements, the data dictionary lists their name and their type.
A data dictionary plays a significant role in any software development process because of the
following reasons:
o A Data dictionary provides a standard language for all relevant information for use by
engineers working in a project. A consistent vocabulary for data items is essential
since, in large projects, different engineers of the project tend to use different terms to
refer to the same data, which unnecessarily causes confusion.
o The data dictionary provides the analyst with a means to determine the definition of
various data structures in terms of their component elements.
Structured Charts:
It partitions a system into block boxes. A Black box system that functionality is known to
the user without the knowledge of internal design.
Program:
Software requirement is a functional or non-functional need to be implemented in the system.
Functional means providing particular service to the user.
For example, in context to banking application the functional requirement will be when
customer selects "View Balance" they must be able to look at their latest account balance.
Software requirement can also be a non-functional, it can be a performance requirement. For
example, a non-functional requirement is where every page of the system should be visible to
the users within 5 seconds.
So, basically software requirement is a
● Functional or
● Non-functional
Analyze Requirements:
Consider example of an educational software system where a student can register for
different courses.
Lets study how to analyze the requirements. The requirements must maintain a standard
quality of its requirement, different types of requirement quality includes
● Atomic
● Uniquely identified
● Complete
● Consistent and unambiguous
● Traceable
● Prioritized
● Testable
A purpose
An overall description
Specific requirements
It’s used to provide critical information to multiple teams — development, quality assurance,
operations, and maintenance. This keeps everyone on the same page.
Using the SRS helps to ensure requirements are fulfilled. And it can also help you make
decisions about your product’s lifecycle — for instance, when to retire a feature.
Writing an SRS can also minimize overall development time and costs. Embedded
development teams especially benefit from using an SRS.
Here are five steps you can follow to write an effective SRS document.
1. Create an Outline (Or Use an SRS Template) Your first step is to create an outline for
your software requirements specification. ...
2. Start With a Purpose. ...
3. Give an Overview of What You'll Build. ...
4. Detail Your Specific Requirements. ...
5. Get Approval for the SRS.
Aim: To write a program to draw the structural view diagram: Class diagram, object diagram
Class Diagram:
⮚ It shows a set of classes, interfaces, and collaborations and their relationships.
⮚ Graphically a class diagram is a collection of vertices and arcs. The relationships used
here are dependency, generalization, association, aggregation.
(i) Dependency:
❖ It is using relationship. Change in one thing may effect in another thing.
❖ Graphically rendered by dashed directed line.
(ii) Generalization:
❖ It is a “is-a-kind-of” relationship. Relationship between general thing and specific
thing (or) Relationship between super class and sub class.
❖ Graphically rendered solid directed line with a large open arrowhead.
(iii) Association:
❖ It is a structural relationship. Objects of one thing are connected to objects of
another thing. Graphically rendered by solid line.
(iv) Aggregation:
❖ It is a structural relationship. It is defined as whole / part relationship.
❖ Graphically rendered as directed line with open diamond shape at one end.
(v) Realization:
❖ It is a semantic relationship. One classifier specifies a contract and another classifier
guarantees to carry out that contract.
❖ Graphically rendered as dashed directed line with a large open arrow head.
Structural diagrams:
❖ These diagrams are static.
❖ There are four structural diagrams
1. Class diagram:
❖ It specifies classes, interfaces, collaborations and relationships
2. Object diagram:
❖ It specifies objects and relationships
3. Component diagram:
❖ It specifies components and relationships
4. Deployment diagram:
❖ It specifies Runtime processing nodes and relationships
Object Diagram:
⮚ An object diagram is a diagram that shows a set of objects and their relationships.
⮚ Graphically an object diagram is a collection of vertices and arcs. It represents objects
and links.
⮚ The object diagram is shown below
Program:
#include <stdio.h>
#include <math.h>
int main()
{
int a,b,g,i,j,x,y;
char ch = 'y';
do
{
puts("\nShow that (!(x < 5) && !(y >= 7)) and !((x < 5) || (y >= 7)) are
logically equivalent\n\n");
printf("%s", "Enter x: ");
scanf("%2u", &x);
printf("%s", "Enter y: ");
scanf("%2u", &y);
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');
if (ch == 'n')
{
do
{
puts("\nShow that (!(a == b) || !(g != 5)) and !((a == b) && (g != 5))
are logically equivalent\n\n");
printf("%s", "Enter a: ");
scanf("%2u", &a);
printf("%s", "Enter b: ");
scanf("%2u", &b);
printf("%s", "Enter g: ");
scanf("%2u", &g);
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');
if (ch == 'n')
{
do
{
puts("\nShow that !((x <= 8) && (y > 4)) and (!(x <= 8) || !(y > 4)) are
logically equivalent\n\n");
printf("%s", "Enter x: ");
scanf("%2u", &x);
printf("%s", "Enter y: ");
scanf("%2u", &y);
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");
printf("%s", "Enter i: ");
scanf("%2u", &i);
printf("%s", "Enter j: ");
scanf("%2u", &j);
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');
}
if (ch == 'n')
printf("\n%s", "Now you know DeMorgan's Laws!");
return 0;
}
Output
Show that (!(x < 5) && !(y >= 7)) and !((x < 5) || (y >= 7)) are logically equivalent
Enter x: 5
Enter y: 7
False!
Show that (!(x < 5) && !(y >= 7)) and !((x < 5) || (y >= 7)) are logically equivalent
Enter x: 2
Enter y: 9
False!
Show that (!(x < 5) && !(y >= 7)) and !((x < 5) || (y >= 7)) are logically equivalent
Enter x: 5
Enter y: 6
False!
Show that (!(x < 5) && !(y >= 7)) and !((x < 5) || (y >= 7)) are logically equivalent
Enter x: 8
Enter y: 6
True!
Show that (!(a == b) || !(g != 5)) and !((a == b) && (g != 5)) are logically equivalent
Enter a: 4
Enter b: 4
Enter g: 5
True!
Show that !((x <= 8) && (y > 4)) and (!(x <= 8) || !(y > 4)) are logically equivalent
Enter x: 3
Enter y: 5
False!
Show that !((x <= 8) && (y > 4)) and (!(x <= 8) || !(y > 4)) are logically equivalent
Enter x: 2
Enter y: 6
False!
Show that !((i > 4) || (j <= 6)) and (!(i > 4) && !(j <= 6)) are logically equivalent
Enter i: 4
Enter j: 5
False!
Show that !((i > 4) || (j <= 6)) and (!(i > 4) && !(j <= 6)) are logically equivalent
Enter i: 6
Enter j: 7
False!
EXPERIMENT 8:
AIM: To write a C program to implement memory management using paging technique
SOURCE CODE:
#include <stdio.h>
#include<unistd.h>
void main()
{
int b[20],n,i,pa,p,a,d;
printf(“\nProgram for
paging”); scanf(“%d”,&n);
printf(“\nEnter the base
address:”); for(i=0;i<n;i++)
{
scanf(“%d”,&b[i]);
}
printf(“\nEnter the logical
address:”); scanf(“%d”,&p);
for(i=0;i<n;i++)
{
if(i==p)
{
pa=
b[i]
+d;
a=b[
i];
printf(“\n\tPageNo.\t BaseAdd. PhysicalAdd. \n\t %d \t %d \t
%d \t ”,p,a,pa);
}
}
printf(“\nInvalid page”);
}
OUTPUT
Program for paging
Enter the number of
pages:2 Enter the
base address:
100
150
Enter the Logical
address:50 Enter the
page number:1
Sample Output 1:
PageNo.
BaseAdd.PhysicalAdd. 1
150 200
Sample Input 2:
Program for paging
Enter the number of
pages:1 Enter the
base address:
100
Enter the Logical
address:2 Enter the
page number:2
Sample Output 2:
Invalid page.
EXPERIMENT 9:
AIM: To write a C program to implement memory management using segmentation
SOURCE CODE:
#include <stdio.h>
#include<unistd.h>
void main()
{
int b[20],l[20],n,i,pa,s,a,d; printf(“\
nProgram for segmentation”);
printf(“\nEnter the number of
segments:”); scanf(“%d”,&n);
printf(“\nEnter the base address and limit
register:”); for(i=0;i<n;i++)
{
scanf(“%d”,&b[i]);
scanf(“%d”,&l[i])
}
printf(“\nEnter the logical
address:”); scanf(“%d”,&d);
for(i=0;i<n;i++)
{
if(i==s)
{
if(d<l[i])
{
pa=
b[i]
+d;
a=b[
i];
printf(“(“\n\tPageNo.\t BaseAdd. PhysicalAdd. \n\t %d \t %d \t%d \t ”,s,a,pa); exit(0);
}
Else
{
Printf(“\n
Pagesize exceeds”);
exit(0);
}}}
Printf(“Invalid
segment”);
}
OUTPUT:
Sample Input 1:
Program for
segmentation Enter the
number ofsegments:3
Enter the base address and limit register:
100 50
150 20
130 34
Enter the Logical
address:25
Enter the segment
number:1
Sample Output 1:
PageNo. BaseAdd.
PhysicalAdd.
2 130 155
Sample Input 2:
Program for
segmentation Enter the
number ofsegments:2
Enter the Logical address and limit register:
100 50
150 20
Enter the logical
address:25 Enter the
segment number:1
Sample Output 2:
page size exceeds