Bonus Practice Sheet Winter 2018 [17-Mar-2018 to 7-Apr-2018]
Program ID- 1531
Given a word ‘w’and a set of tweets in a file named as tweets.txt, write a C++ program to count the number of words in the file. Assume that the program need not bother about case of the words as the input takes care of the same.
Input Format
Word to be searched
Tweets in file
Output Format
Count of the words
Input Format
Word to be searched
Tweets in file
Output Format
Count of the words
Code: C++
#include<fstream>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
fstream f;
char s[100];
cin>>s;
char d;
f.open("tweets.txt",ios::in);
int c=0;
int count=0;
while(!f.eof())
{
f.get(d);
if(d==s[c])
{
c++;
}
else
{
c=0;
}
if(c==strlen(s))
{
count++;
c=0;
}
}
cout<<count;
}
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
fstream f;
char s[100];
cin>>s;
char d;
f.open("tweets.txt",ios::in);
int c=0;
int count=0;
while(!f.eof())
{
f.get(d);
if(d==s[c])
{
c++;
}
else
{
c=0;
}
if(c==strlen(s))
{
count++;
c=0;
}
}
cout<<count;
}
NOTE: The Above Codes are for reference only. It doesn't mean everyone to directly copy/paste those codes.
ReplyDeletenice article for beginners.thank you.
JAVA tutorial
java tutorial