Question

Hello! i need a program in C that uses FILE*! The instructions are below! Please dont...

Hello! i need a program in C that uses FILE*! The instructions are below!

Please dont copy paste another chegg post! Thank you! Will leave positive review!

I need a program that

1) Count all words in a file. A word is any sequence of characters delimited by white space or the end of a sentence, whether or not it is an actual English word.

2)Count all syllables in each word. To make this simple, use the following rules:

•Each group of adjacent vowels (a, e, i, o, u, y) counts as one syllable (for example, the “ea” in “real” counts as one syllable, but the “e..a” in “regal” count as two syllables). However, an “e” at the end of a word does not count as a syllable. Each word has at least one syllable even if the previous rules give a count of zero.

3) Count all sentences in the file. A sentence is a group of words terminated by a period, colon, semicolon, question mark, or exclamation mark. Multiples of each of these characters should be treated as the end of a single sentence. For example, “Fred says so!!!” is one sentence.

4) Calculates the Flesh index which is is computed by: index= 206.835 – 84.6 * ( #syllables / #words) – 1.015 * (#words / #sentences) rounded to the nearest integer (use the round function rather than ceiling or floor)

Input

Your program will read the text to be analyzed from a file. The filename is to be given as a command line parameter to the program. You will name the program fleschIndex.c and will execute the code on a file by doing the following:

./fleschIndex

For example, if you have a file with an essay and the file was named example.txt then you would do the following to find the Flesch index:

./fleschIndex example.txt

Output

The output(to stdout) from your program will be the following:

1. The Flesch/legibility index that you have computed

2. The number of syllables in the input

3. The number of words in the input

4. The number of sentences in the input

It will have the following format (and must match exactly):

OUTPUT TO CONSOLE

Flesch Index = 87

Syllable Count = 10238

Word Count = 2032

Sentence Count = 17

0 0
Add a comment Improve this question Transcribed image text
Answer #1

IF YOU HAVE ANY DOUBTS PLEASE COMMENT BELOW I WILL BE THERE TO HELP YOU

ANSWER:

CODE:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

void CountWords(char ch, int *Alpha, int *SentChk, int *punct, int *Words, int *totalSents, int *onlyVowel_e);               /* Function to counts number of words */
void CountSentences(char ch, int *SentChk, int *totalSents, int *onlyVowel_e);                               /* Function to count number of sentences */
int vowel(int c);                                                           /* Switch function to check for vowels */
void CountSyllables(char ch, int *isVowel, int *vowelChk, int *syllables, int *Vowel_e, int *onlyVowel_e, int *endVowel_e);       /* Function to count number of syllables */

int main (void)
{
   int Alpha=0;       /* letter of alphabeth variable    */
   int SentChk=0;       /* end of sentence identifier        */
   int punct=0;       /* punctuation counter            */
   int Words=0;       /* words ended by whitespace counter    */
   int totalSents=0;   /* total amount of sentences        */
   int onlyVowel_e=0;   /* only the vowel 'e' counter        */
   int isVowel=0;       /* vowel identifier            */
   int vowelChk=0;       /* number of vowels in a word        */
   int syllables=0;   /* number of syllables            */
   int Vowel_e=0;       /* number of vowels 'e'        */
   int endVowel_e=0;   /* word that ends in the vowel 'e'    */
   int totalSylls=0;   /* total number of syllables        */
   int totalWords=0;   /* total number of words        */
   int index;       /* legibility index            */
   char ch;       /* a character read from stdin        */
  
   while ((ch = getchar()) != EOF)   /* loop that reads each character from stdin until the end of file is reached */
   {          
       CountWords(ch, &Alpha, &SentChk, &punct, &Words, &totalSents, &onlyVowel_e);           /* Calls function to count words    */
       isVowel=vowel(ch);                                       /* Calls function to check vowels    */
       CountSyllables(ch, &isVowel, &vowelChk, &syllables, &Vowel_e, &onlyVowel_e, &endVowel_e);   /* Calls function to count syllables   */
   }
  
   totalWords=Words+totalSents;                                                   /* Calculates total words */
   totalSylls=syllables-endVowel_e;                                               /* Calculates total syllables */
   index= floor(206.835 - 84.6 * ((float)totalSylls/(float)totalWords) - 1.015 * ((float)totalWords/(float)totalSents)+0.5);   /* Calculates legibility index */
  
   /* Output of calculated data */
   printf("\nLegibility Index = %d", index);
   printf("\nSyllable count   = %d", totalSylls);
   printf("\nWord count       = %d", totalWords);
   printf("\nSentence count   = %d\n", totalSents);
  
    return 0;  
}

void CountWords(char ch, int *Alpha, int *SentChk, int *punct, int *Words, int *totalSents, int *onlyVowel_e)
{
   if(isalpha(ch))       /* loop to check for letters of alphabeth */
   {
       *Alpha=1;
       *SentChk=1;
   }
  
   if(ch=='.' || ch==':' || ch==';' || ch=='?' || ch=='!')       /* loop to check for sentence identifiers */
   {
       *punct=*punct+1;
      
       if (*punct>=1 && (ch=='.' || ch==':' || ch==';' || ch=='?' || ch=='!'))       /* loop to check for multiple sentence identifiers at end of word */
       {
           *Words=*Words-1;
           *punct=0;
       }
   }
  
   if(ispunct(ch))       /* loop to check for punctuation (character that is neither alphanumeric nor a space) */
   {
       *Alpha=1;
   }
  
   CountSentences(ch, SentChk, totalSents, onlyVowel_e);       /* Calls function to count number of sentences */
  
   if(((ch==' ' || ch=='\n' || ch=='.' || ch==':' || ch==';' || ch=='?' || ch=='!')) && (*Alpha==1))       /* loop to check for words ended by whitespace and punctuation */
   {
       *Words=*Words+1;
       *Alpha =0;
   }      
  
}

void CountSentences(char ch, int *SentChk, int *totalSents, int *onlyVowel_e)
{
   if((ch=='.' || ch==':' || ch==';' || ch=='?' || ch=='!') && *SentChk==1)   /* loop to check for sentence identifiers and counts sentences */
   {
       *totalSents=*totalSents+1;
       *SentChk=0;
       *onlyVowel_e =0;
   }
}

int vowel(int ch)
{
   switch (ch){
       case 'a': ;
       case 'e': ;
       case 'i': ;
       case 'o': ;
       case 'u': ;
       case 'y': return 1;  
           break;
       default : return 0;   /* if vowel identified return 1 else return 0 */
   }
}

void CountSyllables(char ch, int *isVowel, int *vowelChk, int *syllables, int *Vowel_e, int *onlyVowel_e, int *endVowel_e)
{
   if(*isVowel==1)       /* loop to check for vowels in a word */
   {
       *vowelChk=*vowelChk+1;
   }
  
   if((*isVowel==0 && *vowelChk>=1) && (isalpha(ch) || isspace(ch)))    /* loop to count number of syllables */
   {
       *syllables=*syllables+1;
       *vowelChk=0;
   }
  
   if((*Vowel_e==1) && ((isspace(ch)) || (ch=='.')))   /* loop to count words that end with vowel 'e' */
   {  
       if(*onlyVowel_e > 1)       /* loop to count words that end with more than one vowel */
       {
           *endVowel_e=*endVowel_e+1;
       }
      
       *onlyVowel_e=0;
       *Vowel_e=0;
   }
  
   if(ch=='e')       /* loop to count the vowel 'e' in words */
   {
       *Vowel_e=*Vowel_e+1;
       *onlyVowel_e=*onlyVowel_e+1;
   }
   else
   {
       *Vowel_e=0;
   }

}

testfile.txt

This is a vanilla test file. There is nothing tricky or abnormal about the
contents of this file. The counts output by student programs should be
exact as everything here is unambiguously covered by the spec.

HOPE IT HELPS YOU

RATE THUMBSUP PLEASE

Add a comment
Know the answer?
Add Answer to:
Hello! i need a program in C that uses FILE*! The instructions are below! Please dont...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C PROGRAM STRING AND FILE PROCESSING LEAVE COMMENTS! I WILL LEAVE POSITIVE REVIEW! THANK YOU :)...

    C PROGRAM STRING AND FILE PROCESSING LEAVE COMMENTS! I WILL LEAVE POSITIVE REVIEW! THANK YOU :) Use FILE I need a program that 1) Count all words in a file. A word is any sequence of characters delimited by white space or the end of a sentence, whether or not it is an actual English word. 2)Count all syllables in each word. To make this simple, use the following rules: •Each group of adjacent vowels (a, e, i, o, u,...

  • CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the fil...

    CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the file is completely read, write the words and the number of occurrences to a text file. The output should be the words in ALPHABETICAL order along with the number of times they occur and the number of syllables. Then write the following statistics to...

  • Write a Python program to read lines of text from a file. For each word (i.e,...

    Write a Python program to read lines of text from a file. For each word (i.e, a group of characters separated by one or more whitespace characters), keep track of how many times that word appears in the file. In the end, print out the top twenty counts and the corresponding words for each count. Print each value and the corresponding words, in alphabetical order, on one line. Print this in reverse sorted order by word count. You can assume...

  • //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which...

    //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...

  • I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly...

    I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly program that does the following; 1. count and display the number of words in the user input string. 2. Flip the case of each character from upper to lower or lower to upper. For example if the user types in:   "Hello thEre. How aRe yOu?" Your output should be: The number of words in the input string is: 5 The output string is : hELLO...

  • please write a C++ code Problem A: Word Shadow Source file: shadow.cpp f or java, or.cj...

    please write a C++ code Problem A: Word Shadow Source file: shadow.cpp f or java, or.cj Input file: shadow.in in reality, when we read an English word we normally do not read every single letter of that word but rather the word's "shadow" recalls its pronunciation and meaning from our brain. The word's shadow consists of the same number of letters that compose the actual word with first and last letters (of the word) in their original positions while the...

  • Hello, I am struggling with this C# WPF application for one of my classes. I am...

    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 /...

  • Word count. A common utility on Unix/Linux systems. This program counts the number of lines, words...

    Word count. A common utility on Unix/Linux systems. This program counts the number of lines, words (strings of characters separated by blanks or new lines), and characters in a file (not including blank spaces between words). Write your own version of this program. You will need to create a text file with a number of lines/sentences. The program should accept a filename (of your text file) from the user and then print three numbers: The count of lines/sentences The count...

  • Overview: file you have to complete is WordTree.h, WordTree.cpp, main.cpp Write a program in C++ that...

    Overview: file you have to complete is WordTree.h, WordTree.cpp, main.cpp Write a program in C++ that reads an input text file and counts the occurrence of individual words in the file. You will see a binary tree to keep track of words and their counts. Project description: The program should open and read an input file (named input.txt) in turn, and build a binary search tree of the words and their counts. The words will be stored in alphabetical order...

  • Make a C program to count the number of occurrences of words from the input. For...

    Make a C program to count the number of occurrences of words from the input. For example, with input "one two one three one two" your program should output: one 3 two 2 three 1 It should work for up to 100 different words. If there are more than 100 unique words in the input, the program should still work, and count the number of appearances of the first 100 unique words. Each word should have the same maximum amount...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT