Hey people! Can you please help me with this problem? I am so stuck on it and my instructor gave me hints on what I should do. No arrays or anything crazy yet, I'm still a beginer.
1.) Write a program that will compute average word length (average number of characters per word) for a file that contains some text. A word is defined to be any string of symbols that is preceded and followed by one of the following at each end: a blank, a comma, a period, the beginning of a line, or the end of a line. Your program should define a function that is called the input-file stream as an argument.
2.) Write a program that prompts the user to input the name of a text file and then outputs the number of words in the file. You can consider a "word" to be any text that is surrounded by whitespace (for example, a space, carriage return, newline) or borders the beginning or end of the file.
This is my code so far, I know its not much but I really need help with this problem:
And apparently I can try to modify the same code for Problem 1 and Problem 2. Thank you for trying to help me out.
#include "iostream"//include statement(s) #include "iomanip" #include "fstream" using namespace std;//using namespace statement(s) int main() { char filename[17]; cin >> filename; ifstream in_stream; ofstream out_stream; in_stream.open(filename); out_stream.open("results.txt"); char myChar; bool isWhiteSpace (char myChar); { switch (myChar) { case '\n': case '\t': case ' ' : case '\r': case ',': case '.': case '?': case '!': return true; break; default: return false; } in_stream.close(); out_stream.close(); system ("PAUSE"); return 0;//return statement(s) }