In C++, Write a program to read in a simple text file (let\'s call it \"simplefi
ID: 3780883 • Letter: I
Question
In C++, Write a program to read in a simple text file (let's call it "simplefile.txt") and:
find the number of chars in each word (save those values in an array called "word"), the number of chars in each line (save those values as an array called "line"), the number of chars in each sentence (save those values as an array called "sent"), and the number of chars in each paragraph (save those values as an array called "para").Please make the program as simple as possible and include comments illustrating the logic behind each step.
Explanation / Answer
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream inMyStream (simplefile.Txt); //for reading the text file
if (!inMyStream.is_open("")) // if the file failed to open display error.
{
cout << "There was a problem opening the file. Press any key to close." << endl;
}
else //if the file opened is successfully
{
int* array_word=new int[limit]; //for stroing the number of words.
{
for (int number = 0; number < limit; number++)
{
inMyStream >> stepc_char;
cout << stepc_char << endl;
array_word[number] = stepc_char; //for storing the number of characters in each word.
}
}
int* arraay_line =new int[limit]; //for stroing the number of line.
{
for (int number = 0; number < limit; number++)
{
inMyStream >> stepc_char;
cout << stepc_char << endl;
arraay_line[number] = stepc_char; //for storing the number of characters in each line.
}
}
int* array_sent[]=new int[n]; //for stroing the number of senteces.
{
for (int number = 0; number < limit; number++)
{
inMyStream >> stepc_char;
cout << stepc_char << endl;
arraay_sent[number] = stepc_char; //for storing the number of characters in each sentence.
}
}
int* arraay_para[]=new int[n]; //for stroing the number of paragragraphs.
{
for (int number = 0; number < limit; number++)
{
inMyStream >> stepc_char;
cout << stepc_char << endl;
arraay_para[number] = stepc_char; //for storing the number of characters in each paragraph.
}
}
inMyStream.close();
}