Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Pro Blog
  • Users
  • Groups
  • Unsolved
  • Solved
Collapse
Secnto AI
  1. Secnto AI
  2. Categories
  3. Virtual University
  4. CS301 – Data Structures
  5. CS301 Assignment 2 Solution and Discussion
CS301 Final Term Current Paper
zareenZ
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
CS301 Assignment 1 Solution and Discussion
zareenZ
Re: CS301 Assignment 1 Solution and Discussion Assignment No. 1 Semester: Spring 2021 CS301 – Data Structures Total Marks: 20 Due Date: 18/05/2021 Instructions Please read the following instructions carefully before submitting the assignment solution: It should be clear that your assignment will not get any credit/marks if: o Assignment is submitted after due date. o Submitted assignment does not open or file is corrupt. o Assignment is copied (From internet/students). Recommended Tools • Dev C++ Objectives: To enable students to understand and practice the concepts of: • Linked list implementation • Efficient memory management • Efficient use of pointer Assignment Submission Instructions You have to submit only .zip file which will have code (.cpp) and screenshot image files on the assignments interface from your LMS account. Assignment submitted in any other format will not be accepted and will be scaled with zero marks. No excuse will be accepted on submitting solution file in any other format. For any query related to assignment, please contact cs301@vu.edu.pk. Problem Statement: In the lesson videos and handouts you learned to save only one integer element as data in a node. Please note, it is not compulsory to have only one value in a node. There can be more than one and different types of elements as data of a node but pointer will remain one for singly linked list. Write a C++ program to implement linked list data structure. In this problem every node should have two data elements called name and course of a student and a pointer to link the current node to the next node. Your program should prompt the user to enter name and course code of a student and save it into a Node (Student). User can enter the records of multiple students. So you need to create a linked list of students. One node of list will represent one student. Instead of saving the name of course you should use code of course into Student node. This will help you save lots of memory. “short int” type variable can be used to save code of course which will take two bytes while name of course will take many bytes. This technique will help you save lots of memory. Use the following course names and codes while entering the record of a student. Course Name Course Code Introduction to Computing 1 Introduction to Programming 2 Data Structures 3 Object Oriented Programming 4 After saving the required information of all students, you need to perform following operations operated through menu showing in sample output video. • Show the names of students enrolled in a specific or all courses (user will enter a choice of operation). • Show the count of students enrolled in a specific or all courses (user will enter a choice of operation). • Option to close the program by selection from menu as showing in sample output video. • While testing your application and entering the record of first student, use your VU ID for the name of student. Take screenshot of your input which should be showing your VU ID entered as first student name. Zip your code (.cpp) and screenshot image files and submit zip file from your LMS account. Sample Output: For sample output watch the video file “A1 Sample Output.mp4” attached with this assignment file. Lectures Covered: (Lecture # 1- 8) and Due date to submit solution: (Tuesday, May 18, 2021). Solution: //vu id XXXXXXXXXXXXXXXXXX #include <iostream> #include <conio.h> using namespace std; class student{ public: string name; int code; student* next_add; }; class linked_list{ public: student *head=NULL; void menu(); int get_code(); string set_name(); string get_name(); string set_name(string n); void insert(); void show_all(); void show_one(); void show_two(); void show_three(); void show_four(); }; string linked_list::get_name(){ string name; cout<<"enter the name of the student: "; cin>>name; return name; } int linked_list::get_code(){ int code; cout<<"\n\n1. introduction to computing: " ; cout<<"\n2. introduction to programming "; cout<<"\n3. data structures "; cout<<"\n4. object oriented programming "; cout<<"\nEnter the course name "; cin>>code; return code; } string linked_list::set_name(string n){ return n; } void linked_list::insert(){ student *new_node=new student; new_node->name=get_name(); new_node->code=get_code(); new_node->next_add=NULL; if(head==NULL){ head=new_node; } else{ student*ptr=head; while(ptr ->next_add!=NULL){ ptr=ptr->next_add; } ptr->next_add=new_node; } cout<<" students information saved successfully."; } void linked_list::menu(){ p: int choice; cout<<"\n\n0. display all students "; cout<<"\n1. display all students enrolled in introduction to computing "; cout<<"\n2. display all students enrolled in introduction to programming "; cout<<"\n3. display all students enrolled in data structures "; cout<<"\n4. display all students enrolled in object oriented programming "; cout<<"\n5. close the program "; cout<<"\n\n select an option for required operation: "; cin>>choice; switch(choice){ case 0: show_all(); break; case 1: show_one(); break; case 2: show_two(); break; case 3: show_three(); break; case 4: show_four(); break; case 5: exit(0); } goto p; } void linked_list::show_all(){ int count=0; cout<<"\n\nfollowing students are enrolled in all courses: "; student *ptr=head; while(ptr!=NULL){ cout<<"\nStudent name: " <<set_name(ptr->name); count ++; ptr=ptr->next_add; } cout<<"\nenrollemnet count " <<count ; } void linked_list::show_one(){ int count=0; cout<<"\n\nfollowing students are enrolled in intoduction to computing: "; student *ptr=head; while(ptr!=NULL){ if(ptr->code==1){ cout<<"\nStudent name: "<<set_name(ptr->name); count ++; } ptr=ptr->next_add; } cout<<"\nenrollement cout:"<<count; } void linked_list::show_two(){ int count=0; cout<<"\n\nfollowing students are enrolled in intoduction to computing: "; student *ptr=head; while(ptr!=NULL){ if(ptr->code==2){ cout<<"\nStudent name: "<<set_name(ptr->name); count ++; } ptr=ptr->next_add; } cout<<"\nenrollement cout:"<<count; } void linked_list::show_three(){ int count=0; cout<<"\n\nfollowing students are enrolled in intoduction to computing: "; student *ptr=head; while(ptr!=NULL){ if(ptr->code==3){ cout<<"\nStudent name: "<<set_name(ptr->name); count ++; } ptr=ptr->next_add; } cout<<"\nenrollement cout:"<<count; } void linked_list::show_four(){ int count=0; cout<<"\n\nfollowing students are enrolled in intoduction to computing: "; student *ptr=head; while(ptr!=NULL){ if(ptr->code==4){ cout<<"\nStudent name: "<<set_name(ptr->name); count ++; } ptr=ptr->next_add; } cout<<"\nenrollement cout:"<<count; } main(){ linked_list obj; char x; do { obj.insert(); cout<<"\ndo you want to add another student?" ; cin>>x; } while(x=='Y'||x=='y'); obj.menu(); }
CS301 – Data Structures
CS301 GDB 1 Solution and Discussion
zaasmiZ
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
zareenZ
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
zaasmiZ
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 cs301@vu.edu.pk 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: [image: XUFXxkd.png] Out Put 2: [image: Fk4idQA.png] Output 3: [image: xbiFw6G.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
zaasmiZ
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 cs301@vu.edu.pk 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
zaasmiZ
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 CS301@vu.edu.pk 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. [image: bBOo0CX.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: [image: Yi698Gk.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
zareenZ
CS301 GDB 1 Solution and Discussion
CS301 – Data Structures
CS301 Assignment 2 Solution and Discussion
zareenZ
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 CS301@vu.edu.pk 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. [image: NEAmAMH.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. [image: fUV3wVb.png] For Students Id’s having Even number in last of your id. [image: q3qwGRV.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
zareenZ
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 CS301@vu.edu.pk 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. [image: crvVrkX.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
zareenZ
Share your current Quiz Data
CS301 – Data Structures
CS301 Assignment 1 Solution and Discussion
zareenZ
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 cs301@vu.edu.pk 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: [image: 0Q9PkDw.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: [image: DbRi787.png] Detailed description of member functions of DoublyLinkList class: addAtBegining(X): To add the node at the beginning of the doubly linked list class. [image: zSdkfUT.png] addAtEnd(X): To add the node at the End of the doubly linked list class. [image: U7K8PxG.png] delNode(): To delete a node pointed by current pointer in the doubly linked list. [image: GfFKhEd.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: [image: YNo870E.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 Assignment 2 Solution and Discussion

Scheduled Pinned Locked Moved Solved CS301 – Data Structures
cs301assignment 2solutiondiscussionfall 2019
2 Posts 1 Posters 2.0k Views 1 Watching
  • 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.
  • zareenZ Offline
    zareenZ Offline
    zareen
    Cyberian's Gold
    wrote on last edited by
    #1

    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 CS301@vu.edu.pk

    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:

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

    Details:

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

    1. userVUID
    2. 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:

    1. Create an array of objects having size 5 and of type “Student” and store five student’s data in it.
    2. 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”.
    3. 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.
    4. After that show queue data using showQueue() method as given in “Main Output Screenshot”.
    5. 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:

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

    2. 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.

    Discussion is right way to get Solution of the every assignment, Quiz and GDB.
    We are always here to discuss and Guideline, Please Don't visit Cyberian only for Solution.
    Cyberian Team always happy to facilitate to provide the idea solution. Please don't hesitate to contact us!
    %(red)[NOTE: Don't copy or replicating idea solutions.]
    Quiz Copy Solution
    Mid and Final Past Papers
    Live Chat

    1 Reply Last reply
    0
    • zareenZ Offline
      zareenZ Offline
      zareen
      Cyberian's Gold
      wrote on last edited by
      #2

      100% Solved:

      #include <iostream>
      #include <string.h> 
      using namespace std;
      
      const int arrLength = 10;
      
      struct Student{
      	string userVUID;
      	string userDetails;
      	
      }std1={"NULL","NULL"};
      
      class ArrQueue{
      private:
      	//Data Members
      	Student arr[arrLength];
      	int front;
      	int rear;
      	
      public:
      	//Constructor
      	ArrQueue(){
      		for(int i=0; i<arrLength; i++)
      			arr[i] = std1;
      		
      		front = -1;
      		rear = -1;
      	}
      	
      	//Member Functions
      	void enQue(Student std){
      		
      		if(isEmpty()){
      			arr[0] = std;
      			front++;
      			rear++;
      		}
      		else if(isFull()){
      			cout << " Queue is full.";
      		}
      		else{
      			arr[rear+1] = std;
      			rear++;
      		}
      	}
      	
      	void deQue(){
      		
      		if(isEmpty()){
      			cout<< " No Student In the Queue.\n";
      		}
      		else if(rear == 0){
      			arr[front] = std1;
      			front = -1;
      			rear = -1; 
      		}
      		else{
      			
      			int tempfront = front;
      			arr[front] = std1;
      			
      			for(int i=1; i<=rear; i++ ){
      				arr[front] = arr[i];
      				front++;
      			}
      
      			rear--;
      			front = tempfront;
      		}
      	}
      	
      	int queLength(){
      		return rear+1;
      	}
      	
      	bool isEmpty(){
      		if(front==-1 || rear==-1)
      			return true;
      		else
      			return false;
      	}
      	
      	bool isFull(){
      		if(rear == arrLength-1)
      			return true;
      		else
      			return false;
      	}
      	
      	void showQue(){
      		cout << "\n |Sr. VU ID            Details     |";
      		cout << "\n --- -------------------------------\n";
      		for(int i=front; i<=rear; i++){
      			cout<<"  "<< i+1<< ".  "<< arr[i].userVUID << "       " << arr[i].userDetails <<"\n";
      		}
      	}
      	
      };
      
      int main(){
      	/*Code For Even Id's 
      	Student std[] = {{"BC12345684","Bilal (BSCS)"},
      					 {"BC12345685","Bilal (BSCS)"},{"BC12345686","Bilal (BSCS)"},{"BC12345687","Bilal (BSCS)"},
      					 {"BC12345688","Bilal (BSCS)"}};*/
      	
      	/*Code For Odd Id's */
      	Student std[] = {{"BC12345683","Bilal (BSCS)"},
      					 {"BC12345684","Bilal (BSCS)"},{"BC12345685","Bilal (BSCS)"},{"BC12345686","Bilal (BSCS)"},
      					 {"BC12345687","Bilal (BSCS)"}};
      	ArrQueue arrQue;
      	
      	cout << "\n -----------------------------------";
      	cout << "\n |  Queue (After Adding Students)  |";
      	cout << "\n -----------------------------------";
      	for(int i=0; i<=4; i++){
      		arrQue.enQue(std[i]);
      	}
      	arrQue.showQue();
      	
      	cout << "\n -----------------------------------";
      	cout << "\n | Queue (After Removing Students) |";
      	cout << "\n -----------------------------------";
      	
      	/* Code For Even Id's
      	for(int i=0; i<=1; i++){
      		arrQue.deQue();
      	}*/
      	
      	/*Code For Odd Id's*/
      	for(int i=0; i<1; i++){
      		arrQue.deQue();
      	}
      	
      	arrQue.showQue();
      }
      
      

      Discussion is right way to get Solution of the every assignment, Quiz and GDB.
      We are always here to discuss and Guideline, Please Don't visit Cyberian only for Solution.
      Cyberian Team always happy to facilitate to provide the idea solution. Please don't hesitate to contact us!
      %(red)[NOTE: Don't copy or replicating idea solutions.]
      Quiz Copy Solution
      Mid and Final Past Papers
      Live Chat

      1 Reply Last reply
      0

      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      How to Build a $1,000/Month PAK VS BAN Live Live Cricket Streaming
      File Sharing
      Earn with File Sharing

      1

      Online

      3.0k

      Users

      2.8k

      Topics

      8.2k

      Posts
      solution
      1235
      discussion
      1195
      fall 2019
      813
      assignment 1
      428
      assignment 2
      294
      spring 2020
      265
      gdb 1
      238
      assignment 3
      79
      • PM. IMRAN KHAN
        undefined
        4
        1
        4.0k

      • Are the vaccines halal or not?
        undefined
        4
        1
        3.8k

      • All Subjects MidTerm and Final Term Solved Paper Links Attached Please check moaaz past papers
        zaasmiZ
        zaasmi
        3
        26
        75.1k

      • CS614 GDB Solution and Discussion
        M
        moaaz
        3
        3
        8.1k

      • How can I receive Reputation earning from Cyberian? 100% Discount on Fee
        Y
        ygytyh
        3
        28
        23.9k
      cyberianC
      cyberian
      | |
      Copyright © 2010-26 RUP Technologies LLC. USA | Contributors
      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Pro Blog
      • Users
      • Groups
      • Unsolved
      • Solved