The contents of a file named, anput txt Is character strings, separated by one or more white space characters (SPACE, TAB, NEWLINE) Write a program that reads the input file and counts the number of words in the input file Display the number of words on the screen For example If this is the contents of file anput txt Hello world! It asa bright day today How are you? The following will be displayed’ There are 11 words in the file anput txt
Code
#include<fstream>
#include<iostream>
#include<string>
using namespace std;
int main()
{
ifstream inFile; //Declares a file stream object
string fileName;
string word;
int count = 0;
cout << "Please enter the file name ";
getline(cin,fileName);
inFile.open(fileName.c_str());
while(!inFile.eof())
{
inFile >> word;
count++;
}
count++;
cout << "There are "<<count<<" words in the file
"<<fileName<<endl;
inFile.close();
return 0;
}
output
input.txt file
If you have any query regarding the code please ask me in the
comment i am here for help you. Please do not direct thumbs down
just ask if you have any query. And if you like my work then please
appreciates with up vote. Thank You.
The contents of a file named, anput txt Is character strings, separated by one or more...
Program In Assembly For this part, your MAL program must be in a file named p5b.mal. It must have at least one function in addition to the main program. For the purposes of Part (b), you may assume the following 1. Any line of text typed by a user has at most 80 characters including the newline character. 2. A whitespace character refers to a space, a tab or the new line character. 3. A word is any sequence of...
Write a program that first reads in the name of an input file and then reads the file using the csv.reader() method. The file contains a list of words separated by commas. Your program should output the words and their frequencies (the number of times each word appears in the file) without any duplicates. Ex: If the input is: inputl.csv and the contents of input1.csv are: hello, cat, man, hey, dog, boy, Hello, man, cat, woman, dog, Cat, hey, boy the output is: hello 1 cat 2 man...
Consider an input file A2.txt. Each line of A2.txt consists of two numbers separated by space. Write a C++ program that reads the two numbers from each line and prints how many numbers are prime between them. Your program must have a user defined function that takes one number as input parameter and detects whether its prime or not. Show your output in a file named B2.txt using the following format: Sample Input: 3 17 42 91 Sample Output: 6...
Hello, I am struggling with this C# WPF application for one of my classes. I am using visual studio to work on it. The description for the problem is as follows: Create an app that can open a text file. Each line of the file contains an arbitrary number of words separated by spaces. Display the count for how many words are in the line and the count how many non-space characters are in the line on the form /...
implicit none ! Declare File Read Variables CHARACTER(255) :: Line INTEGER :: CP ! Character position in Line INTEGER :: File_Read_Status ! Declare character constants CHARACTER :: Tab > ACHAR(1) CHARACTER :: Space = " " ! Read all lines in the file DO READ(*,'(A)',iostat = File_Read_Status) Line ! Exit if end of file IF (File_Read_Status < 0) EXIT ! Skip leading white space DO CP = 1, LEN_TRIM(Line) IF...
Consider an input file A1.txt. Each line of A1.txt consists of two numbers separated by space. Write a C++ program that reads the two numbers from each line and adds all the integers between those two numbers (starting from the first number and ending at the second. Show your output in B1.txt. Sample Input: 1 6 18 74 29 38 Sample Output: 21 2622 335 (For further clarification, the first line of the sample output was done by 1+2+3+4+5+6 =...
PYTHON The text file motifFinding.txt contains two strings of DNA code, separated by a new-line character. Write a program that opens the file, and stores its contents into two strings, s and t, respectively. Write code that will find all instances of the string t within the string s. At the end, your program should output the number of times the sub-string t occurs within s, along with the index of the starting position of each occurrence of t within...
What to submit: your answers to exercises 2. Write a Java program to perform the following tasks: The program should ask the user for the name of an input file and the name of an output file. It should then open the input file as a text file (if the input file does not exist it should throw an exception) and read the contents line by line. It should also open the output file as a text file and write...
In C++ In this homework, you will be tasked with creating functions to manipulate strings that come from files and then outputting the strings to another file. All of these functions are housed together in a menu. The user will be asked to input a file name and then their menu selection. The menu is this: Get rid of white space Print amount of characters in the file Print amount of words in the file Replace all vowels with 3's...
Capitalization JAVA In this program, you will read a file line-by-line. For each line of data (a string), you will process the words (or tokens) of that line one at a time. Your program will capitalize each word and print them to the screen separated by a single space. You will then print a single linefeed (i.e., newline character) after processing each line – thus your program will maintain the same line breaks as the input file. Your program should...