Write a program that reads several lines from a data file and prints each word o
ID: 3676980 • Letter: W
Question
Write a program that reads several lines from a data file and prints each word of the file on a separate line of an output file followed by the number of letters in that word. Also print a count of words in the file on the screen when done. Assume that words are separated by one or more blanks. Use at least two functions. Use the following as your sample input data: Write a program that reads several lines from a data file and prints each word of the file on a separate line of an output file followed by the number of letters in that word. Also print a count of words in the file on the screen when done. Assume that words are separated by one or more blanks.
Sample output:
Write 5
a 1
program 7
The total number of words is 59
Explanation / Answer
#include //keyboard I/O #include //for external file streams #include //getch() #define in_file "data.txt" using namespace std; void strings(char,int);//function declaration ifstream ins; //ins as input stream char letter,temp; //global variables int count=0; void main() { ins.open(in_file); //open files while (!ins.eof()) { ins.get(letter); strings(letter,count); //function call } getch(); ins.close(); } void strings(char ch, int countCh) { while(ch!=' ') { if((ch>='A' && ch='a' && chRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.