6/9/2019 COMP9319 2019T2 Assignment 1 https://www.cse.unsw.edu.au/~wong/cs9319-2019a1.html 1/3 COMP9319 2019T2 Assignment 1: LZW Encoding and Decoding Your task in this assignment is to implement the...

1 answer below »
I will request for changes after i get the solution as well. because if it doesn't work in my Uni computer i need to make changes


6/9/2019 COMP9319 2019T2 Assignment 1 https://www.cse.unsw.edu.au/~wong/cs9319-2019a1.html 1/3 COMP9319 2019T2 Assignment 1: LZW Encoding and Decoding Your task in this assignment is to implement the original LZW encoder and decoder with 14-bit 16384 dictionary entries, called lencode and ldecode, in C/C++. After the dictionary is full, no new entries can be added. This assignment is to let you understand how LZW works, rather than to produce encoded files with reduced size. Therefore, the encoder will take input from the the standard input and output directly to the standard output. You may assume the input contains one or more visible ASCII characters (plus spaces and tabs). You may further assume that there is one and only one newline character at the end. You do not need to encode this newline character and you should just treat it as EOF as shown in the examples below. To be able to decode and get back the identical file to the original file, make sure you also output one newline character accordingly at the end, as illustrated in the examples. For example, %wagner> cat test.txt ^WED^WE^WEE^WEB^WET %wagner> cat test.txt | lencode ^ W E D 256 E 260 261 257 B 260 T %wagner> cat test.txt | lencode | ldecode > test.out %wagner> diff test.txt test.out %wagner> You may assume that a space is used as the delimiter between the codewords. For instance, if there are three consecutive spaces between two codewords, the second space is a codeword itself and the other twos are delimiters. Similarly, the symbols that are digits can be easily distinguished from dictionary references: %wagner> cat numbers.txt 123123123 %wagner> cat numbers.txt | lencode 1 2 3 256 258 257 %wagner> You should submit totally two C or C++ files, one for encoding and one for decoding. Your submitted files will be compiled using the command depending on their file extensions: %wagner> gcc -o lencode lencode.c %wagner> gcc -o lencode ldecode.c or: %wagner> g++ -o lencode lencode.cpp %wagner> g++ -o lencode ldecode.cpp When a command argument -l is provided, a listing of its variables, output characters and dictionary entries (similar to the listing shown in Slides 100 and 103 of Lecture 1) are displayed to the standard output. For example, using the same test.txt from the above: %wagner> lencode -l < test.txt="" nil="" ^="" ^="" w="" ^="" 256="" ^w="" w="" e="" w="" 257="" we="" e="" d="" e="" 258="" ed="" d="" ^="" d="" 259="" d^="" ^="" w="" 6/9/2019="" comp9319="" 2019t2="" assignment="" 1="" https://www.cse.unsw.edu.au/~wong/cs9319-2019a1.html="" 2/3="" ^w="" e="" 256="" 260="" ^we="" e="" ^="" e="" 261="" e^="" ^="" w="" ^w="" e="" ^we="" e="" 260="" 262="" ^wee="" e="" ^="" e^="" w="" 261="" 263="" e^w="" w="" e="" we="" b="" 257="" 264="" web="" b="" ^="" b="" 265="" b^="" ^="" w="" ^w="" e="" ^we="" t="" 260="" 266="" ^wet="" t="" eof="" t="" %wagner=""> %wagner> cat test.txt | lencode > test.lzw %wagner> ldecode -l < test.lzw="" nil="" ^="" ^="" ^="" w="" w="" 256="" ^w="" w="" e="" e="" 257="" we="" e="" d="" d="" 258="" ed="" d="" 256="" ^w="" 259="" d^="" 256="" e="" e="" 260="" ^we="" e="" 260="" ^we="" 261="" e^="" 260="" 261="" e^="" 262="" ^wee="" 261="" 257="" we="" 263="" e^w="" 257="" b="" b="" 264="" web="" b="" 260="" ^we="" 265="" b^="" 260="" t="" t="" 266="" ^wet="" %wagner=""> Note that all the output fields are delimited by a space. Similarly, if there are three consecutive spaces in this output, the second space is a symbol and the other twos are delimiters. Your solution will be compiled and run on a typical CSE Linux machine e.g. wagner. Your solution should not write out any external files. Any solution that fails to compile on a CSE Linux machine with the above commands or writes out external files will receive zero points for the entire assignment. Performance Any single test (e.g., lencode < test0001.txt ) that takes more than 5 seconds will be terminated, and your solution will receive zero points for that test. so, your dictionary lookup cannot be too slow (e.g., linear search may not make it). documentation and code readability your source code will be inspected. marks may be deducted if your code is very poor on readability and ease of understanding. notes 1. your submission will not be tested with huge files, but it is expected to work properly and correctly for files up to a hundred kilobytes. 2. marks will be deducted for output of any extra text, other than the required, correct answer. this extra information includes (but not limited to) debugging messages, line numbers and so on. marking 6/9/2019 comp9319 2019t2 assignment 1 https://www.cse.unsw.edu.au/~wong/cs9319-2019a1.html 3/3 this assignment is worth 15 points, all based on auto marking. submission deadline: friday 28th june 12:00pm (noon). late submissions will have marks deducted from the maximum achievable mark at the rate of roughly 1% of the total mark per hour that they are late (i.e., 24% per day), and no submissions will be accepted after 3 days late. use the give command below to submit the assignment or submit via webcms3: give cs9319 a1 lencode.c ldecode.c or: give cs9319 a1 lencode.cpp ldecode.cpp plagiarism the work you submit must be your own work. submission of work partially or completely derived from any other person or jointly written with any other person is not permitted. the penalties for such an offence may include negative marks, automatic failure of the course and possibly other academic discipline. assignment submissions will be examined both automatically and manually for such submissions. relevant scholarship authorities will be informed if students holding scholarships are involved in an incident of plagiarism or other misconduct. do not provide or show your assignment work to any other person - apart from the teaching staff of this subject. if you knowingly provide or show your assignment work to another person for any reason, and work derived from it is submitted you may be penalized, even if the work was submitted without your knowledge or consent. this may apply even if your work is submitted by a third party unknown to you. test0001.txt="" )="" that="" takes="" more="" than="" 5="" seconds="" will="" be="" terminated,="" and="" your="" solution="" will="" receive="" zero="" points="" for="" that="" test.="" so,="" your="" dictionary="" lookup="" cannot="" be="" too="" slow="" (e.g.,="" linear="" search="" may="" not="" make="" it).="" documentation="" and="" code="" readability="" your="" source="" code="" will="" be="" inspected.="" marks="" may="" be="" deducted="" if="" your="" code="" is="" very="" poor="" on="" readability="" and="" ease="" of="" understanding.="" notes="" 1.="" your="" submission="" will="" not="" be="" tested="" with="" huge="" files,="" but="" it="" is="" expected="" to="" work="" properly="" and="" correctly="" for="" files="" up="" to="" a="" hundred="" kilobytes.="" 2.="" marks="" will="" be="" deducted="" for="" output="" of="" any="" extra="" text,="" other="" than="" the="" required,="" correct="" answer.="" this="" extra="" information="" includes="" (but="" not="" limited="" to)="" debugging="" messages,="" line="" numbers="" and="" so="" on.="" marking="" 6/9/2019="" comp9319="" 2019t2="" assignment="" 1="" https://www.cse.unsw.edu.au/~wong/cs9319-2019a1.html="" 3/3="" this="" assignment="" is="" worth="" 15="" points,="" all="" based="" on="" auto="" marking.="" submission="" deadline:="" friday="" 28th="" june="" 12:00pm="" (noon).="" late="" submissions="" will="" have="" marks="" deducted="" from="" the="" maximum="" achievable="" mark="" at="" the="" rate="" of="" roughly="" 1%="" of="" the="" total="" mark="" per="" hour="" that="" they="" are="" late="" (i.e.,="" 24%="" per="" day),="" and="" no="" submissions="" will="" be="" accepted="" after="" 3="" days="" late.="" use="" the="" give="" command="" below="" to="" submit="" the="" assignment="" or="" submit="" via="" webcms3:="" give="" cs9319="" a1="" lencode.c="" ldecode.c="" or:="" give="" cs9319="" a1="" lencode.cpp="" ldecode.cpp="" plagiarism="" the="" work="" you="" submit="" must="" be="" your="" own="" work.="" submission="" of="" work="" partially="" or="" completely="" derived="" from="" any="" other="" person="" or="" jointly="" written="" with="" any="" other="" person="" is="" not="" permitted.="" the="" penalties="" for="" such="" an="" offence="" may="" include="" negative="" marks,="" automatic="" failure="" of="" the="" course="" and="" possibly="" other="" academic="" discipline.="" assignment="" submissions="" will="" be="" examined="" both="" automatically="" and="" manually="" for="" such="" submissions.="" relevant="" scholarship="" authorities="" will="" be="" informed="" if="" students="" holding="" scholarships="" are="" involved="" in="" an="" incident="" of="" plagiarism="" or="" other="" misconduct.="" do="" not="" provide="" or="" show="" your="" assignment="" work="" to="" any="" other="" person="" -="" apart="" from="" the="" teaching="" staff="" of="" this="" subject.="" if="" you="" knowingly="" provide="" or="" show="" your="" assignment="" work="" to="" another="" person="" for="" any="" reason,="" and="" work="" derived="" from="" it="" is="" submitted="" you="" may="" be="" penalized,="" even="" if="" the="" work="" was="" submitted="" without="" your="" knowledge="" or="" consent.="" this="" may="" apply="" even="" if="" your="" work="" is="" submitted="" by="" a="" third="" party="" unknown="" to="">
Answered Same DayJun 09, 2021COMP9319

