Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Amira Spann
- // 6/28/16
- // program 8
- // program to count the number of sentences, lines, words, and the like in a text file
- #include <iostream>
- #include <fstream>
- #include <cctype>
- #include <cstring>
- using namespace std;
- // the constant size of the array should be 80 characters per line of the text file.
- const int SIZE = 80;
- // The variable that is going to constantly open the files in the functions, I tried this and it surprisingly made things quicker
- ifstream inF;
- //the amount of numbers in the text file
- int amtOfNum;
- // amount of sentences
- int numSent;
- //amount of words
- int numWords;
- //amount of lines and the variable n.
- int numLines, n;
- string line;
- char x;
- // the array
- char array = SIZE;
- int main() {
- // calling all of the functions to perform the tasks
- void sentenceCounter();
- void spaceCounter();
- void punctuationCounter();
- cout << "Number of Lines : " << numLines << endl;
- return 0;
- }
- // the function to count the amount of sentences in the
- void sentenceCounter() {
- inF.open("out.txt");
- char word[80];
- int count = 0;
- while (!inF.eof())
- {
- inF >> word;
- count++;
- }
- count = numSent;
- cout << " Number of Sentences : " << numSent << endl;
- inF.close();
- }
- // the functin to count the number of spaces
- void spaceCounter() {
- // open the file
- ifstream in;
- //open the text and go through it
- in.open("out.txt");
- char ch;
- int space = 0 ;
- //while different than the end of file, check the number of spaces in the array
- while (!in.eof())
- {
- in.get(ch);
- if (ch == ' ')
- space++;
- //cout the number of spaces
- } cout << "Number of Spaces : " << space << endl;
- in.close();
- }
- // counting the number of punctuation marks
- void punctuationCounter() {
- ifstream in;
- in.open("out.txt");
- char ch;
- int amtOfPunct = 0 ;
- while (!in.eof())
- {
- in.get(ch);
- if (ispunct(ch))
- amtOfPunct++;
- }
- cout << " Number of Punctuation marks : " << amtOfPunct << endl;
- in.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement