+2 votes
373 views

Hi everyone! I am a student of BS.Software Engineering and facing problems in Programming. And now I have submit an assignment for course code CS301 and assignment no is Assignment No.1 Spring 2020. The due date is: 1 Jun 2020 and I have to submit it in cpp format. The problem statement is given bellow.

You are required to write a program in C++ to implement Stack data structure and use this data structure to store different types of books based on their identity number. You have to implement Stack data structure using array. A stack is a LIFO structure in which data elements are stored in an order such that last element pushed on the stack will be popped up first. Your program should cover the following scenario. Suppose a student is collecting books and throwing them into stack of books. You need to develop an application that will count different books in the stack. This stack will consist of three types of books i.e. software, hardware and other books. You will identify book with unique numeric identity number. If book identity number will fully dividable by 8, will consider it software book. While the number fully dividable by 5 will consider it hardware book and consider rest of the books as other books.

First, the program will ask the user to input size of the stack. Then the programmer will ask the user to input total number of books. Then according to the number of Books, it will ask the user to enter identity number for each book. The book identity number can be any random number between 1 and 99. If book identity number is fully dividable by 8, we will consider it software book. While the number fully dividable by 5 will consider it hardware book and consider rest of the books as other books.

Programmer should implement isFull() function of the stack to check if the number of books exceed the size of the stack and isEmpty() function to check if the stack is empty or not. Programmer should also display the message "Books not found" if no books found.

Solution Guidelines:

1. First understand the code given in handouts about stack.
2. Get stack size from user to allocate space for stack dynamically.
3. Get identity number of books that user want to enter into the stack.
4. Get value one by one and push into stack.
5. Don’t allow popping if stack is empty and pushing if stack is full.
6. If identity number of book is dividable by 8 and 5 then priority should be given to 8.

Reference: The Above statement is taken from CS301 Assignment No.1 Spring 2020 and I have the right to use it anywhere.

reopened | 373 views
Thanks admin! I got it and you saved my time!
If you don't mind, can you please add a working screenshot into the answer. It will help us to understand the program.

Once again, thanks by heart!
You are welcome dear! But if you don't mind, please write comment on the Answer not on the question. I have updated the answer with working screenshot. Please check it..

## 1 Answer

0 votes
Best answer

Keywords:
CS301 Assignment No.1 Spring 2020
CS301 Assignments
CS301 Spring 2020
CS301 Assignment 1 Spring 2020
CS301 Assignment No.1 May 2020
CS301 Assignment 1 May 2020

The solution file you sent me on my whatsapp inbox had many syntax errors. Now I have debugged it and is fully working. Please copy the code bellow and Paste it into Dev C++ and let me know if it is working for you or not. If you see any runtime error, please comment bellow and I shall do help you. The Debugged solution is:

``````#include<iostream>
using namespace std;
//Define Class
class MYBooks
{
//Define Private Variables
private :
int *Stack;
int Selected;
int Books;
int TotalSize;

public :
MYBooks(int size, int n_ofbooks)
{
TotalSize = size;
Stack= new int[TotalSize];
Books=n_ofbooks;
Selected=-1;
}
int Empty()
{
return (Selected==-1);
}
int Full()
{
return (Selected==TotalSize-1);
}
//Add an item to the object
void AddItem(int item)
{
Stack[++Selected]=item;
}
int StackCurrent()
{
return Stack[Selected];
}
int StackPre()
{
return Stack[Selected--];
}

};

//Main Function
main()
{

int size, books, id;
int hardware_books=0;
int software_books=0;
int other_books=0;
cout<<"Enter total size of the Stack: ";
cin>>size;
cout<<endl;
cout<<"Number of books you want to add in stack : ";
cin>>books;
//Create an object
MYBooks book(size,books);

for(int i=0; i<books; i++)
{
if(!book.Full())
{
cout<<endl;
cout<<"Enter the ID of the book you want to add into Stack: ";
cin>>id;
book.AddItem(id);
}
}
cout<<endl<<"-----------------"<<endl;
for(int i=0; i<books; i++)
{
if(!book.Empty())
{
int idPre=book.StackPre();

if(idPre%8==0)
{
software_books++;
}
else if (idPre%5==0)
{
hardware_books++;
}
else
{
other_books++;
}
}
}
if(books>0)
{
cout<<endl;
cout<<"Total Software Books : ";
cout<<software_books;
cout<<endl;
cout<<"Total Hardware Books : ";
cout<<hardware_books;
cout<<endl;
cout<<"Total Other Books : ";
cout<<other_books;
}
else
{
cout<<endl;
cout<<"There are no books added into the stack!";
}
}
``````

Edit: Here is the working screenshot

The solution is copyrighted to the admin of this website (meansflow.com). No one can copy it on his own forum or website or even in youtube video.

by (1.4k points)
selected by

+2 votes
1 answer
+1 vote
1 answer
+2 votes
1 answer
+3 votes
1 answer
+1 vote
1 answer
+1 vote
1 answer
+1 vote
2 answers
+2 votes
0 answers
+2 votes
1 answer
+2 votes
1 answer