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!
#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;
}
Comments
Leave a comment