Answer to Question #284550 in C++ for wie

Question #284550

write a program to read an input file to get the number of sentences.

with specifications:

1. count 'A' and 'a' as the occurence of the leter a

2. the two same words should only be recorded once. 

3. ignore non-letter characters ( spaces, punctuation, etc)

4. do not list letters that donot occur at leasr once.

all operations must be done using dynamic array and pointers.


input file 1:

3

My dog did my homework.

My cat is not at home!

Happy New Year!


1
Expert's answer
2022-01-03T14:24:22-0500
#include <iostream>
#include <string>
#include <fstream>


using namespace std;


int main()
{
    ifstream infile("test.txt",ios::in);
    string foo;
    int bar=0;
    while(getline(infile, foo))
    {
        for(int i=0;i<foo.size();i++)
            if(foo[i]=='.' || foo[i]=='?' || foo[i]=='!')
                bar++;
    }
    cout<<"Number of sentences: "<<bar<<"\n";


  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog