Navigation

    Cyberian
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Pro Blog
    • Users
    • Groups
    • Unsolved
    • Solved
    Quiz 100% Result
    • CS301 GDB 1 Solution and Discussion

      zaasmi

      Re: CS301 GDB 1 Solution and Discussion

      Total Marks 5
      Starting Date Monday, February 08, 2021
      Closing Date Tuesday, February 09, 2021
      Status Open
      Question Title Graded Discussion Board
      Question Description
      GDB Scenario:

      Your friend is developing a maze puzzle game and already designed a module which can generate a random maze. The maze has one entry and one exit point. Now he needs to develop the module which will find the path from entry to exit points for randomly generated maze. Your friend wants the path searching should be quickest. He can use only Stack or Queue data structures to store maze’s visited locations for path generation. He is unable to decide the selection of data structure and asked you to help him.

      GDB Question:

      From Stack and Queue data structures which data structure you will suggest using for entry to exit path finding module? Select a data structure and give comments in favour to justify your selection. Also mention why you are not selecting the other data structure?

      Instructions:

      A concise, coherent and to the point answer is preferred over lengthy comment having irrelevant details. Answers, posted on regular Lesson’s MDB or sent through email will NOT be considered in any case.

      Best of Luck!

      CS301 – Data Structures
    • The objective of this assignment is

      zareen

      o Binary Search trees
      o AVL trees
      o Rotation cases of AVL trees
      o Balancing Factor of trees

      CS301 – Data Structures
    • CS301 Assignment 1 Solution and Discussion

      zaasmi

      Re: CS301 Assignment 1 Solution and Discussion

      Assignment No. 01

      Semester Spring 2020
      CS301- Data Structures
      Total Marks: 20

      Due Date :1 June 2020
      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 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).
      Uploading instructions
      For clarity and simplicity, You are required to Upload/Submit only ONE .CPP file.

      Note: Use ONLY Dev-C++ IDE.
      Objective
      The objective of this assignment is

      o To make you familiar of programming with stack data structure.

      For any query about the assignment, contact at [email protected]

      GOOD LUCK

      Marks: 20

      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.

      Program’s sample output is given below

      Output 1:
      7722eec0-3d47-4dfa-8e49-af71bc5276df-image.png

      Out Put 2:
      aeb43ac0-afd4-4ce3-9c15-6440d6bfb4d9-image.png

      Output 3:
      e51ed70a-a3a2-44b1-ae5a-d9e4c2c8f17a-image.png

      Solution Guidelines:

      First understand the code given in handouts about stack. Get stack size from user to allocate space for stack dynamically. Get identity number of books that user want to enter into the stack. Get value one by one and push into stack. Don’t allow popping if stack is empty and pushing if stack is full. If identity number of book is dividable by 8 and 5 then priority should be given to 8.
      Lectures Covered: This assignment covers Lecture # 1-7.
      Deadline: Your assignment must be uploaded/submitted at or before, 1 June 2020
      CS301 – Data Structures
    • CS301 Assignment 3 Solution and Discussion

      zaasmi

      Re: CS301 Assignment 3 Solution and Discussion

      Assignment No. 03

      SEMESTER FALL 2020
      CS301- Data Structures Total Marks: 20
      Due Date: 21/01/2021
      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 due date.
      o The submitted assignment is other than .doc/.docx 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).
      Uploading instructions

      o For clarity and simplicity, you are required to Upload/Submit only .doc/.docx file.

      Objective
      The objective of this assignment is:
      o Binary Search trees
      o AVL trees
      o Rotation cases of AVL trees
      o Balancing Factor of trees

      For any query about the assignment, contact at [email protected]
      GOOD LUCK
      Marks: 20

      Problem Statement:

      You are required to construct AVL tree from the following data:

      15 ,18 ,12, 8, 54, 5, 14, 13, 9, 61, 20, 17, 21

      Solution Guidelines:

      You need to insert these data items one by one starting from the data item 15 in the same order in which they have written above. Show and perform necessary rotations where needed. In Solution show only the final AVL tree and only those steps in which rotation is applied.

      Note: If you show only final tree and do not show the rotation steps then your marks will be deducted.
      Lectures Covered: This assignment covers Lecture # 15-26
      Deadline: Your assignment must be uploaded/submitted at or before January 21 , 2021

      CS301 – Data Structures
    • CS301 Assignment 2 Solution and Discussion Spring 2020

      zaasmi

      Re: CS301 Assignment 2 Solution and Discussion

      Assignment No. 02

      Spring 2020
      CS301- Data Structures
      Total Marks: 20

      Due Date: 17-Jun-2020
      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 due date.
       The submitted assignment is other than .CPP file.
       The submitted code does NOT compile.
       The submitted assignment does NOT open or file is corrupted.
       The assignment is copied (from other student or ditto copy from handouts or internet).

      Uploading instructions
      For clarity and simplicity, you are required to upload/submit only one .CPP file.

      Note: Use only Dev-C++ IDE.

      Objectives
      The objectives of this assignment are;

       To make you familiar of programming with Tree data structure
       To traverse Binary Search Tree (BST) using different techniques
       To perform some basic operations on BST

      For any query about the assignment, contact at [email protected]

      Good Luck!

      Total Marks: 20

      Problem Statement:

      As you know, Binary Search Tree (BST) has property that on the addition of a node in the tree, we compare it with root node. If new node is less than root node, it can be added to the left sub-tree. Otherwise, it will be added to the right sub-tree. So, the BST will have numbers (or nodes) less than the root in the left sub-tree and the numbers greater than the root will be in the right sub-tree.

      Following is a snapshot of Binary Search Tree (BST).

      You are required to develop a C++ program implementing Binary Search Tree (BST) data structure for the above scenario.

      For this you need to;

      Construct Binary Search Tree, based upon above given tree data Calculate minimum node (or number), maximum node, height and total number of nodes for BST
      Details:

      Your solution must contain a tree node class named as TNode, insert() method, buildTree() method, minNode() method, maxNode() method, treeHeight() method and countNodes() method. You should call BuildTree() method in main() method and call insert() method inside BuildTree() method so that insert() method can actually add nodes in BST.
      cf5cdf06-c8b4-453d-ae6a-ae97d76ff228-image.png

      You must call the above-mentioned methods from main to calculate minimum node, maximum node, height and total number of nodes for the BST.

      Remember, the height of root node is 1 while depth or level of root node is 0 in tree.

      Required Output:
      c8d35aaf-4090-460e-b4df-1d5c470a872d-image.png

      Note:
      Make sure to follow class name, method names and variable/objects names as mentioned above in the scenario. Moreover, your solution must be according to the Required Output. Otherwise, you will get Zero marks.
      Lectures Covered: Lecture No. 09 to 16.
      Deadline: Your assignment must be uploaded / submitted on or before, Jun 17, 2020.

      CS301 – Data Structures
    • CS301 GDB 1 Solution and Discussion

      zareen

      CS301 GDB 1 Solution and Discussion

      CS301 – Data Structures
    • CS301 Assignment 2 Solution and Discussion

      zareen

      Assignment No. 02
      SEMESTER Fall 2019
      CS301- Data Structures
      Total Marks: 20

      Due Date: 29-Nov, 2019
      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 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).
      Uploading instructions
      For clarity and simplicity, You are required to Upload/Submit only ONE .CPP file.

      Note: Use ONLY Dev-C++ IDE.
      Objective
      The objective of this assignment is

      o To make you familiar of Programming with Queue Data Structure.

      For any query about the assignment, contact at [email protected]

      GOOD LUCK

      Marks: 20

      Problem Statement:

      You have to implement a Queue Data Structure for student’s admission applications in the university by using Array in C++ language. In which you have to create:

      A structure (using struct keyword) named Student. A class named ArrQueue.

      Details:

      Student structure must have two variables of type string (using string.h library) in it.

      userVUID userDetail Structure Variables Description userVUID It will store the student id e.g. BC12345688 userDetail It will store user details as Name (Degree Program) e.g. Bilal (BSCS)

      ArrQueue should implement following data members and member functions:

      Data Members Description arr[arrLength] “arr” is an array of type Student which will store queue students information in the array. While “arrLength” is the length of the array which is 5. front front variable will store the value of array index of first user in the queue. rear rear variable will store the value of array index of last user in the queue. Methods Description enQue(X) Place X after the rear of the queue (If array have empty space). e.g. queue.enQue(X). You have to handle these cases for enQue(). 1. If queue is empty. Then add Student to Queue. 2. If queue is full. Then show message: “Queue is full”. deQue() Remove the student from front position in the queue and move all students forward in the queue. (If array is not empty). e.g. queue.deQue(). You have to handle these cases for deQue(). 1. If queue is empty. Then show message at “Que is empty cannot remove students”. 2. If queue is not empty, remove element from the queue. Note: Removal of Students from Queue will be according to First In First Out (FiFO) Method (Means a student who comes to queue first will remove from the queue first then others). queLength() Return size of Queue. (Not array size) e.g. queue.queLength(). isEmpty() Return TRUE if Queue is empty, FALSE otherwise. isFull() Return TRUE if Queue is full, FALSE otherwise. showQue() Will show the Queue data as given in below screenshots (Detailed Output Screenshot). e.g. queue.showQue().

      (“X” denote “Student” structure Object means a student profile record while “queue” denotes and Object of the class “ArrQueue”.)

      In the main() function you have to:

      Create an array of objects having size 5 and of type “Student” and store five student’s data in it. Make a queue and add all students in it by using for loop with enQue() method. Then show the array using showQue() method like given in “Main Output Screenshot”. Then you have to remove students from the queue according the following conditions e.g.
      Your id is “BC12345687” then last digit is 7.
      a. If last digit is Even Number then remove first two students from the queue using for loop with deQue() method. There will be 3 remaining students in the queue out of 5 as we have removed two students.
      For details see screenshots under “Main Output Screenshot” heading.
      b. If last digit is an Odd Number (e.g. in above id 7 is an odd number) then remove first one student form the queue using for loop with deQue() method. There will be 4 remaining students in the queue out of 5 as we have removed three students.
      For details see screenshots under “Main Output Screenshot” heading. After that show queue data using showQueue() method as given in “Main Output Screenshot”. Last student data should be your own data and all above ids must be one less than your id number according to Detailed Output Screenshot.

      Note:
      If you will not follow variables, functions and class names as mentioned and explained in this file also your actual output under heading “Main Output Screenshot” is not according to “Detailed Output Screenshot” then you will get Zero marks.
      Detailed Output Screenshot:

      Just For Your Information.

      793f564b-bafc-4c4b-8a42-1ddaf5058848-image.png

      Note: Last record must be your VU ID, Name and Degree Program.

      Main Output Screenshot:

      For Students Id’s having Odd number in last of your id.
      d83ecb32-2d3d-4a30-bbe5-65f21401bbc0-image.png

      For Students Id’s having Even number in last of your id.
      a7616a16-9840-485c-9039-dbe5517aeae3-image.png

      Lectures Covered: This assignment covers Lecture # 1-14.
      Deadline: Your assignment must be uploaded/submitted at or before 29-Nov, 2019.

      CS301 – Data Structures
    • CS301 Assignment 3 Solution and Discussion

      zareen

      Assignment No. 03
      Fall 2019
      CS301 - Data Structures
      Total Marks: 20

      Due Date: 21-1-2020
      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 due date.
      o The submitted assignment is other than C++ file (.cpp).
      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).
      Uploading instructions
      You are required to upload / submit .CPP file.
      Use Dev-C++, Version 5.11 or above.

      Objective
      The objective of this assignment is ;

      o To make you familiar with Huffman Encoding technique.
      o To learn how to write a program for Huffman Encoding in C++.

      For any query about the assignment, contact at [email protected]

      GOOD LUCK

      Problem Statement

      As you know, Huffman Encoding is a technique developed and used for data compression. It is widely used algorithm for JPEG images. Incomplete code of Huffman Encoding is given below. You are required to complete the missing code.

      In the given code we are using two classes and two functions. The first class HeapNode_Min will consist of data members and a constructor. The second class Analyze will consist of a function which will compare two heap nodes and will return the result. We are also using display function to print the codes of Huffman tree from the root. HCodes function is used to build a Huffman tree, this function is using two while loops and at the end it calls display_Codes function. In main function we are using two arrays, one for frequency and the second one for alphabets. We are using size_of variable to store the size of data types after their division. At the end of the main function we will call HCodes function.

      Note: Just add the missing code. Don’t change the given code. Instructions are highlighted with red color.

      // Huffman Coding program in c++ #include <bits/stdc++.h> using namespace std; class HeapNode_Min { // Tree node of Huffman public: //Add data members here. HeapNode_Min(char d, unsigned f) { //Complete the body of HeapNode_Min function } }; class Analyze { // two heap nodes comparison public: bool operator()(HeapNode_Min* l, HeapNode_Min* r) { (l->f > r->f); //Complete this statement } }; void display_Codes(HeapNode_Min* root, string s) // To print codes of huffman tree from the root. { if (!root) return; if (root->d != '$') cout << root->d << "\t: " << s << "\n"; display_Codes(root->l, s + "0"); display_Codes( ); //Complete this statement by passing arguments } void HCodes(char data[], int freq[], int s) // builds a Huffman Tree { HeapNode_Min *t,*r, *l ; // top, right, left priority_queue<HeapNode_Min*, vector<HeapNode_Min*>, Analyze> H_min; int a=0; while (a<s){H_min.push(new HeapNode_Min(data[a], freq[a])); ++a;} while (H_min.size() != 1) { l = H_min.top(); H_min.pop(); r = H_min.top(); H_min.pop(); t = new HeapNode_Min('$', r->f + l->f); t->r = r; t->l = l; H_min.push(t); } display_Codes(H_min.top(), ""); } int main() { int frequency[] = { 3, 6, 11, 14, 18, 25 }; char alphabet[] = { 'A', 'L', 'O', 'R', 'T', 'Y' }; int size_of = sizeof() / sizeof(); //Complete this statement by passing data type to both sizeof operators cout<<"Alphabet"<<":"<<"Huffman Code\n"; cout<<"--------------------------------\n"; //Call Huffman_Codes function. return 0; }

      Sample Output of the above program is given below.
      9aab7e1d-84a7-4700-a725-d558070fc0b6-image.png

      Important Note: Use Dev-C++, Version 5.11 or above.
      Deadline: Your assignment must be uploaded/submitted at or before 21-1-2020.

      CS301 – Data Structures
    • CS301 Quiz 1 Solution and Discussion

      zareen

      Share your current Quiz Data

      CS301 – Data Structures
    • CS301 Assignment 1 Solution and Discussion

      zareen

      Assignment No. 01
      Semester Fall 2019
      CS301- Data Structures Total Marks: 20

      Due Date : 18-Nov-2019
      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 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).
      Uploading instructions
      For clarity and simplicity, You are required to Upload/Submit only ONE .CPP file.

      Note: Use ONLY Dev-C++ IDE.
      Objective
      The objective of this assignment is

      o To make you familiar with implementing the Doubly Linked List data structure in C++ programming language.

      For any query about the assignment, contact at [email protected]

      GOOD LUCK

      Marks: 20
      Problem Statement:

      You have to implement a Double Linked List in C++ language in which you have to create a structure and two classes as given below:

      A structure named as “StudentDetail” by using struct keyword.
      StudentDetail structure should consist of following data members of type “string”.
      name
      vuid

      A node class named as “Node” by using class keyword.
      Node class will have following data members and member functions:
      cda47932-36ec-4210-ab0a-b3bee8bce8dc-image.png

      (“X” denotes StudentDetail variable means the student details and “Y” denotes the data value of the node).

      A doubly linked list class named as “DoublyLinkedList” by using class keyword.
      DoublyLinkedList class will have following data members and member functions:
      a46ffa50-421f-4ab2-9d20-67bfac975435-image.png

      Detailed description of member functions of DoublyLinkList class:

      addAtBegining(X): To add the node at the beginning of the doubly linked list class.
      4da1ea58-b161-48f7-98b0-9684d220156b-image.png

      addAtEnd(X): To add the node at the End of the doubly linked list class.
      08b97a59-7a5e-4312-9d83-5cdb81890a8f-image.png

      delNode(): To delete a node pointed by current pointer in the doubly linked list.
      59d9f4dd-919a-4db9-991a-950c4d6bb829-image.png

      display():To display all student details in doubly linked list.

      (“X” denote Node to add in the doubly linked list).

      In the main ( ) function you have to do the following:

      Create two objects of type StudentDetail at the Beginning of the doubly linked list class using addATBegining (X) method of DoublyLinkedList and use display() method to display doubly linked list.
      Note that first object should contain your own VU ID and your own name otherwise you will get zero marks.

      Create one objects of type StudentDetail at the End of the doubly linked list class using addAtEnd (X) method of DoublyLinkedList and use display() method to display doubly linked list.

      Delete current node of the doubly linked list and use display() method to display doubly linked list.

      Display doubly linked list after calling each functions.

      Detailed Output Screenshot:
      fcd2ba41-d1ae-4c73-9648-8180c609cba1-image.png

      Lectures Covered: This assignment covers Lecture # 1-8.
      Deadline: Your assignment must be uploaded/submitted at or before 18-Nov-2019.

      CS301 – Data Structures
    • CS301 Final Term Current Paper

      zareen

      Cs301 Today paper
      Q1.biner tree bnawa tha OS k levels btao.
      Q2.carictrics of avl tree.
      Q3.if node leaf and non leafe in binry tree then what the hight of tree of its depth is 7?
      Q.4hight of nodes if hight is 5?
      Q.6 [2 9 7 5 8] sort it.
      Q.7 ik tree tha osko array mn conert krna tha.
      Q8.crictristics of union method
      Mostly mcqs and questions are from moazz files.
      Shared By @Awais

      CS301 – Data Structures

    SOLVED CS301 Assignment 1 Solution and Discussion

    CS301 – Data Structures
    assignment 1 cs301 discussion solution spring 2020
    3
    4
    25
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • zaasmi
      zaasmi Cyberian's Gold last edited by

      Re: CS301 Assignment 1 Solution and Discussion

      Assignment No. 01 
      

      Semester Spring 2020
      CS301- Data Structures
      Total Marks: 20

      Due Date :1 June 2020
      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 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).
      Uploading instructions
      For clarity and simplicity, You are required to Upload/Submit only ONE .CPP file.

      Note: Use ONLY Dev-C++ IDE.
      Objective
      The objective of this assignment is

      o To make you familiar of programming with stack data structure.

      For any query about the assignment, contact at [email protected]

      GOOD LUCK

      Marks: 20  
      

      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.

      Program’s sample output is given below

      Output 1:
      7722eec0-3d47-4dfa-8e49-af71bc5276df-image.png

      Out Put 2:
      aeb43ac0-afd4-4ce3-9c15-6440d6bfb4d9-image.png

      Output 3:
      e51ed70a-a3a2-44b1-ae5a-d9e4c2c8f17a-image.png

      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.
        Lectures Covered: This assignment covers Lecture # 1-7.
        Deadline: Your assignment must be uploaded/submitted at or before, 1 June 2020
      1 Reply Last reply Reply Quote 0
      • Eshaal Khan
        Eshaal Khan last edited by

        /* Implementation of stack using array */
        
        #include <iostream>
        #include <conio.h>
        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<<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<<"Set size of stack: ";
            cin>>size;
            stack.setStackSize(size);
            
            
            cout<<"How many Books you want to add into stack: ";
            cin>>t_books;
            
            int book;
            for(int i = 0; i < t_books; i++)
            {
            	cout <<"\nEnter Book identity number that you want to insert into stack: ";
                cin>>book;
                
                 if(!stack.isFull()) {		// checking stack is full or not
                 	
                 	stack.push(book);     	// push the element at the top    
                }
                 else{
                     cout<<"\n Unable to insert "<<book<<". Stack is full, can't insert more";
                     break;
                 }    
            }
        
            // pop the elements at the stack
            
            int current = 0;
            
            for (int i = 0; i < 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 <<"\nStack is empty, sorry can't pop more";
                           getch();
                           break;
                }
            }
            
            if(scount == 0 && hcount==0 && ocount==0){
                cout<<"\nBooks not found\n";
            }
            else {    
                cout<<"\n\nTotal Software Book/Books = "<<scount;    
                cout<<"\n\nTotal Hardware Book/Books = "<<hcount;    
        		cout<<"\n\nTotal Other Book/Books = "<<ocount;    
        		
            }    
             getch();
        }
        
        
        
        1 Reply Last reply Reply Quote 0
        • zareen
          zareen Cyberian's Gold @zareen last edited by zareen

          @zareen
          100% Solution Code

          #include <iostream>
          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->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->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<<"\nEnter VU ID: ";
                      cin>>loc_vuid;
                      newStudent->setVUID(loc_vuid);
                      
                      cout<<"Enter Marks: ";
                      cin>>loc_marks;
                      newStudent->setMarks(loc_marks); 
                      
                      cout<<"Enter First Name: ";
                      cin>>loc_fname;
                      newStudent->setFirstName(loc_fname);
                      
                      cout<<"Enter Last Name: ";
                      cin>>loc_lname;
                      newStudent->setLastName(loc_lname);
                     
                      if(head->getNext() == NULL){
                     		newStudent->setNext(NULL);
                         	head->setNext(newStudent);               	
                         	current   =   newStudent;
          		    }
          		    else{
          		    	Student *temp = head;
          		    	while(temp->getNext() != NULL && temp->getNext()->getMarks() >= loc_marks){
          		    		temp = temp->getNext();
          				}
          				current = temp;
          				newStudent->setNext(current->getNext());
                         	current->setNext( newStudent );               	
                         	current   =   newStudent;
          		   }         
                  };        
          
                  // list class method to get the information of Student
                  void getInfo() { 
                      if (current  !=  NULL){
          				cout<<"VU ID: "<<current->getVUID()<<endl;
          	            cout<<"Marks: "<<current->getMarks()<<endl;				 
          				cout<<"First Name: "<<current->getFirstName()<<endl;
          				cout<<"Last Name: "<<current->getLastName()<<endl<<endl;				
          			}
                  };				          
                         
                  // list class method to move current to next Student
                  bool next() {
                      if (current  ==  NULL){
                          return  false;
                      }  
                      current  =  current->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<<"1. To Add New Student in Ranking"<<endl;
                  cout<<"2. To Display Ranking"<<endl;
                  cout<<"3. To Close"<<endl<<endl;
                  cout<<"Enter Your Choice: (1, 2 or 3) ";
                  cin>> input;
                  
                  if(input == 1) {
                  	lst.add();
          			cout<<"Student's information saved successfully.\n"; 
                  }
                  else if(input == 2) {
                  	cout<<"\nRanking Chart"<<endl;
                      showStudents(lst);
                      return 0;
                  }
                  else {
                  	return 0;
                  }		
          	}
          }
          
          
          1 Reply Last reply Reply Quote 0
          • zareen
            zareen Cyberian's Gold last edited by zareen

            Data Structures (CS301)
            Assignment # 01
            Semester Fall 2020
            Total Marks = 20
            Deadline Date
            26th Nov 2020

            Please carefully read the following instructions before attempting assignment.
            RULES FOR MARKING
            It should be clear that your assignment would not get any credit if:
            • The assignment is submitted after the due date.
            • The submitted assignment does not open or file is corrupt.
            • Strict action will be taken if submitted solution is copied from any other student or from the internet.

            Lectures:

            • Lectures 1 to 7 are covered in this assignment
            NOTE
            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.
            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.
            For any query, feel free to email at: [email protected]

            Problem Statement:
            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.
            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.
            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.
            Sample Output:
            See the gif file attached with this assignment file.

            Note:
            DO REMEMBER that you must use your VUID as an input in this program.

            Submission details
            Following Files Must be submitted in a single zip or rar file.
            • C++ code file (file name should be your VUID)
            • 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)
            • First record must be with your own VU-ID in .gif file.
            If you do not submit any of the above-mentioned file or use some other VU-ID, you will be awarded Zero Marks.

            “The End”

            Solutionvid3.gif

            zareen 1 Reply Last reply Reply Quote 0
            • Eshaal Khan
              Eshaal Khan last edited by

              /* Implementation of stack using array */
              
              #include <iostream>
              #include <conio.h>
              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<<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<<"Set size of stack: ";
                  cin>>size;
                  stack.setStackSize(size);
                  
                  
                  cout<<"How many Books you want to add into stack: ";
                  cin>>t_books;
                  
                  int book;
                  for(int i = 0; i < t_books; i++)
                  {
                  	cout <<"\nEnter Book identity number that you want to insert into stack: ";
                      cin>>book;
                      
                       if(!stack.isFull()) {		// checking stack is full or not
                       	
                       	stack.push(book);     	// push the element at the top    
                      }
                       else{
                           cout<<"\n Unable to insert "<<book<<". Stack is full, can't insert more";
                           break;
                       }    
                  }
              
                  // pop the elements at the stack
                  
                  int current = 0;
                  
                  for (int i = 0; i < 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 <<"\nStack is empty, sorry can't pop more";
                                 getch();
                                 break;
                      }
                  }
                  
                  if(scount == 0 && hcount==0 && ocount==0){
                      cout<<"\nBooks not found\n";
                  }
                  else {    
                      cout<<"\n\nTotal Software Book/Books = "<<scount;    
                      cout<<"\n\nTotal Hardware Book/Books = "<<hcount;    
              		cout<<"\n\nTotal Other Book/Books = "<<ocount;    
              		
                  }    
                   getch();
              }
              
              
              
              1 Reply Last reply Reply Quote 0
              • First post
                Last post

              50% Off on Your FEE Join US!

              Quiz 100% Result If you want to know how you can join us and get 50% Discout on your FEE ask Cyberian in Chat Room! Quiz 100% Result Quiz 100% Result
              solution1241 discussion1193 fall 2019813 assignment 1425 assignment 2295 spring 2020265 gdb 1246 assignment 382 crw10174 spring 201955
              | |
              Copyright © 2021 Cyberian Inc. Pakistan | Contributors
              Live Chat