31
Laboratory Manual Department of Computer Science Aligarh Muslim University Aligarh 2017-18 B.Sc. II Semester Laboratory CourseII (CCB-2P1) (Computer Applications)

Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

Embed Size (px)

Citation preview

Page 1: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

La

bo

ra

tor

y M

an

ua

l

Department of Computer Science

Aligarh Muslim University Aligarh

2017-18

B.Sc.

II Semester

Laboratory Course—II (CCB-2P1)

(Computer Applications)

Page 2: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

CREDITS

Lab Manual Design Committee:

Prof. Mohammad Ubaidullah Bokhari

Dr. Arman Rasool Faridi

Dr. Faisal Anwar

Dr. Aasim Zafar (Convener)

The Committee thankfully acknowledges the efforts and contributions of the following

teachers:

Dr. Mohammad Sajid

Editor:

Dr. Aasim Zafar

Design & Compilation:

Mr. Sunil Kumar Sharma

First Edition: July 2017

Approved by BoS, Dated– 31/07/2017

Department of Computer Science, A.M.U., Aligarh, (U.P.), India

Page 3: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 2 A

MU

AM

U

CS

D

COURSE TITLE: Laboratory Course-II COURSE CODE: CCB – 2P1

CREDIT: 02 PERIODS PER WEEK: 03

CONTINUOUS ASSESSMENT: 40 EXAMS: 60

COURSE DESCRIPTION

This manual is intended for the Second year students in the

subject of Programming with Python. This manual typically contains

practical/Lab Sessions related to Programming with Python covering

various aspects in order to enhance subject understanding.

Python is a general purpose, high-level programming language;

other high-level languages you might have heard of C++, PHP, and

Java. Virtually all modern programming languages make us of an

Integrated Development Environment (IDE), which allows the

creation, editing, testing, and saving of programs and modules. In

Python, the IDE is called IDLE (like many items in the language, this is a

reference to the British comedy group Monty Python, and in this case,

one of its members, Eric Idle).

Many modern languages use both processes. They are first

compiled into a lower level language, called byte code, and then

interpreted by a program called a virtual machine. Python uses both

processes, but because of the way programmers interact with it, it is

usually considered an interpreted language.

There are two ways to use the Python interpreter: shell mode and

script mode. In shell mode, you type Python statements into the Python

shell and the interpreter immediately prints the result. In script mode,

you type statements into the editor and save it in a file known as script.

The interpreter executes the code of the script.

Page 4: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 3 A

MU

AM

U

CS

D

Students are advised to thoroughly go through this manual rather

than only topic mentioned in the syllabus as practical aspects are

the key to understanding and conceptual visualization of theoretical

aspects covered in the books.

Also, this course is designed to review the concepts of Data

Structure using C, studied in previous semester and implement the

various algorithms related to different data structures. Good Luck for

your Enjoyable Laboratory Sessions.

CONTENT

This course is designed to provide the students the opportunity of

learning both – concepts of C, implementing algorithms of data

structures and programming with Python. This course is indented to

develop a deep understanding of various operations on data structure

such as searching, sorting, insertion, deletion and traversing and

provides students the idea of new programming language. Apart from

basic concepts, it helps to understand the concept of lists, tuples,

dictionaries and file handling.

OBJECTIVES

This course is designed to help students in:

Learning the concepts of different data structures using C.

Learning different sorting (Bubble Sort, Insertion Sort, Merge

Sort, Heap Sort, Quick Sort) and searching (Linear and Binary)

techniques using C.

Learning Linked List, Queue, Stack and their operations using C.

Page 5: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 4 A

MU

AM

U

CS

D

Learning non-linear data structures such as Binary Tree, Binary

Search Tree etc. and their operations using C.

Learning Graphs and their operations using C.

Learning Python programming

OUTCOMES

After completing this course, the students would be able to:

Understand and implement the different data structure using C.

Understand and implement different sorting (Bubble Sort,

Insertion Sort, Merge Sort, Heap Sort, Quick Sort) and

searching (Linear and Binary) techniques using C.

Understand and implement Linked List, Queue, Stack and their

operations using C.

Understand and implement non-linear data structures such as

Binary Tree, Binary Search Tree etc. and their operations using

C.

Understand and implement Graphs and their operations using C.

Write, debug and execute Python programs to solve various

problems.

RULES AND REGULATIONS

Students are required to strictly adhere to the following rules.

Page 6: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 5 A

MU

AM

U

CS

D

The students must complete the weekly activities/assignments

