hi all..
ive got a C++ assignment to do.

this is what it says:

Write a program in C++ that takes input from a text file specified by the user and outputs the following to the screen:
• Number of single letter words.
• The average word length for the file.
• Number of words whose word length is below the average word length for the file (small words)
• Number of words whose word length is above the average word length for the file (big words)
• The actual single letter words found (do not print duplicates, print 10 to a line)
• The actual small words found (do not print duplicates, one per line)
• The actual big words found (do not print duplicates, one per line)


A word is a series of consecutive alphanumeric characters delimited by space(s), tabs, the newline character or any other "whitespace" character. The words can also be delimited by the usual punctuation characters like “.”, “,”, “?”, “;”, “:”, .. etc.

In calculating the average word length, single letter words do not contribute to the average. If the average calculation produces a number which is not a whole number (i.e. a floating point number), truncate the number to get a whole number.

The only class that you do not have to write for this assignment is the string class from #include <string>. You may use iostream and file handling classes and objects in C++.

You will need to write a vector class. There will be at least 3 vectors (objects) used in your program (one for the single letter words, one for small words and one for big words) but only one vector class. You may write any other classes that you may need and you need to justify each one.

The vector class that you write should be general enough to be used in other contexts and both methods and attributes should permit this. The class would enable the storage of a list of items and provide access to those items.

is there anyone who could help.
thankss very much. this is due on 7th July .

>is there anyone who could help.
thankss very much. this is due on 7th July .

Seems like someone is thinking that we will do it for him.

Could you maybe first post what you have so far?

Edit:: If you had searched the forums before posting your homework assignment, then you would have found a thread (a recent one) which addresses a very similar problem:
http://www.daniweb.com/forums/thread198519.html :)

I found this snippit a while ago that isolates all words using a vector

not my code:

#include <iostream>
#include <vector>
#include <string>
using namespace std;

// Returns true if text contains ch
inline bool TextContains(char *text, char ch) {
	while ( *text ) {
		if ( *text++ == ch )
			return true;
	}

	return false;
}

void Split(char *text, char *delims, vector<string> &words) {
	int beg;
	for (int i = 0; text[i]; ++i) {

		// While the current char is a delimiter, inc i
		while ( text[i] && TextContains(delims, text[i]) )
			++i;

		// Beginning of word
		beg = i;

		// Continue until end of word is reached
		while ( text[i] && !TextContains(delims, text[i]) )
			++i;

		// Add word to vector
		words.push_back( string(&text[beg], &text[i]) );
	}
}

int main() {
	vector<string> words;

	// Split up words
	Split( "Hello, my name is william!", " ,!", words );

	// Display each word on a new line
	for (size_t i = 0; i < words.size(); ++i)
		cout << words[i] << '\n';

	cin.ignore();
}

I found this snippit a while ago that isolates all words using a vector

not my code:

#include <iostream>
#include <vector>
#include <string>
using namespace std;

// Returns true if text contains ch
inline bool TextContains(char *text, char ch) {
	while ( *text ) {
		if ( *text++ == ch )
			return true;
	}

	return false;
}

void Split(char *text, char *delims, vector<string> &words) {
	int beg;
	for (int i = 0; text[i]; ++i) {

		// While the current char is a delimiter, inc i
		while ( text[i] && TextContains(delims, text[i]) )
			++i;

		// Beginning of word
		beg = i;

		// Continue until end of word is reached
		while ( text[i] && !TextContains(delims, text[i]) )
			++i;

		// Add word to vector
		words.push_back( string(&text[beg], &text[i]) );
	}
}

int main() {
	vector<string> words;

	// Split up words
	Split( "Hello, my name is william!", " ,!", words );

	// Display each word on a new line
	for (size_t i = 0; i < words.size(); ++i)
		cout << words[i] << '\n';

	cin.ignore();
}

Hey, you don't have to copy-paste the whole code, please just provide a link instead: http://www.daniweb.com/code/snippet1068.html :P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.