CS301P Assignment 1 Solution Fall 2026

CS301P Data Structure Practical turns data structure concepts into working code. Assignment 1 for Fall 2026 carries 20 marks and the due date is 5 November 2026, and it asks you to build a stack using a singly linked list, then use it to work with prime numbers and binary conversion. The program pushes six numbers onto the stack, counts and sums the prime numbers, pops the top number, and converts it to binary.
The solution file linked below is a complete, working C++ program. It implements a Node class and a NumberStack class with push, pop, prime counting, prime summing, and binary conversion using a second stack. The program was compiled and run to verify its output, and the numbers below are the verified results for the example VU ID used in the file.
What Does the Solution File Cover?
The file covers the complete stack program. The stack is built on a singly linked list, so push inserts a new node at the top and pop removes and returns the top node while freeing its memory. The prime functions walk the stack without changing it, and the binary conversion pushes remainders onto a second stack so they print in the correct order. The main function ties it all together with the VU ID logic.
Which Numbers Are Pushed Onto the Stack?
The program takes the last digit of the VU ID and pushes six numbers in this order: the last digit, 18, 23, 29, 41, and 45. With the example ID BC190409022, the last digit is 2, so the pushed numbers are 2, 18, 23, 29, 41, and 45. Because a stack is last-in-first-out, the top of the stack after all pushes is 45.
What Are the Prime Count and Prime Sum?
Among the six numbers, the prime numbers are 2, 23, 29, and 41. The numbers 18 and 45 are not prime. So the total prime count is 4, and the sum of the prime numbers is 2 + 23 + 29 + 41 = 95. The program computes both by walking the linked list and testing each value with a standard prime check.
What Is Popped and What Is Its Binary Value?
The program pops one number from the stack, which is the top value 45. It then converts 45 to binary using a second stack: dividing by 2 repeatedly gives remainders 1, 0, 1, 1, 0, 1, and popping them from the second stack prints them in reverse as 101101. So the binary of 45 is 101101.
How Do You Download the Solution File?
You can download the complete solution file from Google Drive using the link below. The file is a.cpp file, ready to open in Dev C++. Replace the VU ID in the program with your own before running it, because your own last digit changes the first pushed number, and therefore can change the prime count and prime sum. The popped value stays 45, since 45 is pushed last.
How Should You Use This Solution?
A solution file helps most when you use it to learn, not just to submit. Trace the push and pop operations by hand first, so the last-in-first-out order is clear. Then check the prime test on each number yourself, and work out the binary conversion by hand before comparing with the program output. Also check your work against the exact assignment file on VULMS, since question wording can vary.
- Download the.cpp file and open it in Dev C++.
- Replace the VU ID with your own and re-run the program.
- Trace push and pop by hand to confirm the stack order.
- Check the prime count and sum against your own numbers.
- Work out the binary conversion by hand before comparing.
For more study material, you can download course handouts from the VU handouts page and compact revision notes from the VU short notes page. Past papers are also useful for programming practice, and you can find them on the VU midterm past papers page.
Frequently Asked Questions
Is this the complete solution for CS301P Assignment 1 Fall 2026?
Yes. The file is a complete C++ program with a linked list stack, prime counting, prime summing, and binary conversion. The assignment carries 20 marks and the due date is 5 November 2026.
Why do I need to change the VU ID in the program?
Because the first pushed number is the last digit of your own VU ID. With a different last digit, the prime count and prime sum can change, so you must run the program with your own ID to get your own correct output.
Why is a second stack used for the binary conversion?
Because dividing by 2 produces the binary digits in reverse order. Pushing the remainders onto a second stack and then popping them reverses them back, so the binary digits print in the correct order.
Last updated: October 2026.