well in time (i.e., within the same week).

The students must maintain the Lab File of their completed

activities/assignments in the prescribed format (Appendix-1).

The students must get the completed weekly

activities/assignments checked and signed by the concerned

teachers in the Lab in the immediate succeeding week. Failing

which the activities/assignments for that week will be treated as

incomplete.

At least TEN (10) such timely completed and duly signed weekly

activities/assignments are compulsory, failing which students will

not be allowed to appear in the final Lab Examination.

The students need to submit the following three deliverables for

each exercise duly signed by the Teacher:

Algorithm

Flow Chart

Coding

Input /Output

Each question will be evaluated on a scale of 10 points, 4 for

Algorithm, 3 for Flow Chart and 3 for Coding part.

The students need to ensure that each question is assessed and

signed by the Teacher in the week/time.

Late submission would not be accepted after the due date.

Cooperate, collaborate and explore for the best individual

learning outcomes but copying is strictly prohibited.

Page 7: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

APPENDIX-1

Template for the Index of Lab File W

EE

K N

O.

PROBLEMS WITH DESCRIPTION

PA

GE

NO

. SIGNATURE

OF THE

TEACHER

WITH DATE

1

1#

2#

3#

2

1#

2#

3#

3

1#

2#

3#

4

1#

2#

3#

Note: The students should use Header and Footer mentioning their roll no. & name in footer and page no in header.

Page 8: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

WEEK #1

To understand concept of control construct, arrays,

recursion, string functions and pointers in C.

To learn the following in Shell and Script mode:-

The basic printing command is print.

Different operators (+, -, *, /, %).

Integer and floating number arithmetic.

PEDMAS Law.

After completing this, the students would be able:

to understand the concepts of control construct arrays,

recursion, string functions and pointers in C.

to write and run a simple Python statement/ programs

in Shell and Script mode.

Note: When naming a Python program, a .py extension must be used. Failing

to do so will result in code that will not be recognized by the system as a Python

program.

1# Scenario: A courier company has number of items to be delivered to its

intended customers through its salesman. The salesman visits following cities

to deliver the respective items:

S. NO. CITIES NO. OF ITEMS

1. Aligarh 18

2. Agra 25

OU

TC

OM

ES

PROBLEMS

S

OB

JE

CT

IVE

S

Page 9: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 8 A

MU

AM

U

CS

D

3. Baroda 13

4. Banaras 43

5. Chennai 8

6. New Delhi 67

7. New Jalpaiguri 29

8. Howrah 11

9. Kolkata 56

10. Mumbai 33

Solve the following problems based on the above mentioned scenario

using C:

a) Write a program to store and display the above mentioned cities and

corresponding items using arrays.

b) Write a program to display name of cities where salesman has delivered

maximum and minimum number of items.

c) Write a program to search the number of items to be delivered of a user

supplied city.

2# Use interactive Shell to print the Hello

Example: print „Hello, World‟

3# Start the Python interpreter and use it as a calculator i.e. Use interactive shell

to perform the following operations

2 + 3, 5*3, 7-2, 6/2, 6/4, 6%4, 6%2, 2*4-3, 4-2*6-4

4# Write a program in Python programming and save it firstProgram.py to

perform the following operations:

2 + 3, 5*3, 7-2, 6/2, 6/4, 6%4, 6%2

5# Write a program in Python programming and save it second Program.py to

display the following messages

“Hello World, Python is High level, General-purpose Programming

language”

“ Guido Van Rossum invented the Python programming language in 1990s”

.

Page 10: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 9 A

MU

AM

U

CS

D

WEEK #2

To understand concept of control construct, arrays,

recursion, string functions and pointers using C

(continues...).

To learn different data types (int, float and string) in

Python.

To learn the rules to define variables in Python.

To learn the use of Assignment (=) and comparison (==)

operators in Python.

To learn the special use of + for string concatenation in

Python.

To learn the basic input receiving command is raw_input

in Python.

After completing this, the students would be able:

to understand the concepts of control construct arrays,

recursion, string functions and pointers using C

(continues...). to learn how to input character, variables/keywords,

evaluate expressions.

Note: To Learn three basic types of simple variables in Python: integers (whole

numbers, commonly used as an index), floats (that is, numbers with a decimal

point, AKA real numbers), and strings (collections of alphanumeric characters

such as names, sentences, or numbers that are not manipulated

mathematically such as a part number or zip code).

The first assignment to a variable creates it. The variable types don’t need to be

