CS301 Assignment: 01 Solution

Assignment Details

Due Date:

Tuesday 4, November, 2025

Extended Date:

Wednesday 5, November, 2025


Assignment Question Details:

Assignment No. 01
SEMESTER Fall 2025
CS301- Data Structures

 

Total Marks: 20

Due Date: 04 - Nov, 2025

 

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:

  • The assignment is submitted after the due date.
  • The submitted code does NOT compile.
  • The submitted assignment is other than .CPP file.
  • The submitted assignment does NOT open or file is corrupted.
  • The assignment is copied (from other student or ditto copy from handouts or internet).
  • The Stack is implemented using array and STL is used.

 

 

 

Uploading instructions

For clarity and simplicity, you are required to Upload/Submit only ONE .cpp  “ Assignment 1 Template” file after completing its code.

 

Note:

  • Use ONLY Dev-C++ IDE.
  • Only add the code where commented (// Write your code here) in given .cpp “ Assignment 1 Template” file. Don’t change any other code otherwise you will lose your marks.
  • Mention your own student VU id instead of BC123456789 in “ Assignment 1 Template” file as given in the output screenshot.
  • Only implement these functions pushBook(),  popBook(),  reverseBookStack (),  displayBooksStack().

 

 

 

Learning Objectives:

 

·         To understand and implement stack data structure using linked list

·         To simulate real life scenario using data structures

·         To learn push and pop operations logically and practically

·         To enhance understanding of pointer manipulation by reversing linked list connections within a stack structure

For any query about the assignment, contact at cs301@vu.edu.pk

 

GOOD LUCK

 

 

 

Problem Statement

Marks 20

You are working in the IT department of a School Library System, managing a stack of returned books. This system uses a Stack implemented with a Linked List to handle book returns and re-shelving.

The system performs the following operations sequentially, as outlined in the provided “Assignment 1 Template.cpp” file:

1.      Initialize and Display Book Stack:

·         Pushes 5 book titles (Book-A to Book-E) onto the stack.

·         Displays the books currently in the stack (before re-shelving).

2.      Re-shelve Books (Pop):

Automatically determines the number of books to re-shelve/pop based on the last digit of your Student ID:

·         If the last digit is less than or equal to 5, 2 books are re-shelved.

·         If the last digit is greater than 5, 3 books are re-shelved.

Pops the determined number of books from the stack.

Displays the updated stack after popping the books.

3.      Reverse Remaining Stack:

Reverse the order of the books remaining in the stack permanently, so the bottom-most book becomes the new top, and vice versa and display update stack.

4.      Display Final Stack:

Displays the books still remaining on the counter (after re-shelving and reversing) as final stack.

Your Task to Perform:

  • Understand the Provided Code Template:
    Open and thoroughly understand the “Assignment 1 Template.cpp” file provided within the assignment .zip file uploaded on VULMS. This file includes the foundational class structures for re-shelving the books using a stack as a linked list.
  • Implement pushBook() Function:
    Write the code to insert the book into the stack.
  • Implement popBook() Function:
    Write the code to pop the book from the stack.
  • Implement  reverseBookStack() Function:
    Write the code to reverse the existing stack books e.g. means reverse the stack order completely.

·         Implement  displayBookStack() Function:
Write the code to display all the existing books in the stack as given in the output screenshot.

  • In the main function;
    • Replace the Sample VUID with Your Own:
      In the code and output messages, replace the example VUID “BC123456789” with your actual VUID to personalize and validate your submission. Otherwise, your marks will be deducted.

·         Check sample output screenshot given below to understand program output.

 

Sample Output Screenshot:


 

 

 

 

 

 

Lectures Covered:  This assignment covers Lecture # 01 - 06.

Deadline:           Your assignment must be uploaded/submitted on or before 04 November 2025.

 

VuPark Approved

Wednesday 29, October, 2025