Post on 01-Jul-2018
transcript
Laboratory Manual B. Sc. (Hons.) Computer Applications
III Semester
Laboratory Course – III: CCB – 3P1
Department of Computer Science
Aligarh Muslim University, Aligarh
LAB MANUAL/CCB–3P1/DoCS-AMU Page 2 A
MU
AM
U
CS
D
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 Nadeem
Mr. Sunil Kumar Sharma
Mr. Imshad Ahmad Khan
Mr. Naved Iqbal
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
LAB MANUAL/CCB–3P1/DoCS-AMU Page 3 A
MU
AM
U
CS
D
COURSE TITLE: Laboratory Course-III COURSE CODE: CCB – 3P1
CREDIT: 2 PERIODS PER WEEK: 3
CONTINUOUS ASSESSMENT: 40 EXAMS: 60
COURSE DESCRIPTION
This course is designed to review the concepts of C++ language,
studied in previous semester and implement the various algorithms
related to different data structures.
CONTENT
This course is designed to provide the students the opportunity of
learning both – concepts of C++ and then implementing algorithms and
data structures. This course is indented to develop a deep
understanding of various operations on data structure such as searching,
sorting, insertion, deletion and traversing.
OBJECTIVES
This course is designed to help students in:
Learning OOP concepts 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++.
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++.
LAB MANUAL/CCB–3P1/DoCS-AMU Page 4 A
MU
AM
U
CS
D
OUTCOMES
After completing this course, the students would be able to:
Understand and implement OOP concepts 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++.
RULES AND REGULATIONS
Students are required to strictly adhere to the following rules.
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
LAB MANUAL/CCB–3P1/DoCS-AMU Page 5 A
MU
AM
U
CS
D
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.
LAB MANUAL/CCB–3P1/DoCS-AMU Page 6 A
MU
AM
U
CS
D
APPENDIX-1
Template for the Index of Lab File
S. No. PROBLEMS DATE OF
SUBMISSION
SIGNATURE OF THE
TEACHER
REMARKS
1
WE
EK
#1
1#
2#
3#
2
WE
EK
#2
1#
2#
3#
3
WE
EK
#3
1#
2#
3#
Note: The students should use Header and Footer mentioning their roll no. & name in footer and page no in header.
LAB MANUAL/CCB–3P1/DoCS-AMU Page 7 A
MU
AM
U
CS
D
WEEK #1
OBJECTIVES
To understand concept of control construct, arrays,
recursion, string functions and pointers.
OUTCOMES
After completing this, the students would be able to understand
the concepts of control construct arrays, recursion, string functions and
pointers.
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
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++:
1. Write a program to store and display the above mentioned cities and
corresponding items using arrays.
LAB – 1-2-3
PROBLEM
LAB MANUAL/CCB–3P1/DoCS-AMU Page 8 A
MU
AM
U
CS
D
2. Write a program to display name of cities where salesman has delivered
maximum and minimum number of items.
3. Write a program to search the number of items to be delivered of a user
supplied city.
LAB MANUAL/CCB–3P1/DoCS-AMU Page 9 A
MU
AM
U
CS
D
WEEK #2
OBJECTIVES
To understand concept of control construct, arrays,
recursion, string functions and pointers (continues...).
OUTCOMES
After completing this, the students would be able to understand
the concepts of control construct arrays, recursion, string functions and
pointers (continues...).
Based on the previous scenario, do the followings:
1. Write a program to find total number of items delivered using recursive
function additem().
2. Write a program to display name of the cities along with their length, and
identity cities composed of two words.
3. The number of items of ‘Agra’ and ‘Kolkata’ are accidently interchanged.
Correct them by writing a swap function using pointers.
LAB – 4-5-6
PROBLEM
LAB MANUAL/CCB–3P1/DoCS-AMU Page 10 A
MU
AM
U
CS
D
WEEK #3
OBJECTIVES
To understand concept of class, inheritance, operator
overloading and file handling.
OUTCOMES
After completing this, the students would be able to understand
the concepts of class, inheritance, operator overloading and file
handling.
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()}
Solve the following problems based on the above mentioned scenario using
C++:
1. Write a program to create Teacher, Program and Student Classes with above
mentioned data members and member functions.
2. 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.
3. Write a program to overload ‘+’ operator to add the hours of two teachers.
4. Write a program to create two subclasses ‘Residential Student’ and ‘Non-
Residential Student’ inherited from Student class. ‘Residential Student’ would
LAB – 7-8-9
PROBLEM
LAB MANUAL/CCB–3P1/DoCS-AMU Page 11 A
MU
AM
U
CS
D
have a data member ‘Hall of Residence’ and ‘Non-Residential Student’ would
have ‘Address’ as its data member.
LAB MANUAL/CCB–3P1/DoCS-AMU Page 12 A
MU
AM
U
CS
D
WEEK #4
OBJECTIVES
To understand concept of class, inheritance, operator
overloading and file handling (continues…).
OUTCOMES
After completing this, the students would be able to understand
the concepts of class, inheritance, operator overloading and file
handling (continues…).
Based on the previous scenario, do the followings:
1. Write a friend function to determine number of hours taught by a particular
teacher.
2. Write a program to store details of Teacher, Program and Student, each in a
separate file.
3. Write a program to read details of Student from file whose Roll No is given by
the user?
LAB – 10-11-12
PROBLEM
LAB MANUAL/CCB–3P1/DoCS-AMU Page 13 A
MU
AM
U
CS
D
WEEK #5
OBJECTIVES
To understand concept of function template and class
template.
OUTCOMES
After completing this, the students would be able to understand
the concepts of function template and class template.
1. Write a function 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 to perform Matrix
operations (2-D array implementation), Add and Multiplication using class
template.
PROBLEM
LAB – 13-14-15
LAB MANUAL/CCB–3P1/DoCS-AMU Page 14 A
MU
AM
U
CS
D
WEEK #6
OBJECTIVES
To learn linear and binary search techniques.
OUTCOMES
After completing this, the students would be able to understand
and implement linear and binary search methods in a given list.
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.
PROBLEM
LAB – 16-17-18
LAB MANUAL/CCB–3P1/DoCS-AMU Page 15 A
MU
AM
U
CS
D
WEEK #7
OBJECTIVES
To learn Bubble and Selection sorting techniques.
OUTCOMES
After completing this, the students would be able to understand
and implement Bubble and Selection sort.
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.
LAB – 19-20-21
PROBLEM
LAB MANUAL/CCB–3P1/DoCS-AMU Page 16 A
MU
AM
U
CS
D
WEEK #8
OBJECTIVES
To learn Insertion and Quick sorting techniques.
OUTCOMES
After completing this, the students would be able to understand
and implement Insertion and Quick sort.
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.
PROBLEM
LAB – 22-23-24
LAB MANUAL/CCB–3P1/DoCS-AMU Page 17 A
MU
AM
U
CS
D
WEEK #9
OBJECTIVES
To learn how to create a linked list and perform
different operations on it using pointer concepts.
OUTCOMES
After completing this, the students would be able to understand
and implement linked list and perform its different operations using
pointer concepts.
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.
LAB – 25-26-27
PROBLEM
LAB MANUAL/CCB–3P1/DoCS-AMU Page 18 A
MU
AM
U
CS
D
WEEK #10
OBJECTIVES
To learn how to create a linked list and perform
different operations on it using pointer concepts
(continues…).
OUTCOMES
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
LAB – 28-29-30
PROBLEM
LAB MANUAL/CCB–3P1/DoCS-AMU Page 19 A
MU
AM
U
CS
D
WEEK #11
OBJECTIVES
To learn how to create Stack and perform its different
operations.
OUTCOMES
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.
LAB – 31-32-33
PROBLEM
LAB MANUAL/CCB–3P1/DoCS-AMU Page 20 A
MU
AM
U
CS
D
WEEK #12
OBJECTIVES
To learn some of the applications of Stack.
OUTCOMES
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.
LAB – 34-35-36
PROBLEM
LAB MANUAL/CCB–3P1/DoCS-AMU Page 21 A
MU
AM
U
CS
D
WEEK #13
OBJECTIVES
To learn how to create Queue and perform its
different operations.
OUTCOMES
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.
LAB – 37-38-39
PROBLEM
LAB MANUAL/CCB–3P1/DoCS-AMU Page 22 A
MU
AM
U
CS
D
WEEK #14
OBJECTIVES
To learn the concept of Binary tree, Binary Search
Tree and their different functions.
OUTCOMES
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.
LAB – 40-41-42
PROBLEM
LAB MANUAL/CCB–3P1/DoCS-AMU Page 23 A
MU
AM
U
CS
D
WEEK #15
OBJECTIVES
To learn the concept of Binary Tree, Binary Search
Tree and their different functions (continues…).
OUTCOMES
After completing this, the students would be able to understand
and implement Binary Tree, Binary Search Tree and their different
functions (continues…).
1. 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.
LAB – 43-44-45
PROBLEM
LAB MANUAL/CCB–3P1/DoCS-AMU Page 24 A
MU
AM
U
CS
D
WEEK #16
OBJECTIVES
To learn the concepts of Graph and their different
functions.
OUTCOMES
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.
LAB – 46-47-48
PROBLEM