declared. Python figures out the variable types on its own.

OU

TC

OM

ES

OB

JE

CT

IVE

S

Page 11: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 10 A

MU

AM

U

CS

D

1# Based on the previous scenario, do the followings using C:

a) Write a program to find total number of items delivered using recursive

function additem().

b) Write a program to display name of the cities along with their length, and

identity cities composed of two words.

c) The number of items of „Agra‟ and „Kolkata‟ are accidently interchanged.

Correct them by writing a swap function using pointers.

2# Write a program to find SUM and MULTIPLY of any three numbers.

3# Write a program to find the average of any five numbers.

4# Write a program to find simple interest.

5# Write a program to convert Celsius into Fahrenheit temperature.

6# Write a program to find perimeter of Rectangle.

7# Write a program to find circumference of Circle.

8# The volume of a sphere with radius r is 43 πr3. Write a Python program

which accepts the radius of a sphere and computes the volume. What is the

volume of a sphere with radius 5?

9# Suppose the cover price of a book is Rs 240.95, but bookstores get a 40%

discount. Shipping costs Rs 30 for the first copy and 75 cents for each

additional copy. What is the total wholesale cost for 60 copies?

10# Write a Python program which accepts the radius of a circle from the user

and compute the area.

PROBLEMS

S

Page 12: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 11 A

MU

AM

U

CS

D

WEEK #3

To understand concept of class, inheritance, operator

overloading and file handling using C.

To learn the concept of function in Python.

To learn Built-in functions: Type conversion and Math

functions in Python.

To learn the user-defined functions: Definitions and use

in Python.

To learn the Function: Flow of execution, parameters and

arguments and fruitful and void functions in Python.

After completing this, the students would be able:

to understand the concepts of class, inheritance,

operator overloading and file handling using C .

to write, debug and run a simple Python functions.

to learn how to define user-defined functions and pass

arguments to functions in Python.

1# Scenario: A university has different entities such as Department, Programs

and Student whose data members and member functions are given below:

Teacher- { Data Members: Name, department, hours, programsTaught;

Member Function: setDetails(), getDetails()}

Program- {Data Members: Name, department, duration;

Member Functions: setDetails(), getDetails()}

Student- {Data Members: Name, RollNo, Program, Department}

Member Function: setDetails(), getDetails()}

OU

TC

OM

ES

PROBLEMS

S

OB

JE

CT

IVE

S

Page 13: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 12 A

MU

AM

U

CS

D

Solve the following problems based on the above mentioned scenario

using C:

a) Write a program to create Teacher, Program and Student Classes with above

mentioned data members and member functions.

b) Add following functionalities in the above program; the default

department of Teacher, Program and Student should be „Computer Science‟;

however a different department could be assigned at run time.

c) Write a program to overload „+‟ operator to add the hours of two teachers.

d) Write a program to create two subclasses „Residential Student‟ and „Non-

Residential Student‟ inherited from Student class. „Residential Student‟ would

have a data member „Hall of Residence‟ and „Non-Residential Student‟ would

have „Address‟ as its data member.

2# Write a Python program which accepts the inputs from the user and do

the following using functions.

a) To find largest of 3 numbers.(Function)

b) To generate first 4th Fibonacci term.(function)

c) To compute factorial of an integer n recursively.(function)

d) To find volume of cylinder or cube or rectangular box.

e) To find area of rectangle.

f) To find circumference of circle.(Using constructor)

g) To exchange the values of two variables

h) To find the distance between two points.

Page 14: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 13 A

MU

AM

U

CS

D

WEEK #4

To understand concept of class, inheritance, operator

overloading and file handling using C (continues…).

To learn Boolean Expression in Python.

To learn the logical operators, relational operators.

To learn the Conditional (if), Alternative (if-else).

To learn the Chained conditional (if-elif-else), Nested

Conditional.

After completing this, the students would be able:

to understand the concepts of class, inheritance, operator

overloading and file handling using C(continues…).

to write, debug and run a simple Python programs based on

conditions.

1# Based on the previous scenario, do the followings:

a) Write a friend function to determine number of hours taught by a particular

teacher.

b) Write a program to store details of Teacher, Program and Student, each in a

separate file.

c) Write a program to read details of Student from file whose Roll No is given by

the user?

2# Write a program to find the greatest of three numbers.(use only if Statement)

3# Write a program to find smallest of three number.(use if and else statement)

4# Write a program to check the given no that is even or odd.(use if and else)

5# Write a program to check a year for leap year.( use if and else)

