KCS653
KCS653
KCS653
LAB MANUAL
Computer Network
(KCS-653)
To be an excellent department that imparts value based quality education and uplifts
innovative research in the ever-changing field of technology.
Mission of Department
1. Students will have the successful careers in the field of computer science and
allied sectors as an innovative engineer.
2. Students will continue to learn and advance their careers through participation
in professional activities, attainment of professional certification and seeking
advance studies.
3. Students will be able to demonstrate a commitment to life-long learning.
4. Students will be ready to serve society in any manner and become a responsible
and aware citizen.
5. Establishing students in a leadership role in any field.
Program Outcomes
1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering
problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems
and design system components or processes that meet the specified needs with
appropriate consideration for the public health and safety, and the cultural, societal,
and environmental considerations
4. Conduct investigations of complex problems: Use research-based knowledge and
research methods including design of experiments, analysis and interpretation of data,
and synthesis of the information to provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.
7. Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of,
and need for sustainable development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and norms of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or
leader in diverse teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend
and write effective reports and design documentation, make effective presentations,
and give and receive clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a
member and leader in a team, to manage projects and in multidisciplinary
environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to
engage in independent and life-long learning in the broadest context of technological
change.
Program Specific Outcomes
1. Ability to apply and analyze computational concepts in the areas related to
algorithms, machine learning, cloud computing, web designing and web
services.
2. Ability to apply standard practices and methodologies in software development
and project management.
3. Ability to employ fundamental concepts and emerging technologies for
innovative research activities, carrier opportunities & zeal for higher studies.
Course Outcomes
To implement the basic concepts of python programming like math function, Strings, List,
CO-1 Tuple and Dictionary
Procedure: Python provides a getopt module that helps you parse command-line
options and arguments.
$ python test.py arg1 arg2 arg3
The Python sys module provides access to any command-line arguments via
the sys.argv. This serves two purposes −
sys.argv is the list of command-line arguments.
len(sys.argv) is the number of command-line arguments.
Here sys.argv[0] is the program ie. script name.
Result −
Program-1(b)
Input:
9
Output:
3
Program 2(a)
Input:
Enter base: 7
Output:
49
Program-2(b)
Input:
M=12, N=17
Output:
Program-2(C)
Input:
Output:
2 3 5 7 11 13 17 19
Program-3(a)
Input:
Output-
Max=99
Program 3(b)
Object: To write a python program to perform Matrix Multiplication.
Algorithm:
1. Define two matrices X and Y
2. Create a resultant matrix named ‘result’
3. for i in range(len(X)):
for j in range(len(Y[0])):
a) for k in range(len(Y))
b) result[i][j] += X[i][k] * Y[k][j]
4. for r in result, print the value of r
Input:
# 3x3 matrix
# 3x4 matrix
Output:
Program-4
Object: To write a python program to find the most frequent words in a text
file.
Algorithm:
Input:
Let us consider you have a text file with contents like this
Output:
Program 5(a)
Input:
Output:
Program-5(b)
Object: To write a python program Binary search.
Algorithm:
Input:
x =10
Output:
Program-6(a)
Input:
Output:
Program-6(b)
Step 4 − Shift all the elements in the sorted sub-list that is greater than the value to be sorted
Input:
Output:
Program-7
Object: To write a python program Merge sort.
Merge Sort is a Divide and Conquer algorithm. It divides input array in two halves,
calls itself for the two halves and then merges the two sorted halves. The merge ()
function is used for merging two halves. The merge (arr, l, m, r) is key process
that assumes that arr[l..m] and arr[m+1..r] are sorted and merges the two sorted
sub-arrays into one. See following C implementation for details.
MergeSort(arr[], l, r)
If r > l
Call mergeSort(arr, l, m)
Call merge(arr, l, m, r)
Input:
Given array is
12 11 13 5 6 7
Output:
Sorted array is
5 6 7 11 12 13
Program 8
Object: To write a python program to simulate bouncing ball in Pygame.
ALGORITHM:
STEP 1: Define the class Ball and initialize the screen background, image and the
circle for the ball.
STEP 2: Define the functions for update and for checking the boundary for the ball
to hit
STEP 3: Define the main function for the actual bouncing ball simulation
Output:
Procedure:
Creating Classes
The class statement creates a new class definition. The name of the class immediately follows the
keyword class followed by a colon as follows −
class ClassName:
class_suite
The class has a documentation string, which can be accessed via ClassName. doc .
The class_suite consists of all the component statements defining class members, data attributes
and functions.
To create instances of a class, you call the class using class name and pass in whatever arguments
its init method accepts.
Accessing Attributes
You access the object's attributes using the dot operator with object. Class variable would be accessed
using class name as follows −
emp1.displayEmployee()
emp2.displayEmployee()
Instead of using the normal statements to access attributes, you can use the following functions
Every Python class keeps following built-in attributes and they can be accessed using dot operator like
any other attribute −
Python deletes unneeded objects (built-in types or class instances) automatically to free the memory
space. The process by which Python periodically reclaims blocks of memory that no longer are in use is
termed Garbage Collection.
Python's garbage collector runs during program execution and is triggered when an object's reference
count reaches zero. An object's reference count changes as the number of aliases that point to it changes.
An object's reference count increases when it is assigned a new name or placed in a container (list, tuple,
or dictionary). The object's reference count decreases when it's deleted with del, its reference is
reassigned, or its reference goes out of scope. When an object's reference count reaches zero, Python
collects it automatically.
<40>
You normally will not notice when the garbage collector destroys an orphaned instance and reclaims its
space. But a class can implement the special method del (), called a destructor, that is invoked when
the instance is about to be destroyed. This method might be used to clean up any non-memory resources
used by an instance.
Procedure:
Class Method
class C(object):
@classmethod
....
A class method is a method which is bound to the class and not the object of the
class.
They have the access to the state of the class as it takes a class parameter that
points to the class and not the object instance.
It can modify a class state that would apply across all the instances of the class.
For example it can modify a class variable that will be applicable to all the
instances.
Static Method
A static method does not receive an implicit first argument.
Syntax:
class C(object):
@staticmethod
...
A static method is also a method which is bound to the class and not the object of
the class.
A static method can’t access or modify class state.
It is present in a class because it makes sense for the method to be present in class.
Types of constructors:
Class Inheritance:
Instead of starting from scratch, you can create a class by deriving it from a pre-
existing class by listing the parent class in parentheses after the new class name.
The child class inherits the attributes of its parent class, and you can use those
attributes as if they were defined in the child class. A child class can also override
data members and methods from the parent.
Syntax
Derived classes are declared much like their parent class; however, a list of base
classes to inherit from is given after the class name –
class_suite
Objective:Concept of polymorphism in python(method overloading and
overriding)
Sometimes an object comes in many types or forms. If we have a button, there are
many different draw outputs (round button, check button, square button, button
with image) but they do share the same logic: onClick(). We access them using the
same method. This idea is called Polymorphism.
Polymorphism is based on the greek words Poly (many) and morphism (forms).
We will create a structure that can take or use many forms of objects.
Overriding Methods
You can always override your parent class methods. One reason for overriding
parent's methods is because you may want special or different functionality in your
subclass.
Example:
class Bear(object):
def sound(self):
print "Groarrr"
class Dog(object):
def sound(self):
def makeSound(animalType):
animalType.sound()
bearObj = Bear()
dogObj = Dog()
makeSound(bearObj)
makeSound(dogObj)
Output:
Groarrr
Woof woof!