2 Replies - 1419 Views - Last Post: 08 May 2010 - 03:02 AM Rate Topic: -----

#1 Vietnam_mylove  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 6
  • Joined: 07-May 10

Write code (object-oriented programming) - help me

Posted 07 May 2010 - 06:11 PM

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 .....

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;
}



Admin Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: Write code (object-oriented programming) - help me

#2 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 379
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Write code (object-oriented programming) - help me

Posted 07 May 2010 - 09:17 PM

The only way to complete 'd' that I know of would be to create a map or associative array that holds all the words in the file then increment words if they are found more than once.

For 'e', again the easiest way (Lowest amount of thinking) would be to read the file into a vector of strings. Then use the sort() function from the algorithm header.

A little reference:
Vectors
Maps
Algorithm Header - Sort function
Was This Post Helpful? 0
  • +
  • -

#3 Vietnam_mylove  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 6
  • Joined: 07-May 10

Re: Write code (object-oriented programming) - help me

Posted 08 May 2010 - 03:02 AM

I don't understand. Could you explain more clearly ?
Was This Post Helpful? -1
  • +
  • -

Page 1 of 1