<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[CS301 Assignment 1 Solution and Discussion]]></title><description><![CDATA[<p dir="auto">Re: <a href="/topic/618/cs301-assignment-1-solution-and-discussion">CS301 Assignment 1 Solution and Discussion</a></p>
<pre><code>Assignment No. 01 
</code></pre>
<p dir="auto">Semester Spring 2020<br />
CS301- Data Structures	<br />
Total Marks: 20</p>
<p dir="auto">Due Date :1 June 2020<br />
Instructions<br />
Please read the following instructions carefully before solving &amp; submitting assignment:<br />
It should be clear that your assignment will not get any credit (zero marks) if:<br />
o	The assignment is submitted after due date.<br />
o	The submitted code does NOT compile.<br />
o	The submitted assignment is other than .CPP file.<br />
o	The submitted assignment does NOT open or file is corrupted.<br />
o	The assignment is copied (from other student or ditto copy from handouts or internet).<br />
Uploading instructions<br />
For clarity and simplicity, You are required to Upload/Submit only ONE .CPP file.</p>
<p dir="auto">Note: Use ONLY Dev-C++ IDE.<br />
Objective<br />
The objective of this assignment is</p>
<p dir="auto">o	To make you familiar of programming with stack data structure.</p>
<p dir="auto">For any query about the assignment, contact at <a href="mailto:cs301@vu.edu.pk" target="_blank" rel="noopener noreferrer nofollow ugc">cs301@vu.edu.pk</a></p>
<p dir="auto">GOOD LUCK</p>
<pre><code>Marks: 20  
</code></pre>
<p dir="auto">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.<br />
Your program should cover the following scenario.<br />
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.<br />
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.</p>
<p dir="auto">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.</p>
<p dir="auto">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.</p>
<p dir="auto">Program’s sample output is given below</p>
<p dir="auto">Output 1:<br />
<img src="https://i.imgur.com/XUFXxkd.png" alt="7722eec0-3d47-4dfa-8e49-af71bc5276df-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Out Put 2:<br />
<img src="https://i.imgur.com/Fk4idQA.png" alt="aeb43ac0-afd4-4ce3-9c15-6440d6bfb4d9-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Output 3:<br />
<img src="https://i.imgur.com/xbiFw6G.png" alt="e51ed70a-a3a2-44b1-ae5a-d9e4c2c8f17a-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Solution Guidelines:</p>
<ol>
<li>First understand the code given in handouts about stack.</li>
<li>Get stack size from user to allocate space for stack dynamically.</li>
<li>Get identity number of books that user want to enter into the stack.</li>
<li>Get value one by one and push into stack.</li>
<li>Don’t allow popping if stack is empty and pushing if stack is full.</li>
<li>If identity number of book is dividable by 8 and 5 then priority should be given to 8.<br />
Lectures Covered:  This assignment covers Lecture # 1-7.<br />
Deadline:           Your assignment must be uploaded/submitted at or before, 1 June 2020</li>
</ol>
]]></description><link>https://community.secnto.com//topic/1849/cs301-assignment-1-solution-and-discussion</link><generator>RSS for Node</generator><lastBuildDate>Mon, 08 Jun 2026 21:39:56 GMT</lastBuildDate><atom:link href="https://community.secnto.com//topic/1849.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 05 Jun 2020 09:34:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to CS301 Assignment 1 Solution and Discussion on Fri, 05 Jun 2020 09:34:37 GMT]]></title><description><![CDATA[<pre><code>/* Implementation of stack using array */

#include &lt;iostream&gt;
#include &lt;conio.h&gt;
using namespace std;

class  Stack  /* the Stack class */ 
{
    public:
        Stack() { 
			size = 0; 
			current = -1;
	 	} //constructor
			
        int pop() { 
			return data[current--];
			}    	// The pop function    
        
		void push(int x) {
			data[++current] = x;
			//cout&lt;&lt;A[current];
		} // The push function
        
		int top(){ 
			return data[current];
		}      	// The top function
        
		int isEmpty(){
			return ( current == -1 );
		} // Will return true when stack is empty
        
		int isFull(){ 
			return ( current == size-1);
		} // Will return true when stack is full	
		void setStackSize(int s){
			size = s;
			data = new int[size];
		}

     private:
       int   object;  				// The data element
       int   current; 				// Index of the array
       int   size;    				// max size of the array
       int   *data;    				// Array of 10 elements    
};	

// Main method
int main()
{
    int t_books= 0, size = 0;
	int scount = 0, hcount=0, ocount=0; // For counting of book i.e software , hardware and other books. 
        
	Stack stack; 				// creating a stack object
    
    cout&lt;&lt;"Set size of stack: ";
    cin&gt;&gt;size;
    stack.setStackSize(size);
    
    
    cout&lt;&lt;"How many Books you want to add into stack: ";
    cin&gt;&gt;t_books;
    
    int book;
    for(int i = 0; i &lt; t_books; i++)
    {
    	cout &lt;&lt;"\nEnter Book identity number that you want to insert into stack: ";
        cin&gt;&gt;book;
        
         if(!stack.isFull()) {		// checking stack is full or not
         	
         	stack.push(book);     	// push the element at the top    
        }
         else{
             cout&lt;&lt;"\n Unable to insert "&lt;&lt;book&lt;&lt;". Stack is full, can't insert more";
             break;
         }    
    }

    // pop the elements at the stack
    
    int current = 0;
    
    for (int i = 0; i &lt; t_books; i++)
    {
    	
        if(!stack.isEmpty()) {		// checking stack is empty or not
                  current = stack.pop();
                  if(current % 8 == 0){
                  	scount++;
                  	
                  }
                  else if(current % 5 == 0){
                  	hcount++;
                  }
                  else {
                  	ocount++;
                  }
			}
                
        else {
        
                  cout &lt;&lt;"\nStack is empty, sorry can't pop more";
                   getch();
                   break;
        }
    }
    
    if(scount == 0 &amp;&amp; hcount==0 &amp;&amp; ocount==0){
        cout&lt;&lt;"\nBooks not found\n";
    }
    else {    
        cout&lt;&lt;"\n\nTotal Software Book/Books = "&lt;&lt;scount;    
        cout&lt;&lt;"\n\nTotal Hardware Book/Books = "&lt;&lt;hcount;    
		cout&lt;&lt;"\n\nTotal Other Book/Books = "&lt;&lt;ocount;    
		
    }    
     getch();
}


</code></pre>
]]></description><link>https://community.secnto.com//post/5142</link><guid isPermaLink="true">https://community.secnto.com//post/5142</guid><dc:creator><![CDATA[Eshaal Khan]]></dc:creator><pubDate>Fri, 05 Jun 2020 09:34:37 GMT</pubDate></item><item><title><![CDATA[Reply to CS301 Assignment 1 Solution and Discussion on Mon, 18 Jan 2021 06:54:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/zareen" aria-label="Profile: zareen">@<bdi>zareen</bdi></a><br />
100% Solution Code</p>
<pre><code>#include &lt;iostream&gt;
using namespace std;

/* The Student class */
class Student {
	private:
		string firstname, lastname, VUID;
		int marks;
		Student *nextStudent;
		
	public:
		// constructor of Student class to initialize data members of class   
        Student(){
        	VUID = "";
            marks = 0;
			firstname = "";
            lastname = "";            			
            nextStudent = NULL;
        }        
        
        // Student class method to set VU  ID of Student
        void setVUID(string val){
            VUID = val;
        };
        
        //Student class method to get VU ID of Student
        string getVUID(){
            return VUID;
        }; 
            
        // Student class method to set first name of Student
        void setFirstName(string val){
            firstname = val;
        };
        
        //Student class method to get first name of Student
        string getFirstName(){
            return firstname;
        }; 
        
        // Student class method to set last name of Student
        void setLastName(string val){
            lastname = val;
        };
        
        //Student class method to get last name of Student
        string getLastName(){
            return lastname;
        };
        
        //Student class method to set the Marks of Student
        void setMarks(int val) { 
            marks = val; 
        };
		// Student class method to get the Marks of Student
        int getMarks() { 
            return   marks; 
        }
        
        //Student class method to point current Student to next Student
        void setNext(Student *nextStudent) {
        	this-&gt;nextStudent   =   nextStudent; 
        }
        
        // Student class method to get memory address where pointer is pointing
        Student *getNext() { 
            return   nextStudent; 
        }       
};

/* The List class */
class List {
	
	private:
		Student *   head;
        Student *   current;
    
    public:
        // constructor of list class to initialize data members of class
        List() {            
            head   =   new Student();
            head-&gt;setNext(NULL);
            current   =   NULL;          
        }                
        
        // list class method to add Students into list
        void   add() {
            Student *newStudent = new Student();
            int loc_marks = 0;
            string loc_vuid = "", loc_fname = "", loc_lname = "";
            
            cout&lt;&lt;"\nEnter VU ID: ";
            cin&gt;&gt;loc_vuid;
            newStudent-&gt;setVUID(loc_vuid);
            
            cout&lt;&lt;"Enter Marks: ";
            cin&gt;&gt;loc_marks;
            newStudent-&gt;setMarks(loc_marks); 
            
            cout&lt;&lt;"Enter First Name: ";
            cin&gt;&gt;loc_fname;
            newStudent-&gt;setFirstName(loc_fname);
            
            cout&lt;&lt;"Enter Last Name: ";
            cin&gt;&gt;loc_lname;
            newStudent-&gt;setLastName(loc_lname);
           
            if(head-&gt;getNext() == NULL){
           		newStudent-&gt;setNext(NULL);
               	head-&gt;setNext(newStudent);               	
               	current   =   newStudent;
		    }
		    else{
		    	Student *temp = head;
		    	while(temp-&gt;getNext() != NULL &amp;&amp; temp-&gt;getNext()-&gt;getMarks() &gt;= loc_marks){
		    		temp = temp-&gt;getNext();
				}
				current = temp;
				newStudent-&gt;setNext(current-&gt;getNext());
               	current-&gt;setNext( newStudent );               	
               	current   =   newStudent;
		   }         
        };        

        // list class method to get the information of Student
        void getInfo() { 
            if (current  !=  NULL){
				cout&lt;&lt;"VU ID: "&lt;&lt;current-&gt;getVUID()&lt;&lt;endl;
	            cout&lt;&lt;"Marks: "&lt;&lt;current-&gt;getMarks()&lt;&lt;endl;				 
				cout&lt;&lt;"First Name: "&lt;&lt;current-&gt;getFirstName()&lt;&lt;endl;
				cout&lt;&lt;"Last Name: "&lt;&lt;current-&gt;getLastName()&lt;&lt;endl&lt;&lt;endl;				
			}
        };				          
               
        // list class method to move current to next Student
        bool next() {
            if (current  ==  NULL){
                return  false;
            }  
            current  =  current-&gt;getNext();            
        };
        
        // frient function to list class to show all students in the list
        friend void showStudents(List list){
            Student* savedCurrent  =  list.current;
            list.current  =  list.head;
            
            for(int i = 1; list.next(); i++){			
				list.getInfo();          
			}
            list.current  =  savedCurrent;
        };
};
    
main() {
	int input = 0;
    List lst;      
    
    while(input != -1) {
        
        cout&lt;&lt;"1. To Add New Student in Ranking"&lt;&lt;endl;
        cout&lt;&lt;"2. To Display Ranking"&lt;&lt;endl;
        cout&lt;&lt;"3. To Close"&lt;&lt;endl&lt;&lt;endl;
        cout&lt;&lt;"Enter Your Choice: (1, 2 or 3) ";
        cin&gt;&gt; input;
        
        if(input == 1) {
        	lst.add();
			cout&lt;&lt;"Student's information saved successfully.\n"; 
        }
        else if(input == 2) {
        	cout&lt;&lt;"\nRanking Chart"&lt;&lt;endl;
            showStudents(lst);
            return 0;
        }
        else {
        	return 0;
        }		
	}
}

</code></pre>
]]></description><link>https://community.secnto.com//post/6384</link><guid isPermaLink="true">https://community.secnto.com//post/6384</guid><dc:creator><![CDATA[zareen]]></dc:creator><pubDate>Mon, 18 Jan 2021 06:54:33 GMT</pubDate></item><item><title><![CDATA[Reply to CS301 Assignment 1 Solution and Discussion on Mon, 18 Jan 2021 06:54:07 GMT]]></title><description><![CDATA[<p dir="auto">Data Structures (CS301)<br />
Assignment # 01<br />
Semester Fall 2020	<br />
Total Marks = 20<br />
Deadline Date<br />
26th Nov 2020</p>
<p dir="auto">Please carefully read the following instructions before attempting assignment.<br />
RULES FOR MARKING<br />
It should be clear that your assignment would not get any credit if:<br />
•	The assignment is submitted after the due date.<br />
•	The submitted assignment does not open or file is corrupt.<br />
•	Strict action will be taken if submitted solution is copied from any other student or from the internet.</p>
<p dir="auto">Lectures:</p>
<p dir="auto">•	Lectures 1 to 7 are covered in this assignment<br />
NOTE<br />
No assignment will be accepted after the due date via email in any case (whether it is the case of load shedding or internet malfunctioning etc.). Hence refrain from uploading assignment in the last hour of deadline. It is recommended to upload solution file at least one day before its closing date.<br />
If you people find any mistake or confusion in assignment (Question statement), please consult with your instructor before the deadline. After the deadline no queries will be entertained in this regard.<br />
For any query, feel free to email at:  <a href="mailto:cs301@vu.edu.pk" target="_blank" rel="noopener noreferrer nofollow ugc">cs301@vu.edu.pk</a></p>
<p dir="auto">Problem Statement:<br />
Suppose you are asked to make a Ranking information chart of students in a dynamic list called linked list using C++ language. The data will be stored in this list in order i.e. the highest marks student will be on top position with other information whereas the next highest marks student will be on second top position and so on.<br />
Your program will get the information of a student in the form of input (Student ID, Name, Marks) through console. After filling the required information, the student will be inserted in linked list at right place. The right place of student will be decided on the basis of marks.<br />
Furthermore, you are required to use only classes for this assignment. As we are not covering Struct in this course so using it in assignment solution is not allowed.<br />
Sample Output:<br />
See the gif file attached with this assignment file.</p>
<p dir="auto">Note:<br />
DO REMEMBER that you must use your VUID as an input in this program.</p>
<p dir="auto">Submission details<br />
Following Files Must be submitted in a single zip or rar file.<br />
•	C++ code file (file name should be your VUID)<br />
•	A .gif file which shows only “execution” of your Application (For Recording .gif a software named Screentogif is uploaded on LMS, or you can use any other gif recording tool as well)<br />
•	First record must be with your own VU-ID in .gif file.<br />
If you do not submit any of the above-mentioned file or use some other VU-ID, you will be awarded Zero Marks.</p>
<p dir="auto">“The End”</p>
<p dir="auto"><img src="https://i.imgur.com/Xg7l62h.gif" alt="Solutionvid3.gif" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.secnto.com//post/6383</link><guid isPermaLink="true">https://community.secnto.com//post/6383</guid><dc:creator><![CDATA[zareen]]></dc:creator><pubDate>Mon, 18 Jan 2021 06:54:07 GMT</pubDate></item><item><title><![CDATA[Reply to CS301 Assignment 1 Solution and Discussion on Fri, 05 Jun 2020 09:34:37 GMT]]></title><description><![CDATA[<pre><code>/* Implementation of stack using array */