OU

TC

OM

ES

PROBLEMS

S

OB

JE

CT

IVE

S

Page 15: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 14 A

MU

AM

U

CS

D

6# Write a program to print number of days in a month.(Chained Conditional)

7# Write a program to find the area of triangle and show its type.( use if and

else)

8# Write a program which takes a character as input from the keyboard and

convert it into capital letter if it is a small letter and Vice-Versa.(if –else)

9# Write a Python program to find those numbers which are divisible by 7 and

multiple of 5, between 1500 and 2700 (both included).

10# Write a program that ask the user for a number. Depending on whether the

number is even or odd, print out an appropriate message to the user.

Page 16: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 15 A

MU

AM

U

CS

D

WEEK #5

To understand concept of function template and class

template using C.

To learn definite iteration (For loop) and conditional iteration

(While loop) in Python.

To learn the Conditional (if), Alternative (if-else), break and

pass statements in Python.

To learn the recursion, flow of execution, infinite recursion in

Python.

After completing this, the students would be able to:

to understand the concepts of function template and class

template using C.

to write, debug and run a simple Python functions based

on iteration and recursion.

1# Write a function in C to swap two numbers using function template. The

numbers could be Integer or float that depends on the user inputs.

2# Create a class Matrix that has matric data members and getvalue(), setvalue()

as member functions. Write a program in C to perform Matrix operations (2-D

array implementation), Add and Multiplication using class template.

3# Write a program in Python to check a number for Armstrong. (while)

4# Write a program in Python to print factorial of a number.(for)

5# Write a program in Python to generate first n Fibonacci terms

recursively.(function)

6# Write a program in Python to compute factorial of an integer n

recursively.(function)

OU

TC

OM

ES

PROBLEMS

S

OB

JE

CT

IVE

S

Page 17: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 16 A

MU

AM

U

CS

D

7# Write a program in Python that asks the user how many Fibonnaci numbers to

generate and then generates them. Take this opportunity to think about how

you can use functions. (Without recursion)

8# Write a program in Python to print the following Pattern.(for)

*

* *

* * *

* * * *

9# Write a program to print the following Pattern.(for)

A

A B C

A B C D E

… … . . .

N-lines

10# Write a program to print the following Pattern.(for)

1

2 2

3 3 3

4 4 4 4

5 5 5 5 5

11# Write a Python program to construct the following pattern, using a nested for

loop.

*

* *

* * *

* * * *

* * * * *

* * * *

* * *

* *

*

Page 18: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 17 A

MU

AM

U

CS

D

WEEK #6

To learn linear and binary search techniques using C.

To learn the concept of string in Python.

To learn the different String functions and methods.

After completing this, the students would be able to:

to understand and implement linear and binary search

methods in a given list.

To access individual characters in a string.

To retrieve a substring from a string.

Top search for a substring in a string.

To use string methods to manipulate strings.

1# Write a C program to search an element in a given 2D array of integers.

2# Write a C program to implement Binary search on 1D array of Employee

structure (contains employee_name, emp_no, emp_salary), with key as

emp_no. And count the number of comparison happened.

3# Assume that the variable data refers to the string “Python rules!”. Use a string

methods to perform the following tasks:

a. Obtain a list of the words in the string.

b. Convert the string to uppercase.

c. Locate the position of the string “rules”.

d. Search a given character

e. Replace the exclamation point with a question mark.

OU

TC

OM

ES

PROBLEMS

S

OB

JE

CT

IVE

S

Page 19: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 18 A

MU

AM

U

CS

D

4# Write a Python program to determine the length of the given string.

5# Write a Python program to count the number of characters (character

frequency) in a string.

6# Write a Python program to reverse the order of the characters in the given

string.

7# Write a Python program to get a string made of the first 2 and the last 2 chars

from a given a string. If the string length is less than 2, return instead of the

empty string.

8# Write a Python program which accepts the user's first and last name and print

them in reverse order with a space between them.

9# Write a Python program to calculate the length of a string.

10# Write a program (using functions!) that asks the user for a long string

containing multiple words. Print back to the user the same string, except with

the words in backwards order. For example, say I type the string:

My name is Michele

Then the output will be: Michele is name My.

11# Ask the user for a string and print out whether this string is a palindrome or

not. (A palindrome is a string that reads the same forwards and backwards.)

Page 20: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 19 A

MU

AM

U

CS

D

WEEK #7

To learn Bubble and Selection sorting techniques using C.

To learn about list and its associated operations in

Python.

