Question

Program Description: (C++). Write a word search program that searches an input data file for a...

Program Description: (C++).

Write a word search program that searches an input data file for a word specified by the user. The program should display the number of times the word appears in the input data file. In addition, the program should count and display the number of characters in the input data file that are not vowels. Your program must do this by providing the following functions :

void processFile(ifstream &inFile, string &word, int &wordCount, int &nonVowelCount) ;

void displayResult(string word, int wordCount, int nonVowelCount) ;

Both functions should be called from main(). No non-constant global variables should be used.

Test your program using the file provided “paragraph.dat”.

"You'll generally read and write longer paragraphs in academic papers. However, too many long
paragraphs can provide readers with too much information to manage at one time. Readers
need planned pauses or breaks when reading long complex papers in order to understand your presented
ideas. Remember this writing mantra: "Give your readers a break!" or
"Good paragraphs give one pause"."

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

ANSWER:

#include<iostream>

#include<fstream>

using namespace std;

int getNonVowelCount(string &word)

{

int count=0;

for(int i=0; i<word.size(); i++)

{

switch(word.at(i))

{

case 'a':break;

case 'e':break;

case 'i':break;

case 'o':break;

case 'u':break;

case 'A':break;

case 'E':break;

case 'I':break;

case 'O':break;

case 'U':break;

default: count++;

}

}

return count;

}

string removePunctuations(string word)

{

string newString=word;

while(true)

{

if(newString.size()==0)

break;

switch(newString.at(newString.size()-1))

{

//remove last charactre if its a punctuation mark

case '!':newString=newString.substr(0, newString.size()-1);break;

case '.':newString=newString.substr(0, newString.size()-1);break;

case '?':newString=newString.substr(0, newString.size()-1);break;

case '\'':newString=newString.substr(0, newString.size()-1);break;

case '\"':newString=newString.substr(0, newString.size()-1);break;

default: return newString;//else return the trsing

}

}

return newString;

}

void processFile(ifstream &inFile, string &word, int &wordCount, int &nonVowelCount)

{

string curWord;

int nonVowelC=0;

int wCount=0;

while(!inFile.eof())

{

inFile>>curWord;

string noPunctuation=removePunctuations(curWord);

if(noPunctuation.compare(word)==0)

wCount++;

nonVowelC+=getNonVowelCount(curWord);

}

nonVowelCount=nonVowelC;

wordCount=wCount;

}

void displayResult(string word, int wordCount, int nonVowelCount)

{

cout<<"\n\nWord: "<<word<<endl;

cout<<"Word Count: "<<wordCount<<endl;

cout<<"Non Vowel Count: "<<nonVowelCount<<endl;

}

int main()

{

ifstream input;

input.open("paragraph.dat");

string word="";

int wordCount=0;

int nonVowelCount=0;

cout<<"Enter a word to search in the file."<<endl;

cin>>word;

processFile(input, word, wordCount, nonVowelCount);

displayResult(word, wordCount, nonVowelCount);

cin.get();

return 0;

}

Add a comment
Know the answer?
Add Answer to:
Program Description: (C++). Write a word search program that searches an input data file for a...
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
  • C++ PART B: (STRING) – 40% Program Description: Write a word search program that searches an...

    C++ PART B: (STRING) – 40% Program Description: Write a word search program that searches an input data file for a word specified by the user. The program should display the number of times the word appears  in the input data file.   In addition, the program should read and display each word with the count of vowels in each word.  For example : The 1 Friend 2 Wrote 2 Write functions to process and display the results. No non-constant global variables should...

  • Write a program, called wordcount.c, that reads one word at a time from the standard input....

    Write a program, called wordcount.c, that reads one word at a time from the standard input. It keeps track of the words read and the number of occurrences of each word. When it encounters the end of input, it prints the most frequently occurring word and its count. The following screenshot shows the program in action: adminuser@adminuser-VirtualBox~/Desktop/HW8 $ wordCount This is a sample. Is is most frequent, although punctuation and capitals are treated as part of the word. this is...

  • I need to make a few changes to this C++ program,first of all it should read...

    I need to make a few changes to this C++ program,first of all it should read the file from the computer without asking the user for the name of it.The name of the file is MichaelJordan.dat, second of all it should print ,3 highest frequencies are: 3 words that occure the most.everything else is good. #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int>...

  • Write a simple telephone directory program in C++ that looks up phone numbers in a file...

    Write a simple telephone directory program in C++ that looks up phone numbers in a file containing a list of names and phone numbers. The user should be prompted to enter a first name and last name, and the program then outputs the corresponding number, or indicates that the name isn't in the directory. After each lookup, the program should ask the user whether they want to look up another number, and then either repeat the process or exit the...

  • I need to add something to this C++ program.Additionally I want it to remove 10 words...

    I need to add something to this C++ program.Additionally I want it to remove 10 words from the printing list (Ancient,Europe,Asia,America,North,South,West ,East,Arctica,Greenland) #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int> words);    int main() { // Declaring variables std::map<std::string,int> words;       //defines an input stream for the data file ifstream dataIn;    string infile; cout<<"Please enter a File Name :"; cin>>infile; readFile(infile,words);...

  • Can someone please edit my current code to accept a user input for the text file...

    Can someone please edit my current code to accept a user input for the text file name in lieu of how it currently will read data1.txt. Also if the user enters a data file that isn't ready to be used, cout a statement "cout << "Could not open file " << userInputforData.txt << endl; Another condition that I need to add is if there is a special character anywhere in the word it cannot be an acceptable variable name. could...

  • For this assignment, you are to write a program that does the following:  read temperatures...

    For this assignment, you are to write a program that does the following:  read temperatures from a file name data.txt into an array, and  after reading all the temperatures, output the following to the monitor: the average temperature, the minimum temperature, and the total number of temperatures read. In addition, the program must use the following functions: //precondition: fileName is name of the file to open, inFile is the input file //postcondition: inFile is opened. If inFile cannot...

  • //This program is your final practice exam. //Please fill in the functions at the bottom of...

    //This program is your final practice exam. //Please fill in the functions at the bottom of the file. (sum and removeItem) //DO NOT CHANGE ANYTHING ELSE. //main has all the code needed to test your functions. Once your functions are written, please build and make sure it works fine //Note that in this case, the list is not sorted and does not need to be. Your goal is to insert the number in the given position. #include <iostream> #include <fstream>...

  • //This program is your final exam. //Please fill in the functions at the bottom of the...

    //This program is your final exam. //Please fill in the functions at the bottom of the file. (evenCount and insertItem) //DO NOT CHANGE ANYTHING ELSE. //main has all the code needed to test your functions. Once your functions are written, please build and make sure it works fine //Note that in this case, the list is not sorted and does not need to be. Your goal is to insert the number in the given position. #include <iostream> #include <fstream> using...

  • //This program is your final exam. //Please fill in the functions at the bottom of the...

    //This program is your final exam. //Please fill in the functions at the bottom of the file. (evenCount and insertItem) //DO NOT CHANGE ANYTHING ELSE. //main has all the code needed to test your functions. Once your functions are written, please build and make sure it works fine //Note that in this case, the list is not sorted and does not need to be. Your goal is to insert the number in the given position. #include <iostream> #include <fstream> using...

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