Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. //Amira Spann
  2. // 6/28/16
  3. // program 8
  4. // program to count the number of sentences, lines, words, and the like in a text file
  5. #include <iostream>
  6. #include <fstream>
  7. #include <cctype>
  8. #include <cstring>
  9. using namespace std;
  10. // the constant size of the array should be 80 characters per line of the text file.
  11. const int SIZE = 80;
  12.  
  13. // The variable that is going to constantly open the files in the functions, I tried this and it surprisingly made things quicker
  14. ifstream inF;
  15. //the amount of numbers in the text file
  16. int amtOfNum;
  17. // amount of sentences
  18. int numSent;
  19. //amount of words
  20. int numWords;
  21. //amount of lines and the variable n.
  22. int numLines, n;
  23. string line;
  24. char x;
  25. // the array
  26. char array = SIZE;
  27.  
  28.  
  29.  
  30. int main() {
  31.  
  32.  
  33.  
  34. // calling all of the functions to perform the tasks
  35. void sentenceCounter();
  36. void spaceCounter();
  37. void punctuationCounter();
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46. cout << "Number of Lines : " << numLines << endl;
  47. return 0;
  48.  
  49. }
  50.  
  51.  
  52.  
  53. // the function to count the amount of sentences in the
  54. void sentenceCounter() {
  55. inF.open("out.txt");
  56. char word[80];
  57. int count = 0;
  58. while (!inF.eof())
  59. {
  60. inF >> word;
  61. count++;
  62. }
  63. count = numSent;
  64. cout << " Number of Sentences : " << numSent << endl;
  65. inF.close();
  66.  
  67.  
  68. }
  69.  
  70. // the functin to count the number of spaces
  71. void spaceCounter() {
  72. // open the file
  73. ifstream in;
  74. //open the text and go through it
  75. in.open("out.txt");
  76. char ch;
  77. int space = 0 ;
  78. //while different than the end of file, check the number of spaces in the array
  79. while (!in.eof())
  80. {
  81.  
  82. in.get(ch);
  83. if (ch == ' ')
  84. space++;
  85. //cout the number of spaces
  86. } cout << "Number of Spaces : " << space << endl;
  87. in.close();
  88. }
  89. // counting the number of punctuation marks
  90. void punctuationCounter() {
  91. ifstream in;
  92. in.open("out.txt");
  93. char ch;
  94. int amtOfPunct = 0 ;
  95. while (!in.eof())
  96. {
  97.  
  98. in.get(ch);
  99. if (ispunct(ch))
  100. amtOfPunct++;
  101. }
  102. cout << " Number of Punctuation marks : " << amtOfPunct << endl;
  103. in.close();
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement