Write code about object-oriented programming

write programs using object-oriented programming (code)

Application of vector and string classes in STL library for building statistical program text:
a, Open/Read a passage from a text file
b, Count the number of sentences in paragraphs
c, Count the words in each sentence
d, Find words in the text that appears that most
e, Sort ascending words (dictionary order) in the text
f, Output results to text file

P/s: I come from Vietnam. Everyone help me .....
Last edited on
No one is going to do the work for you, You're going to have to do it your self, we'd all be glad to help you along the way though. Do you have any code to post for us? So we have an idea as to where you are at?
Seraphisman++;

We'll help you if and only if you show us some code first. But because I feel very generous today I'll help you get started ;D

- Open/Read a passage from a text file
Use strings to store the input.

- Count the number of sentences in paragraphs
What characters is a sentence terminated with in your file? '.', '?', '!' could be some I assume... And how do you know when a new paragraph starts? Is newline character ('\n') the answer? If so, count the number of '.', '?', '!' between each pair of consecutive '\n's.

- Count the words in each sentence
I'd count the number of space characters in each sentence.

- Find words in the text that appears that most
Use a map<string,int>.

- Sort ascending words (dictionary order) in the text
Use a vector of strings to store the words of the text and then sort that vector.

- Output results to text file
Doesn't seem very difficult to me.

If you're not familiar with file i/o this will help -> http://cplusplus.com/doc/tutorial/files/
Info on string -> http://cplusplus.com/reference/string/string/
Info on vector -> http://cplusplus.com/reference/stl/vector/
Info on map -> http://cplusplus.com/reference/stl/map/

P/s: I come from Vietnam. Everyone help me .....
Nice try :D
Last edited on
I am a first year girl student, I just learn C + +. I have to send fold this project for my teacher. If I do not send on time, I will be point zero. Please help me this time.

Help me write a C + + program completed

Thanks a lot.


I just do part the a, b, c. Now the d and e do not know. Please help me

Code:

a,
void readdata(istream& input,string& s)
{
getline(input,s);
}

b,
int count_sentences(string s, int& number_sentences,int& d_sentences)
{
int l=s.size();
for(int i =0;i < l;i++)
{
if(s[i]=='?'||s[i]=='.'||s[i]=='!')
number_sentences ++;
if((s[i]=='?'||s[i]=='!'||s[i]=='.')&&(s[i+1]=='?'||s[i+1]=='?'||s[i+1]=='!'||s[i+1]=='.'))
d_sentences ++;
}
return number_sentences-d_sentences;
}

c,
int count_words(string& s,int& number_words,int& d_words)
{

for(int i=0;i<s.size();i++)
{
if((s[i]>='a'&& s[i]<='z')||(s[i]>='A'&& s[i]<='Z'))
number_words++;
if(((s[i]>='a'&& s[i]<='z')||(s[i]>='A'&& s[i]<='Z'))&&((s[i+1]>='a'&& s[i+1]<='z')||(s[i+1]>='A'&& s[i+1]<='Z')))
d_words ++;
}
return number_words-d_words;
}
Last edited on
I am a first year girl student

Nice try here too! :D
I am a first year girl student, I just learn C + +. I have to send fold this project for my teacher. If I do not send on time, I will be point zero. Please help me this time.

Help me write a C + + program completed

Thanks a lot.

I just do part the a, b, c. Now the d and e do not know. Please help me

Code:

a,
void readdata(istream& input,string& s)
{
getline(input,s);
}

b,
int count_sentences(string s, int& number_sentences,int& d_sentences)
{
int l=s.size();
for(int i =0;i < l;i++)
{
if(s[i]=='?'||s[i]=='.'||s[i]=='!')
number_sentences ++;
if((s[i]=='?'||s[i]=='!'||s[i]=='.')&&(s[i+1]=='?'||s[i+1]=='?'||s[i+1]=='!'||s[i+1]=='.'))
d_sentences ++;
}
return number_sentences-d_sentences;
}

c,
int count_words(string& s,int& number_words,int& d_words)
{

for(int i=0;i<s.size();i++)
{
if((s[i]>='a'&& s[i]<='z')||(s[i]>='A'&& s[i]<='Z'))
number_words++;
if(((s[i]>='a'&& s[i]<='z')||(s[i]>='A'&& s[i]<='Z'))&&((s[i+1]>='a'&& s[i+1]<='z')||(s[i+1]>='A'&& s[i+1]<='Z')))
d_words ++;
}
return number_words-d_words;
}
FIRAJA! YOU TAKE 9999 DAMAGE!
I prefer blizzaja but I suppose yours will also do the work...
I am a first year girl student

Nice try here too! :D

I was about so say that, but I found it very funny when someone also notice it.

hahahaha.. lmao
Ok, seriously now, it would be good if you also posted the contents of your file (if it's not big) so that we know what we're actually dealing with. If it's big, just post a small part indicating the format of the file.

And use code tags for your code, like this:
[code] /*your code here*/ [/code ] (<-without this extra space here, before ']')

and output tags for the contents of the file, like this:
[output] contents of file here [/output ] (<-without this extra space here, before ']')
Last edited on
Topic archived. No new replies allowed.