To learn the various list operations (Map, filter and

reduce)in Python.

.

After completing this, the students would be able to:

to understand and implement Bubble and Selection sort

using C.

to construct lists and access items in those lists.

to use methods to manipulate lists.

to perform traversals of lists to process items in the lists

to define simple functions that expect parameters and return

values.

1# Write a C Program to sort a given list of Integers using Bubble sort technique.

2# Write a C Program to sort a given list of Integers using Selection sort

technique.

3# Write a Python program to create an array of 5 integers and display the List

items. Access individual element through indexes.

4# Write a Python program to reverse the order of the items in the array.

5# Write a Python function to sum all the numbers in a list.

6# Write a Python function to multiply all the numbers in a list.

7# Take a list, say for example this one

OU

TC

OM

ES

PROBLEMS

S

OB

JE

CT

IVE

S

Page 21: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 20 A

MU

AM

U

CS

D

a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 85 ]

a) Write a program that prints out all the elements of the list that are less

than 5.

b) Instead of printing the elements one by one, make a new list that has all

the elements less than 5 from this list in it and print out this new list.

c) Ask the user for a number and return a list that contains only elements

from the original list a that are smaller than that number given by the user.

8# Let‟s say I give you a list saved in a variable: a = [1, 4, 9, 16, 25, 36, 49, 64,

81, 100]. Write one line of Python that takes this list a and makes a new list

that has only the even elements of this list in it.

9# Write a program to find the sum of n numbers. (List)

10# Write a program to find the average of n numbers.(List)

11# Write a program to find maximum/minimum value of n numbers.(List)

12# Write a program to search a given element in the list.

13# Write a program to sort the given list of elements.

14# Write a program to perform binary search.

15# Write a function called most_frequent that takes a string and prints the letters

in decreasing order of frequency. Find text samples from several different

languages and see how letter frequency varies between languages.

Page 22: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 21 A

MU

AM

U

CS

D

WEEK #8

To learn Insertion and Quick sorting techniques using C.

To learn about dictionary, how to create a dictionary.

To learn the various dictionary operations and methods.

To learn the reverse search method.

.

After completing this, the students would be able:

to understand and implement Insertion and Quick sort.

to construct dictionaries and access entries in those

dictionaries

to use methods to manipulate dictionaries

to decide whether a list or a dictionary is an appropriate

data structure for a given application.

1# Write a C Program to sort a given list of Integers using Insertion sort technique.

2# Write a C Program to sort a given list of Integers using Quick sort technique.

3# Assume that the variable data refers to the dictionary {“b”:20, “a”:35}.

Write the values of the following expressions:

data[“a”]

data.get(“c”, None)

len(data)

data.keys()

data.values()

data.pop(“b”)

OU

TC

OM

ES

PROBLEMS

S

OB

JE

CT

IVE

S

Page 23: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 22 A

MU

AM

U

CS

D

4# Assume that the variable data refers to the dictionary {“b”:20, “a”:35}.

Write the expressions that perform the following tasks:

a) Replace the value at the key “b” in data with that value‟s negation.

b) Add the key/value pair “c”:40 to data.

c) Remove the value at key “b” in data, safely.

d) Print the keys in data in alphabetical order.

5# Write a python program to read a string and count how many times each letter

appears. (Histogram)

6# Write a python program to create a dictionary, read a value from the user and

search the key element (Reverse lookup).

7# Write a python program to create two dictionaries and merge them.

Page 24: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 23 A

MU

AM

U

CS

D

WEEK #9

To learn how to create a linked list and perform different

operations on it using pointer concepts.

To learn the concept of file and its associated operations

in Python.

To learn File handling methods.

To learn Format operator.

To learn Handling exceptions.

After completing this, the students would be able:

to understand and implement linked list and perform its

different operations using pointer concepts.

to write, debug and run program that handles file.

1# Write a C program to create a Linked List and perform the following

operations:

a. Function called InsertAtMiddle to add node in the middle of list.

b. Function called InsertBefore to add node before Nth node.

c. Function called InsertEnd to add node at the tail of linked list.

d. Function called DeleteAfter to delete node after Nth node.

e. Function called DeleteNode to delete a node having specific value.

2# Write a C program to append a Linked List L2 into a given Linked List L1. L1

contains N1 nodes with header H1 and L2 contains N2 nodes with header

H2.

OU

TC

OM

ES

PROBLEMS

S

OB

JE

CT

IVE

S

Page 25: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 24 A

MU

AM

U

CS

