Laboratory Manual B. Sc. (Hons.) Computer Applications III Semester Laboratory Course III: CCB 3P1 Department of Computer Science Aligarh Muslim University, Aligarh
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- Page 2
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. 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- Page 3
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- Page 4
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- Page 5
WEEK #3 WEEK #2 WEEK #1 APPENDIX-1 Template for the Index of Lab File S. No. S DATE OF SUBMISSION SIGNATURE OF THE TEACHER REMARKS 1# 1 2# 3# 1# 2 2# 3# 1# 3 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- Page 6
WEEK #1 LAB 1-2-3 To understand concept of control construct, arrays, recursion, string functions and pointers. 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 MANUAL/CCB 3P1/DoCS- Page 7
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- Page 8
WEEK #2 LAB 4-5-6 To understand concept of control construct, arrays, recursion, string functions and pointers (continues...). 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 MANUAL/CCB 3P1/DoCS- Page 9
WEEK #3 LAB 7-8-9 To understand concept of class, inheritance, operator overloading and file handling. 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 MANUAL/CCB 3P1/DoCS- Page 10
have a data member Hall of Residence and Non-Residential Student would have Address as its data member. LAB MANUAL/CCB 3P1/DoCS- Page 11
WEEK #4 LAB 10-11-12 To understand concept of class, inheritance, operator overloading and file handling (continues ). 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 MANUAL/CCB 3P1/DoCS- Page 12
WEEK #5 LAB 13-14-15 To understand concept of function template and class template. 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. LAB MANUAL/CCB 3P1/DoCS- Page 13
WEEK #6 LAB 16-17-18 To learn linear and binary search techniques. 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. LAB MANUAL/CCB 3P1/DoCS- Page 14
WEEK #7 LAB 19-20-21 To learn Bubble and Selection sorting techniques. 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 MANUAL/CCB 3P1/DoCS- Page 15
WEEK #8 LAB 22-23-24 To learn Insertion and Quick sorting techniques. 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. LAB MANUAL/CCB 3P1/DoCS- Page 16
WEEK #9 LAB 25-26-27 To learn how to create a linked list and perform different operations on it using pointer concepts. 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 MANUAL/CCB 3P1/DoCS- Page 17
WEEK #10 LAB 28-29-30 To learn how to create a linked list and perform different operations on it using pointer concepts (continues ). 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 MANUAL/CCB 3P1/DoCS- Page 18
WEEK #11 LAB 31-32-33 To learn how to create Stack and perform its different operations. 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 MANUAL/CCB 3P1/DoCS- Page 19
WEEK #12 LAB 34-35-36 To learn some of the applications of Stack. 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 MANUAL/CCB 3P1/DoCS- Page 20
WEEK #13 LAB 37-38-39 To learn how to create Queue and perform its different operations. 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 MANUAL/CCB 3P1/DoCS- Page 21
WEEK #14 LAB 40-41-42 To learn the concept of Binary tree, Binary Search Tree and their different functions. 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 MANUAL/CCB 3P1/DoCS- Page 22
WEEK #15 LAB 43-44-45 To learn the concept of Binary Tree, Binary Search Tree and their different functions (continues ). 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 MANUAL/CCB 3P1/DoCS- Page 23
WEEK #16 LAB 46-47-48 To learn the concepts of Graph and their different functions. 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 MANUAL/CCB 3P1/DoCS- Page 24