Answer To: 6/9/2019 COMP9319 2019T2 Assignment 1 https://www.cse.unsw.edu.au/~wong/cs9319-2019a1.html 1/3...

Ankita answered on Jun 18 2021
131 Votes
decode-celejuk4-1n4glsqh.c
#include
#include
#include
#include
typedef struct DLListNode {
    int value;
    char chars[10];
} DLNodeList;
DLNodeList *newDLNodeList(char c[], int it)
{
    DLNodeList *new;
    new = malloc(sizeo
f(DLNodeList));
    assert(new != NULL);
    new->value = it;
    strcpy(new->chars, c);
    return new;
}
int get_len(char string[]){
    for(int m=0;m<100;m++){
    if (string[m] == '\0'){
            return m;
        }
        else{
        printf("ERROR");}
    }
    return 100;
}
int compare(DLNodeList *nodes[], char chars[]){
    for(int m=0;m<1000;m++)
    {
        if (strcmp(chars, nodes[m]->chars)== 0){
            return 1;
        }
    }
    return 0;
}
void print_nodes(DLNodeList *nodes[]){
    int m = 0;
    while (nodes[m]->value != -1){
        printf("Index: %d. Value: %s\n",nodes[m]->value, nodes[m]->chars);
        m++;
    }
}
int search_str(DLNodeList *nodes[], char string[]){
    int m =0;
    while(m<1000){
        if (strcmp(nodes[m]->chars, string) == 0){
            return nodes[m]->value;
        }
        m++;
    }
    return 0;
}
char *search_value(DLNodeList *nodes[], int val){
    int m =0;
    while(m<1000){
        if (nodes[m]->value == val){
            return nodes[m]->chars;
        }
        m++;
    }
    return "no";
}
//Main function of LZW
int main(int argc, char *argv[]) {
char var[100];
int k = 0;
while(k <100){
    var[k] = '0';
    k++;
}
DLNodeList *nodes[1000];
int m = 0;
while(m<1000){
    nodes[m] = newDLNodeList("\0", -1);
    m++;
}
char str[1000];
fgets(str, 1000, stdin);
int length = strlen(str);
DLNodeList *string[1000];
m = 0;
while(m<1000){
string[m] = newDLNodeList("\0", -1);
m++;
}
m = 0;
char delim[] = " ";
char *ptr = strtok(str, delim);
int modi = 0;
while(ptr != NULL)
{
if (strlen(ptr) != 1){
strcpy(string[modi]->chars,ptr);
string[modi]->value = 2;
modi++;
}
else{
strcpy(string[modi]->chars,ptr);
string[modi]->value = 1;
modi++;
}
ptr = strtok(NULL, delim);
if (strcmp(ptr,"\n")== 0){
break;
}
}
m = 0;
int index = 256;
int last_mod = 0;
while(m {
if(m == 0){
char W[10] = {"\0"},K[10] = {"\0"}, output[10] = {"\0"}, symbol[10] ={"\0"}, real_W[10] = {"\0"};
strcpy(K,string[m]->chars);
if (argc != 1){printf("NIL %s %s \n",K,K);}
else{printf("%s",K);}
}
else if (string[m]->value == 1 && string[m-1]->value == 1){
char W[10] = {"\0"},K[10] = {"\0"}, output[10] = {"\0"}, symbol[10]...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here