[Help]Prompting user for input and output files

Hello im having a hard time trying to build a program that prompts user for input and output files. The program should opens the file and read all the words in the file and keep track of how many times that word appears. It writes (appends) the word and the number to the output file. It continues this until the user types "exit".
So Far:


#include<iostream>
#include<fstream>
#include<string>

using namespace std;


//This function opens the output file to append the word and count on a new line
bool WriteWordToFile(string outputFile, string searchWord, int wordCount)
{
return false;
}


//This function opens the inputfile and searches for the word. It returns
//the number of times the word appears. It assumes that it is case sensitive
//and that there is no punctuation. Thus, the simple insertion operator can
//be used.
int SearchFile(string inputFile, string searchWord)
{
return 0;
}


//The main function of the program. This gets the file names and the word to
//search and then calls the functions.
int main()
{

string inputFile;
string outputFile;
string searchWord;
int wordCount;

//get input file name
cout << "Enter input file name: ";
getline (cin, inputFile);


//get output file name
cout << "Enter output file name: ";
getline(cin, outputFile);


//get word to search
cout << "Enter word to search: ";
getline(cin, searchWord);

do
{
//search for word and get count
wordCount = SearchFile(inputFile, searchWord);

//record the word and count
WriteWordToFile(outputFile, searchWord, wordCount);

//get word to search(trouble with this)




}
while(searchWord != "exit");


return 0;
}
Last edited on
Where is the implementation ?
what do you mean?
This is in Code format

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

#include<iostream>
#include<fstream>
#include<string>

using namespace std;


//This function opens the output file to append the word and count on a new line
bool WriteWordToFile(string outputFile, string searchWord, int wordCount)
{
return false;
}


//This function opens the inputfile and searches for the word. It returns
//the number of times the word appears. It assumes that it is case sensitive
//and that there is no punctuation. Thus, the simple insertion operator can
//be used.
int SearchFile(string inputFile, string searchWord)
{
return 0;
}


//The main function of the program. This gets the file names and the word to
//search and then calls the functions.
int main()
{

string inputFile;
string outputFile;
string searchWord;
int wordCount;

//get input file name
cout << "Enter input file name: ";
getline (cin, inputFile);


//get output file name
cout << "Enter output file name: ";
getline(cin, outputFile);


//get word to search
cout << "Enter word to search: ";
getline(cin, searchWord);

do
{
//search for word and get count
wordCount = SearchFile(inputFile, searchWord);

//record the word and count
WriteWordToFile(outputFile, searchWord, wordCount);

//get word to search(trouble with this)




}
while(searchWord != "exit");


return 0;
}
Last edited on
Topic archived. No new replies allowed.