my code stock.com

main file

Snippet options

Download: Download snippet as final_project.cpp.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

//
//  FinalProject.cpp
//  
//
//  STUDENT NAME: Shaswat Koirala
//

#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include "HashTable.cpp"
#include "Utils.cpp"

using namespace std;
int main(int argc,char *argv[]) {
  string filename;
    const string END_OF_BOOK_DATA = "***************";
    string title, body, line;
    filename=argv[1];
    
    ifstream infile(filename.c_str());
    if(infile.fail()){
        cout << "ERROR: could not open input file " << filename << endl;
        return 1;
    }

        Utils *here2;
	NewHash *myhash;
    HashTable<40> myHashTable;
    while(getline(infile, title)){
        title = title.substr(1); 
        body = "";
        while(getline(infile, line)){	     
            if(line == END_OF_BOOK_DATA)
                break;
            body += line + "\n";
        }
	ZippedBookNode *here=new ZippedBookNode;
	 string encodedString;
	 here2->computeFrequency(body, body.length());
	 here2->HuffmanCodes(body.length());
         for (auto i: body) encodedString+=codes[i];
         here->title=title;
	 here->c_excerpt=encodedString; 
	 here->huff_root=minHeap.top();
	 here->next=NULL;
	  myHashTable.insertNode(here);
	   }
     	
       infile.close();
       int user=0;						    
     while(user!=3){
    cout<<"=====Main Menu====="<<endl;
    cout<<"1. Print Titles"<<endl;
    cout<<"2. Search Excerpt"<<endl;
    cout<<"3. Quit"<< endl;
    cin>> user;
    if(user==1)   myHashTable.printTitles();
    if(user==2){
       cin.ignore();
       string t="";
       cout<<"Enter Title :"<<endl;
       getline(cin,t);
         
      string encode=myhash->search(myHashTable.lookupTable[myHashTable.hashSum(t)],t);
    
       
       HuffNode* e=myhash->search2(myHashTable.lookupTable[myHashTable.hashSum(t)],t);
        
       cout<<"*********************************************************"<<endl;
       cout << "\nEncoded Huffman data:\n"; 
        cout<<encode<<endl;
       cout<<here2->decode_file(e,encode);
    }
    if(user==3) cout<<"Goodbye!"<<endl;
       }
       return 0;
    
}


































Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.