Assignment No.
02
Total Marks: 20
SEMESTER Spring 2025
Due Date: 30 June, 2025
CS301P- Data Structures (Practical)
Instructions
Please read the following instructions carefully before solving & submitting assignment:
It should be clear that your assignment will not get any credit (zero marks) if:
o The assignment is submitted after the due date.
o The submitted code does NOT compile.
o The submitted assignment is other than .CPP file.
o The submitted assignment does NOT open, or file is corrupted.
o The assignment is copied (from other student or ditto copy from handouts or internet).
o The BST is not implemented manually and STL is used.
Uploading instructions
For clarity and simplicity, you are required to Upload/Submit only ONE .cpp “ Assignment 2
Template(CS301P)” file after completing its code.
Note:
o Use ONLY Dev-C++ IDE.
o Only add the code were commented (// Write your code here) in given .cpp “Assignment 2 Template (CS301P)
file. Don’t change any other code otherwise you will lose your marks.
o Mention your own student VU id instead of BC123456789 in “Assignment 2 Template (CS301P)” file as given
in the output screenshot.
o You are required to implement the following functions:
addBook(BookNode* node, int price, string title)
removeBook(BookNode* node, int price)
printInOrder(BookNode* node)
findBook(BookNode* node, int price)
Learning Objectives:
o To manually implement a Binary Search Tree (BST) in C++ without relying on STL containers.
o To perform core BST operations: insertion, search, deletion, and in-order traversal.
o To efficiently organize and manage book data (titles and prices) using BST logic.
o To observe how in-order traversal maintains sorted order within the BST.
For any query about the assignment, contact at cs301P@[Link]
GOOD LUCK
Problem Statement: Marks 20
A bookstore wants to manage its catalog of books efficiently. Your task is to implement a Binary Search Tree (BST)
in C++ to store and manage book titles with their prices.
You are given the following predefined books to insert into the BST:
- C++ Primer (Rs. 520)
- Clean Code (Rs. 580)
- Algorithms Unlocked (Rs. 610)
- Design Patterns (Rs. 695)
- Intro to AI (Rs. 750)
o BST Implementation:
o Book management using Binary Search Tree
o Books stored by price (key) and title
o Insertion, Deletion, Search, and Traversal Operations
o Student-Specific Customization:
o VUID-based custom book creation
o Last digit extraction from student ID
o Custom price calculation (500 + last digit)
o Core Functions:
o addBook(): Inserts books with price validation
o removeBook(): Handles all deletion cases (0/1/2 children)
o printInOrder(): Displays books in sorted order
o findBook(): Efficient price-based search
o Error Handling:
o Duplicate price detection
o Empty tree handling
o Comprehensive search feedback
o Output:
o Clear operation headers
o Visual book listing
o Status messages for all operations
o Student ID displayed throughout
How to Implement the code:
Replace Student ID:
Change "BC2123456789" to your actual VU ID
Operations:
o Initial tree built with 5 sample books
o Custom book inserted using VUID last digit
o Tree displayed before/after insertion
o Book search demonstration
o Custom book deletion
Sample Output:
Lectures Covered: This assignment covers Lab 4 and 5.
Deadline: Your assignment must be uploaded/submitted on or before 30-June 2025.