#include &lt;iostream&gt;
#include &lt;conio.h&gt;
using namespace std;

class  Stack  /* the Stack class */ 
{
    public:
        Stack() { 
			size = 0; 
			current = -1;
	 	} //constructor
			
        int pop() { 
			return data[current--];
			}    	// The pop function    
        
		void push(int x) {
			data[++current] = x;
			//cout&lt;&lt;A[current];
		} // The push function
        
		int top(){ 
			return data[current];
		}      	// The top function
        
		int isEmpty(){
			return ( current == -1 );
		} // Will return true when stack is empty
        
		int isFull(){ 
			return ( current == size-1);
		} // Will return true when stack is full	
		void setStackSize(int s){
			size = s;
			data = new int[size];
		}

     private:
       int   object;  				// The data element
       int   current; 				// Index of the array
       int   size;    				// max size of the array
       int   *data;    				// Array of 10 elements    
};	

// Main method
int main()
{
    int t_books= 0, size = 0;
	int scount = 0, hcount=0, ocount=0; // For counting of book i.e software , hardware and other books. 
        
	Stack stack; 				// creating a stack object
    
    cout&lt;&lt;"Set size of stack: ";
    cin&gt;&gt;size;
    stack.setStackSize(size);
    
    
    cout&lt;&lt;"How many Books you want to add into stack: ";
    cin&gt;&gt;t_books;
    
    int book;
    for(int i = 0; i &lt; t_books; i++)
    {
    	cout &lt;&lt;"\nEnter Book identity number that you want to insert into stack: ";
        cin&gt;&gt;book;
        
         if(!stack.isFull()) {		// checking stack is full or not
         	
         	stack.push(book);     	// push the element at the top    
        }
         else{
             cout&lt;&lt;"\n Unable to insert "&lt;&lt;book&lt;&lt;". Stack is full, can't insert more";
             break;
         }    
    }

    // pop the elements at the stack
    
    int current = 0;
    
    for (int i = 0; i &lt; t_books; i++)
    {
    	
        if(!stack.isEmpty()) {		// checking stack is empty or not
                  current = stack.pop();
                  if(current % 8 == 0){
                  	scount++;
                  	
                  }
                  else if(current % 5 == 0){
                  	hcount++;
                  }
                  else {
                  	ocount++;
                  }
			}
                
        else {
        
                  cout &lt;&lt;"\nStack is empty, sorry can't pop more";
                   getch();
                   break;
        }
    }
    
    if(scount == 0 &amp;&amp; hcount==0 &amp;&amp; ocount==0){
        cout&lt;&lt;"\nBooks not found\n";
    }
    else {    
        cout&lt;&lt;"\n\nTotal Software Book/Books = "&lt;&lt;scount;    
        cout&lt;&lt;"\n\nTotal Hardware Book/Books = "&lt;&lt;hcount;    
		cout&lt;&lt;"\n\nTotal Other Book/Books = "&lt;&lt;ocount;    
		
    }    
     getch();
}


</code></pre>
]]></description><link>https://community.secnto.com//post/5142</link><guid isPermaLink="true">https://community.secnto.com//post/5142</guid><dc:creator><![CDATA[Eshaal Khan]]></dc:creator><pubDate>Fri, 05 Jun 2020 09:34:37 GMT</pubDate></item></channel></rss>