need help with arrays, lists, counters

have this problem designing a program that

interactively prompt for and read the name of an input file
interactively prompt for and read a string to search for
open the input file (using an input filestream variable) and with one pass through the file
count the number of "words" in the file
for each word, make sure all letters, except the first, are lower case - leave the first character unchanged
count the number of "sentences" in the file
count the number of letters in the file (A-Z,a-z)
count the number of consonants in the file (consonants are letters that are not vowels - the vowels are: a, e, i, o, u, A, E, I, O, and U)
count the number of nonwhitespace characters in the file that are NOT letters

count the number of times the search string is found in the file (must be an exact match) - search for matches AFTER upper case letters have been coverted to lower case

required output (all output should be displayed on the screen)
display a message that provides the name of the input file
display the contents of the file so that each word on a line is separated by exactly 1 blank space and there are no more than 40 characters per line (including blanks); you must display the maximum number of whole words that will fit on a line without exceeding 40 characters
when the entire file has been read and displayed, display the 6 counts made with appropriate labels; when displaying the search string count, you MUST display the string enclosed in quotes as part of the label; leave at least one blank line between the end of the file and the counts
close the input file

dont even know where to start :/
Last edited on
Here's something for you to start with:

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
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
	ifstream fin;
	string tempstr, keyword;
	cout << "Enter name of file to search through: ";
	cin >> tempstr;
	fin.open(tempstr.c_str());
	cout << "Enter keyword to search for: ";
	cin >> keyword;
	
	//declare all your counters
	
	while (fin >> tempstr)
	{
		//all your counters should be doing stuff in here
	}

	//output your results here
	
	return 0;
}


You might want to take a look at these links:
http://www.cplusplus.com/forum/beginner/74288/
http://www.cplusplus.com/reference/string/string/
http://www.cplusplus.com/reference/clibrary/cctype/
Last edited on
thanks man working on it right now, will post progress hopefully it works !
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cctype>
#include <string>
using namespace std;

int main ()
{

ifstream input;
ofstream output;
string file;
string sterm;
string word;

cout << "Please enter the name of the input file " << endl;
cin >> file;
input.open (filename.c_str());
cout << "Please enter the search string " << endl;
cin >> sterm;

while (input)
{
if ( ch == '\n')
numLines ++;
if (((file >= 'a' ) && (ch <= 'z'))|| ((ch >= 'A' && (ch <= 'Z')))
numChars ++;
}

so far i have this am i on the right track?
You are going to have to declare the variables ch, numlines, and numChars before you try and use them.

and you don't need c_str() to open a file. Just use the string (which also isn't declared).
Last edited on
Topic archived. No new replies allowed.