CS301 Assignment No 03 Fall 2019 Solution & Discussion Due Date: 21-01-2020
Tags:
Please Discuss here about this assignment.Thanks
Our main purpose here discussion not just Solution
Students having same subject can start discussion here to solve assignment, GDB & Quiz and can clear their concepts until solution is provided.
P.S: Please always try to add the discussion in proper format title like “CS101 Assignment / GDB No 01 Solution & Discussion Due Date: ___________”
Then copy Questions from assignment file and paste in Discussion.
+ http://bit.ly/vucodes (For Assignments, GDBs & Online Quizzes Solution)
+ http://bit.ly/papersvu (For Past Papers, Solved MCQs, Short Notes & More)
+ Click Here to Search (Looking For something at vustudents.ning.com?)
+ Click Here to Join (Our facebook study Group)
CS301 Assignment No 03 Solution Fall 2019
below link
CS301_Assignmnet_03_Solution_Fall_2019_vustudents.ning.com.cpp
this solution is not match with the code of assignment and generating error
CS301 Data Structures Assignment 3 Solution & Discussion Fall 2019
Assignment No. 03 Fall 2019 |
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. |
Important Note: Use Dev-C++, Version 5.11 or above. Deadline: Your assignment must be uploaded/submitted at or before 21-1-2020. |
Please share idea solution.
CS301 Data Structures Assignment 3 Solution & Discussion Fall 2019
Solution Idea:
using namespace std;
#include <stdlib.h>
#include <iostream>
struct StudentDetail{
string name;
string vuid;
};
//class Node* head;
class Node{
struct StudentDetail newStd;
class Node* next;
class Node* prev;
void Set(string name,string vuid)
{
newStd.name=name;
newStd.vuid=vuid;
}
Node Get()
{
}
void setNext(string name,string vuid){
if(next==NULL)
{
}
else
{
class Node* newNode= new Node();
newStd.name=name;
newStd.vuid=vuid;
newNode->next= newNode;
} }
string getNext()
{
next;
}
void setPrev(string name,string vuid){
if(next==NULL)
{
}
else
{
class Node* newNode= new Node();
newStd.name=name;
newStd.vuid=vuid;
newNode->next= newNode;
} }
string getPrev()
{
prev;
}
};
class DoublyLinkedList{
public:
struct StudentDetail newStd;
class DoublyLinkedList* headPtr;
class DoublyLinkedList* curPtr;
class DoublyLinkedList* nextPtr;
int size;
//dfdf
class DoublyLinkedList* headDlinkList=NULL;
void addAtBegining(string vuid, string name)
{
class DoublyLinkedList* dNode= new DoublyLinkedList();
dNode->newStd.vuid=vuid;
dNode->newStd.name=name;
dNode->nextPtr=headDlinkList;
headDlinkList= dNode;
dNode->curPtr=dNode;
}
void addAtEnd(string vuid, string name)
{
class DoublyLinkedList* dNode= new DoublyLinkedList();
dNode->newStd.vuid=vuid;
dNode->newStd.name=name;
dNode->nextPtr=headDlinkList;
headDlinkList= dNode;
dNode->curPtr=dNode;
}
void delNode()
{
class DoublyLinkedList* temp1=curPtr;
class DoublyLinkedList* temp2= temp1;
temp1->nextPtr= temp2->nextPtr;
free(temp2);
}
void print()
{
class DoublyLinkedList* temp= headDlinkList;
while(temp!=NULL)
{
couttemp->newStd.vuid" "temp->newStd.nameendl;
temp= temp->nextPtr;
}
}
};
int main()
{
string vuid,name;
cout"Add your vuID and Name at First Position "endl;
cout"_ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _"endl;
DoublyLinkedList dlist1;
cin>>vuid;
cin>>name;
dlist1.addAtBegining(vuid,name);
dlist1.print();
cout"Insertion At Beginning in doubly Link List "endl;
cout"_ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _"endl;
cin>>vuid;
cin>>name;
dlist1.addAtBegining(vuid,name);
dlist1.print();
cout"Insertion At End in doubly Link List "endl;
cout"_ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _"endl;
cin>>vuid;
cin>>name;
dlist1.addAtEnd(vuid,name);
dlist1.print();
cout"Deletion of Current Node (Last Node) "endl;
cout"_ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _"endl;
dlist1.delNode();
dlist1.print();
}
CS301 Assignment No 03 Solution Fall 2019
below link
CS301_Assignmnet_03_Solution_Fall_2019_vustudents.ning.com.cpp
sir its totaly different solution not match with the question
out not same according to the question. this solution is not correct sir
***********
© 2021 Created by + M.Tariq Malik.
Powered by
Promote Us | Report an Issue | Privacy Policy | Terms of Service
We are user-generated contents site. All product, videos, pictures & others contents on site don't seem to be beneath our Copyrights & belong to their respected owners & freely available on public domains. We believe in Our Policy & do according to them. If Any content is offensive in your Copyrights then please email at m.tariqmalik@gmail.com with copyright detail & We will happy to remove it immediately.
Management: Admins ::: Moderators
Awards Badges List | Moderators Group
All Members | Featured Members | Top Reputation Members | Angels Members | Intellectual Members | Criteria for Selection
Become a Team Member | Safety Guidelines for New | Site FAQ & Rules | Safety Matters | Online Safety | Rules For Blog Post