473,288 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

need help pleaseeeeeeeeeeeeeeeeee

Introduction

This assignment requires you to develop solutions to the given problem
using several different approaches (which actually involves using three
different STL containers). You will implement all three techniques as
programs. In these programs, as well as solving the problem, you will
also measure how long the program takes to run. The programs are worth
80% of the total mark. The final 20% of the marks are awarded for a
brief report explaining why the different algorithms performed in the
way they did.
The Problem - text analysis/word counting

Computer analysis of texts, which involves making statistical
measurements on the text, is used in a variety of situations, including
authorship attribution (checking a piece of text by an unknown author
against texts by others to try and work out who wrote it) and
plagiarism detection (shudder at the thought). One of the simplest
measures is to take a piece of text and count how often each word used
in the text occurs. Obviously, in a large piece of text many words are
going to be used. We are going to look at several ways of do this
counting. We are not going to worry about analysing the data - that is
the problem for a different program (or different part of the program)
- we are just looking at the word counting phase. We are going to run
various programs (six in all) which all using STL containers (some of
the programs use the same containers but in different ways, so there
are only three different containers used). We are going to time how
long each algorithm takes (don't worry, the first appendix shows you
how to do this). To enable meaningful measurements to be made, a fairly
large piece of text is required. A file called Frank.txt has been put
on BrightSpark for you to use. It contains the first three chapters of
'Frankenstein' by Mary Shelley. The text has been ready prepared
for analysis - all punctuation and capitalisation has been removed.

Each program must read the file, and count how often each of the words
occurs. The program then prints out a list of the words (the order of
the words depends on which part you are doing) and how many times they
are present in the text. There are a lot of ways that this could be
done. Several approaches/algorithms are given below. You should measure
the time taken to complete each algorithm. Outputting the text to the
screen will be a slower process than doing the analysis, so you should
take a time measurement at three points - before starting the
analysis, after the analysis but before the output and after the
output. You can then say how long the analysis took, how long the
printing took and how long the overall analysis took. Remember, do not
take a single value, but run several (say, ten times) and take the
average.


Note

Most of the programs (all except 3) will need you to use a class to
hold a word/word count pair. The following header file defines a class
which (with the addition of the matching body) is sufficient for parts
and 2.:


class WordCount
{
private:
string word;
int count;
public:
WordCount();
WordCount(const string& word);
WordCount(const WordCount& wc);

WordCount operator++(int);
bool operator==(const WordCount& rhs);

friend
ostream& operator<<(ostream& os, const WordCount& rhs);
};

As you can see, there are two attributes, a word and the number of
times that word occurs in the text.

Here are some details of the operators:
WordCount();
This is the default constructor. You will not create objects directly
with it, but it is required for creating some of the initial STL
containers. It should set the count to zero and the word to an empty
string.
WordCount(const string& word);
This is the constructor that you will use to create objects in your
program). You supply the word as a parameter and set the count to 1
(since it is used when you find a new word for the first time).
WordCount(const WordCount& wc);
This is a standard copy constructor which will be needed at some
stages. You do not explicitly call it.

Here are some details of the operators:
operator++
This is the increment operator (actually a post-increment) which
increments the count field (only). Post increment operators are
slightly strange to write, the stages are:
a) take a copy of the object
b) increment the count attribute
c) return the copy of the object
operator==
This only compares the word fields, it returns true if they are the
same and false if they are different. In parts 2 and 3 you will also
need a less than comparison. It is very similar to this operator.
operator<<
The overloaded output operator simplifies the output stage of the
program and should give the word followed by its count - put the
count in brackets to make it easier to follow.

Depending on how you write the code you may need some additional
operators or methods. Hopefully you won't, but if you do then you may
add them.


Part 1

The programs

In this assignment, the words are output in any order, i.e. no sorting
is done. There are three programs to write (although the second is
only a fairly minor modification of the first):

The first program (1)
Use the vector container from STL. As you read in each word, check to
see if it is already stored in the vector. If it is, increment that
word's count. If it isn't, add the word to the end of the vector.
It is easiest if you create a temporary word count object as soon as
you read each word from the file and use that for the comparisons etc.

The second program (2)
This should be a very similar program to the first program, but should
use a list container instead of a vector.

The third program (3)
This should use a hash map. The approach of the third program is
similar to the first two, but you will not use the WordCount class
because the hash map expects pairs of values. You will not have met
hash maps before, so there are notes on using the hash map in appendix
2. The hash maps work on the concept of pairs of values, one being a
key which is used to locate the data and the other being the data
value. If we let the word be the key and the count of that word be the
data then the hash map will work for solving this problem. Because hash
maps automatically work with pairs you will not use the WordCount class
in this section.

When you have read a word, you should use the find method to see if it
is already in the hash map. The find method returns an iterator. If the
iterator is set to the end of the map (i.e. is equal to wordlist.end())
then the word is not in the map. You can use the insert method to
insert this as a new word. Appendix 2 shows gow to use the template
pair to do this.

If the iterator is not set to the end then the word has been found. The
iterator allows you to access two fields, first (the word) and second
(the count). You can increment the count directly.

To output the result you can declare an iterator and step through the
hash map. You can use the first and second fields to mimic the output
of the other programs.

Hash maps are very efficient at insertion and retrieval, and both
operators work in almost constant time.

Oct 19 '06 #1
6 2095
naknak wrote:
Introduction

This assignment requires you [..]
So, have you done what it requires *you* to do? If not, why? If
only partially, can we see what's done so far? Please read the FAQ,
especially section 5. http://www.parashift.com/c++-faq-lite/

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 19 '06 #2
naknak wrote:
Introduction

This assignment requires you to develop solutions to the given problem
using several different approaches (which actually involves using three
different STL containers).
<snip>

so where are you stuck then?

--
Nick Keighley

Oct 19 '06 #3
this the header
this is the wordcount.h
#ifndef wordcount_h
#define wordcount_h

// read_words.h
#include <iostream>
#include <vector>
#include <string>
using std::string;

using namespace std;

std::istream& read_words(std::istream&, std::vector<std::string>&);
class WordCount
{
private:
string word;
int count;
public :
WordCount();
WordCount(const string& word);
WordCount(const WordCount& wc);
WordCount operator++(int);
bool operator ==(const WordCount& rhs);

friend ostream& operator<<(ostream& os ,const WordCount& rhs);

};

#endif
and this is the wordcount.cpp
#include "wordcount.h"

wordcount::WordCount()
{

}
wordcount::WordCount(const string& word)
{
}
wordcount::WordCount(const WordCount& wc)
{
}
wordcount::WordCount operator++(int)
{
}
bool operator ==(const WordCount& rhs)
who can i build the bool bool operator ==(const WordCount& rhs)
and can u check if is it right what i wrote

Oct 19 '06 #4
naknak wrote:
this the header
this is the wordcount.h
#ifndef wordcount_h
#define wordcount_h

// read_words.h
#include <iostream>
#include <vector>
#include <string>

using std::string;
using namespace std;
why do you have both of these?

std::istream& read_words(std::istream&, std::vector<std::string>&);
class WordCount
{
private:
string word;
int count;
public :
WordCount();
WordCount(const string& word);
WordCount(const WordCount& wc);
WordCount operator++(int);
bool operator ==(const WordCount& rhs);

friend ostream& operator<<(ostream& os ,const WordCount& rhs);

};

#endif
and this is the wordcount.cpp
#include "wordcount.h"

wordcount::WordCount()
{

}
wordcount::WordCount(const string& word)
{
}
wordcount::WordCount(const WordCount& wc)
{
}
wordcount::WordCount operator++(int)
{
}
bool operator ==(const WordCount& rhs)
who can i build the bool bool operator ==(const WordCount& rhs)
and can u check if is it right what i wrote
please try to use standard english. I'm guessing you meant

"How can I write the function
bool operator ==(const WordCount& rhs)
and can you check if it what I have written is correct?"

My first problem is that I don't think you have written anything...
So why don't you start with the above equality operator. It returns
true
if the "word" members match in the two WordCount objects
(that is the current WordCount ("this") and the parameter passed
("rhs")).
So if you were going to compare two strings for equaility how would
you go about it?
--
Nick Keighley

Oct 19 '06 #5
"naknak" writes:
this the header
this is the wordcount.h
#ifndef wordcount_h
#define wordcount_h

// read_words.h
#include <iostream>
#include <vector>
#include <string>
using std::string;

using namespace std;
Don't put using declarations in *header* files!
>
std::istream& read_words(std::istream&, std::vector<std::string>&);
class WordCount
{
private:
string word;
int count;
public :
WordCount();
WordCount(const string& word);
WordCount(const WordCount& wc);
WordCount operator++(int);
bool operator ==(const WordCount& rhs);

friend ostream& operator<<(ostream& os ,const WordCount& rhs);

};

#endif
and this is the wordcount.cpp
#include "wordcount.h"

wordcount::WordCount()
{

}
wordcount::WordCount(const string& word)
{
}
wordcount::WordCount(const WordCount& wc)
{
}
wordcount::WordCount operator++(int)
{
}
bool operator ==(const WordCount& rhs)
who can i build the bool bool operator ==(const WordCount& rhs)
---
>>operator==
This only compares the word fields, it returns true if they are the
same and false if they are different.
word is a string and == is overloaded for stirng.
-----
and can u check if is it right what i wrote
Try to compile it. The compiler will tell you if it is probably right, at
least syntax wise. Compile often. You can compile and not run and still
get useful information. Is your source as you see it indented? What I see
is not, don't defer indentation, it will come back to bite you.

Just as a point of interest, how many C++ programs have you already written?
Is this for a trade school or for a University? It strikes me as terribly
time consuming for a University where you have several other subjects as
well.
Oct 19 '06 #6
On 19 Oct 2006 07:19:37 -0700 in comp.lang.c++, "naknak"
<na*****@walla.co.ilwrote,
>who can i build the bool bool operator ==(const WordCount& rhs)
What have you tried? What happened when you tried it?

This issue is covered in Marshall Cline's C++ FAQ. See the topic
"# [5.2] How do I get other people to do my homework problem for
me?" It is always good to check the FAQ before posting. You can
get the FAQ at:
http://www.parashift.com/c++-faq-lite/

>and can u check if is it right what i wrote

#include <assert.h>
int main()
{
WordCount w1("cheese");
WordCount w2("bread");
WordCount w3("cheese");
assert (!(w1 == w2));
assert(w1 == w3);
}

Oct 19 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sofia | last post by:
My name is Sofia and I have for many years been running a personals site, together with my partner, on a non-profit basis. The site is currently not running due to us emigrating, but during its...
6
by: Robert Maas, see http://tinyurl.com/uh3t | last post by:
System login message says PHP is available, so I tried this: http://www.rawbw.com/~rem/HelloPlus/h.php It doesn't work at all. Browser just shows the source. What am I doing wrong?
0
by: Gregory Nans | last post by:
hello, i need some help to 'tree-ify' a string... for example i have strings such as : s = """A(here 's , B(A ) silly test) C(to show D(what kind) of stuff i need))""" and i need to...
7
by: Mike Kamermans | last post by:
I hope someone can help me, because what I'm going through at the moment trying to edit XML documents is enough to make me want to never edit XML again. I'm looking for an XML editor that has a...
8
by: JustSomeGuy | last post by:
I need to write an new class derived from the list class. This class stores data in the list to the disk if an object that is added to the list is over 1K in size. What methods of the std stl...
3
by: Bob.Henkel | last post by:
I write this to tell you why we won't use postgresql even though we wish we could at a large company. Don't get me wrong I love postgresql in many ways and for many reasons , but fact is fact. If...
2
by: Michael R. Pierotti | last post by:
Dim reg As New Regex("^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$") Dim m As Match = reg.Match(txtIPAddress.Text) If m.Success Then 'No need to do anything here Else MessageBox.Show("You need to enter a...
5
by: HotRod | last post by:
I am new to this so please go easy. We currently have some students doing some work on some web based tracking documents for us. They are currently using VB .net to develop what we requested....
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.