D

3# Write a code segment that opens a file named myfile.txt for input and prints

the number of lines in the file.

4# Write a code segment that opens a file for input and prints the number of

four-letter words in the file.

5# Write a python program which reads itself and prints the number of lines in

the file.

6# Write a python program which reads an integer/floating point number and

stores it in a file (Format operator).

7# Receive the filename from the user, open the file (say firstFile) and perform

the following:

a) Count the sentences in the text.

b) Count the words in the text.

c) Count the syllables in the text.

d) Create a new file (secondFile) and copy the text from first file.

Page 26: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 25 A

MU

AM

U

CS

D

WEEK #10

To learn how to create a linked list and perform different

operations on it using pointer concepts (continues…).

.

After completing this, the students would be able to

understand and implement linked list and perform its

different operations using pointer concepts (continues...).

1# Write a C program that reverses a given list L with header H while traversing it

only once. Each node should point to the node that was previously its

predecessor; the head should point to the node that was previously at the end

and the node that was previously at beginning should be last node.

2# Write a C program to implement circular doubly linked list and perform the

following operations:

a. Adding node to the linked list

b. Traversing the whole list

c. Deleting nodes from the list

OU

TC

OM

E

S

PROBLEMS

S

OB

JE

CT

IVE

S

Page 27: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 26 A

MU

AM

U

CS

D

WEEK #11

To learn how to create Stack and perform its different

operations.

.

After completing this, the students would be able to

understand and implement Stack and perform its different

operations.

.

1# Write a C program to create a Stack and perform the following operations:

a. push an Element to the stack

b. pop an element from stack

2# Write a C program to implement a 4-stacks of size „m‟ in an array of size „n‟

with all the basic operations such as IsEmpty(i), Push(i), Pop(i), IsFull(i) where

„i‟ denotes the stack number (1,2,3,4), m n/4. Stacks are not overlapping each

other. Leftmost stack facing the left direction and other three stacks are facing

in the right direction.

OU

TC

OM

ES

PROBLEMS

S

OB

JE

CT

IVE

S

Page 28: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 27 A

MU

AM

U

CS

D

WEEK #12

To learn some of the applications of Stack.

After completing this, the students would be able to

understand the practical usage of Stack with the help of

implementing its some applications.

1# Write a C program to check whether an expression has balanced parentheses

using array implementation of a stack.

2# Write a C program to evaluate a postfix expression using array implementation

of a stack.

OU

TC

OM

E

S

PROBLEMS

S

OB

JE

CT

IVE

S

Page 29: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 28 A

MU

AM

U

CS

D

WEEK #13

To learn how to create Queue and perform its

different operations.

After completing this, the students would be able to understand and implement Queue and perform its different operations.

1# Write a C program to create a Queue and perform the following operations:

a. Insert an Element from Queue

b. Delete an element from Queue

2# Write a C program to move all the items from a queue onto stack.

OU

TC

OM

ES

PROBLEMS

S

OB

JE

CT

IVE

S

Page 30: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 29 A

MU

AM

U

CS

D

WEEK #14 – 15

To learn the concept of Binary tree, Binary Search Tree

and their different functions.

After completing this, the students would be able to

understand and implement Binary tree, Binary Search Tree

and their different functions.

1# Write a C program to implement Binary tree insertion.

2# Write a C program to implement Post-order, pre-order and In-order traversal of

the Binary tree.

3# Write a C program for Binary Search Tree to implement following operations:

a. Insertion

b. Finding an element

c. Finding Min element

d. Finding Max element.

OU

TC

OM

E

S

PROBLEMS

S

OB

JE

CT

IVE

S

Page 31: Laboratory Course II - amu.ac.in · PDF fileCREDITS Lab Manual Design Committee: Prof. Mohammad Ubaidullah Bokhari Dr. Arman Rasool Faridi Dr. Faisal Anwar Dr. Aasim Zafar (Convener)

LAB MANUAL/B.Sc. (CA)/CCB–2P1/CSD-AMU 30 A

MU

AM

U

CS

D

WEEK #16

To learn the concepts of Graph and their different

functions.

After completing this, the students would be able to

understand and implement Graph and their different

functions.

1# Write a C program to implement graph using array and linked-list.

2# Write a C program to implement Breadth-First and Depth-First Traversal of

Graphs.

3# Write a C program to implement Dijkstra‟s Single Source Shortest Path

Algorithm.

OU

TC

OM

E

S

PROBLEMS

S

OB

JE

CT

IVE

S