[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

programming help

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 9
Thread images: 1

File: 1433403714769.jpg (99KB, 960x720px) Image search: [Google]
1433403714769.jpg
99KB, 960x720px
HElp /g/ I need your help.

I need to do this.

In this assignment we are going to create our own simple lossless data compression algorithm and implement it as a C++ class. In this assignment you will feed your class an input file that contains various words. Your class will read these words, keep track of when it finds a new word that it did not encounter previously and assign a number to that word. Your program will write an output file that contains the compressed data which will be the numbers that are associated with the words that were in the input file.

For example, if my input file had the following text: “test this file test test test”, then the output file might look like this: “1 2 3 1 1 1”. In this case my program would have associated the number “1” with the word “test”, the number “2” with the word “this” and “3” with the word “file”. To make this assignment easier, we will only deal with words and not punctuation or newlines. You can also treat the word “test” and “Test” as the same word or treat them as separate words. It is ok to limit your program to a set number of words that it can store (try to store at least 1000 unique words). At the end of your output file you must print out a list of each word and the associated number that your program used to compress the data so that we could decompress and read the data.

In your program you must use file input and output. You must use object oriented design to write your code in C++. You must use exception handling. (Use try and catch statements.) You must create at least 3 different test input files. You must create a header file (.h) and separate your class source code file (.cpp) from your main source code file. (You should turn in at least 3 source code files, one header file and 2 source code files.) Remember that your header file contains just definitions and not source code. You must also turn in all 3 (or more) of your test input files (.txt).
>>
So I have the back bone done, I just need to setup the driver and how to set the item type to string.
>>
Kys
>>
>>58923464
Isn't this like semester 1 stuff OP?
Surely you can google anything you need help with. Delete this thread and consider killing yourself.
>>
itemtype.cpp

// The following definitions go into file ItemType.cpp.
#include <fstream>
#include <iostream>
#include "ItemType.h"

ItemType::ItemType()
{
value = 0;
}

RelationType ItemType::ComparedTo(ItemType otherItem) const
{
if (value < otherItem.value)
return LESS;
else if (value > otherItem.value)
return GREATER;
else return EQUAL;
}

void ItemType::Initialize(int number)
{
value = number;
}

void ItemType::Print(std::ostream& out) const
// pre: out has been opened.
// post: value has been sent to the stream out.
{
out << value;
}
>>
>>58923464
Hashtable
>>
Item type.h
// The following declarations and definitions go into file 
// ItemType.h.

#include <fstream>
const int MAX_ITEMS = 1000;
enum RelationType { LESS, GREATER, EQUAL };

class ItemType
{
public:
ItemType();
RelationType ComparedTo(ItemType) const;
void Print(std::ostream&) const;
void Initialize(int number);
private:
int value;
};
>>
#pragma once
#include "ItemType.h"
// File ItemType.h must be provided by the user of this class.
// ItemType.h must contain the following definitions:
// MAX_ITEMS: the maximum number of items on the list
// ItemType: the definition of the objects on the list
// RelationType: {LESS, GREATER, EQUAL}
// Member function ComparedTo(ItemType item) which returns
// LESS, if self "comes before" item
// GREATER, if self "comes after" item
// EQUAL, if self and item are the same

class UnsortedType
{
public:
UnsortedType();
// Constructor

void MakeEmpty();
// Function: Returns the list to the empty state.
// Post: List is empty.

bool IsFull() const;
// Function: Determines whether list is full.
// Pre: List has been initialized.
// Post: Function value = (list is full)

int GetLength() const;
// Function: Determines the number of elements in list.
// Pre: List has been initialized.
// Post: Function value = number of elements in list

ItemType GetItem(ItemType, bool&);


void PutItem(ItemType item);


void DeleteItem(ItemType item);
// Function: Deletes the element whose key matches item's key.
// Pre: List has been initialized.
// Key member of item is initialized.
// One and only one element in list has a key matching item's key.
// Post: No element in list has a key matching item's key.

void ResetList();
// Function: Initializes current position for an iteration through the list.
// Pre: List has been initialized.
// Post: Current position is prior to list.

ItemType GetNextItem();

private:
int length;
ItemType info[MAX_ITEMS];
int currentPos;
};
>>
// Implementation file for Unsorted.h

#include "unsorted.h"

UnsortedType::UnsortedType()
{
length = 0;
}
bool UnsortedType::IsFull() const
{
return (length == MAX_ITEMS);
}
int UnsortedType::GetLength() const
{
return length;
}

ItemType UnsortedType::GetItem(ItemType item, bool& found)
// Pre: Key member(s) of item is initialized.
// Post: If found, item's key matches an element's key in the
// list and a copy of that element has been returned;
// otherwise, item is returned.
{
bool moreToSearch;
int location = 0;
found = false;

moreToSearch = (location < length);

while (moreToSearch && !found)
{
switch (item.ComparedTo(info[location]))
{
case LESS :
case GREATER : location++;
moreToSearch = (location < length);
break;
case EQUAL : found = true;
item = info[location];
break;
}
}
return item;
}
void UnsortedType::MakeEmpty()
// Post: list is empty.
{
length = 0;
}
void UnsortedType::PutItem(ItemType item)
// Post: item is in the list.
{
info[length] = item;
length++;
}
void UnsortedType::DeleteItem(ItemType item)
// Pre: item's key has been initialized.
// An element in the list has a key that matches item's.
// Post: No element in the list has a key that matches item's.
{
int location = 0;

while (item.ComparedTo(info[location]) != EQUAL)
location++;

info[location] = info[length - 1];
length--;
}
void UnsortedType::ResetList()
// Post: currentPos has been initialized.
{
currentPos = -1;
}

ItemType UnsortedType::GetNextItem()
// Pre: ResetList was called to initialized iteration.
// No transformer has been executed since last call.
// currentPos is defined.
// Post: item is current item.
// Current position has been updated.
{
currentPos++;
return info[currentPos];
}

Thread posts: 9
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.