Question

I need to create a program using C++ that can search an external text file (FileWord.txt) and determine the number of people named "Joker" in the file. Here's a picture of the text file below:Joker Dave Paul Rudd Joker Parker Thomas Joke Sam David Mary Marcus Joke Jokers Bean Ben Joker Joker Alice Tim Joker Peter Ro

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//C++ program

#include<iostream>
#include<fstream>
using namespace std;

int main(){
   ifstream in;
   in.open("FileWord.txt");
   int count=0;
   string word;
  
   if(!in){
       cout<<"File not opened\n";
       exit(1);
   }
  
   while(!in.eof()){
       in>>word;
       if(word == "Joker"){
           count++;
       }
   }
  
   cout<<"Number of peoples named Joker is "<<count<<endl;
   in.close();
}

//sample output

FileWord - WordPad - o x File Home View Courier New E - 11 - AA abe X, x 2 A - 3 Paste B I U Insert à Find ac Replace D Selec

Add a comment
Know the answer?
Add Answer to:
I need to create a program using C++ that can search an external text file (FileWord.txt)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help parsing a large text file in order to create a map using Java....

    I need help parsing a large text file in order to create a map using Java. I have a text file named weather_report.txt which is filled with hundreds of different indexes. For example: one line is "POMONA SUNNY 49 29 46 NE3 30.46F". There are a few hundred more indexes like that line with different values in the text file and they are not delimited by commas but instead by spaces. Therefore, in this list of indexes we only care...

  • Given the text file “Alamo defenders.txt” (attached to this assignment), write a simple Java program to...

    Given the text file “Alamo defenders.txt” (attached to this assignment), write a simple Java program to do the following: - count how many names are in the file - find the longest full name in the file - find the longest single name (first, middle or last) in the file - find whether there were any Alamo defenders named “Jones” - write out, to the screen (console), all of the above information Alamo defenders.txt file: Juan Abamillo James L. Allen...

  • CREATE TWO C++ PROGRAMS : Program 1 Write a program that reads in babynames.txt (provided) and...

    CREATE TWO C++ PROGRAMS : Program 1 Write a program that reads in babynames.txt (provided) and outputs the top 20 names, regardless of gender. The file has the following syntax: RANK# BoyName Boy#OfBirths Boy% GirlName Girl#OfBirths Girl% You should ignore the rank and percentages. Compare the number of births to rerank. Output should go to standard out. Program 2 Write a program that reads a text file containing floating-point numbers. Allow the user to specify the source file name on...

  • C++ Create an application that searches a file of male and female first names. A link...

    C++ Create an application that searches a file of male and female first names. A link to the file is provided on the class webpage. "FirstNames2015.txt" is a list of the most popular baby names in the United States and was provided by the Social Security Administration. Each line in the file contains a boy's name and a girl's name. The file is space-delimited, meaning that the space character is used to separate the boy name from the girl name....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT