Question

In: Computer Science

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 :)

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 = 1

Solutions

Expert Solution

//give it a thumbs up

C++ code

//put .txt file along with .c file

#include <stdio.h>

int main()
{
FILE *fp;
char filename[100];
char ch,ch2='b';
int linecount, wordcount, charcount,syl;

linecount = 0;
wordcount = 0;
charcount = 0;
syl = 0;

printf("Enter a filename :");
gets(filename);

fp = fopen(filename,"r");

if ( fp )
{
   while ((ch=getc(fp)) != EOF) {
       if (ch != ' ' && ch != '\n') { ++charcount; }

       if (ch == ' ' || ch == '\n') { ++wordcount; }

       if (ch == '\n' || ch=='.' || ch==':' ||ch==';' ||ch=='?'||ch=='!') { ++linecount; }

       if (ch=='a'||ch=='i'||ch=='o'||ch=='u'||ch=='e')
       {
               if(ch2!='a'&&ch2!='e'&&ch2!='i'&&ch2!='o'&&ch2!='u')
               {
                   syl++;
               }
       }
       if(ch==' '&&ch2=='e')
       {
               syl--;
       }
       ch2=ch;
   }

   if (charcount > 0) {
       ++linecount;
       ++wordcount;
   }
}
else
{
printf("Failed to open the file\n");
}
   float ind;
   ind = 206.835 - 84.6*((syl*1.0)/wordcount) - 1.015 * ((wordcount*1.0)/linecount);
   float diff = (int)ind;
   if(diff>=0.50)
   {
       ind = (int)ind+1;
   }
   else
       ind = (int)ind;
   int ans = ind;
   printf("Flesch Index : %d \n", ans);
   printf("Syllable count : %d \n", syl);
   printf("Words count : %d \n", wordcount);
printf("Sentences : %d \n", linecount);

return(0);
}


Related Solutions

C++ and leave comments explaining. Thank you You are given two STL lists X and P...
C++ and leave comments explaining. Thank you You are given two STL lists X and P where n P is already in sorted order. Write a valid C++ function printPositions(X,P) that prints the elements in X specified by P. For example, if P = 0, 3, 7, 8, the elements in positions 0 (head of the list), 3, 7, and 8 in X are printed. You may use only the public STL container operations. Also specify the running time of...
If answer can be shown using a c++ program and leave comments it will be very...
If answer can be shown using a c++ program and leave comments it will be very appreciated!!! A bank charges $10 per month plus the following check fees for a commercial checking account: $0.10 each for fewer than 20 checks $0.08 each for 20-39 checks $0.06 each for 40-59 checks $0.04 each for 60 or more checks The bank also charges an extra $15.00 if the balance of the account falls below $400 (before any check fees are applied). Write...
HELLO CAN YOU PLEASE DO THIS JAVA PROGRAM I WILL LEAVE AWESOME RATING. THANK YOU IN...
HELLO CAN YOU PLEASE DO THIS JAVA PROGRAM I WILL LEAVE AWESOME RATING. THANK YOU IN ADVANCE. QUESTION Suppose you are designing a game called King of the Stacks. The rules of the game are as follows:  The game is played with two (2) players.  There are three (3) different Stacks in the game.  Each turn, a player pushes a disk on top of exactly one of the three Stacks. Players alternate turns throughout the game. Each...
In c++ Write a program that reads a string consisting of a positive integer or a...
In c++ Write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format. Use the STL stack
In c++, write a program that reads a string consisting of a positive integer or a...
In c++, write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format.
I need specific codes for this C program assignment. Thank you! C program question: Write a...
I need specific codes for this C program assignment. Thank you! C program question: Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and...
: This exercise will give you a review of Strings and String processing. Create a class...
: This exercise will give you a review of Strings and String processing. Create a class called MyString that has one String called word as its attribute and the following methods: Constructor that accepts a String argument and sets the attribute. Method permute that returns a permuted version of word. For this method, exchange random pairs of letters in the String. To get a good permutation, if the length of the String is n, then perform 2n swaps. Use this...
Program Language C++ How do I take lines of string from an input file, and implement...
Program Language C++ How do I take lines of string from an input file, and implement them into a stack using a double linked list? Example input, command.txt, and output file. Ex: Input.txt postfix: BAC-* prefix:+A*B/C-EF postfix:FE-C/B*A+ postfix:AB-C-D/ postfix:AB-CF*-D / E+ Command.txt printList printListBackwards Output.txt List: postfix:BAC-* prefix:+A*B/C-EF postfix:FE-C/B*A+ postfix:AB-C-D/ postfix:AB-CF*-D/E+ Reversed List: postfix:AB-CF*-D/E+ postfix:AB-C-D/ postfix:FE-C/B*A+ prefix:+A*B/C-EF postfix:BAC-*
Create this C++ program using classes 1. Create a file text file with a string on...
Create this C++ program using classes 1. Create a file text file with a string on it 2. Check the frecuency of every letter, number and symbol (including caps) 3. Use heapsort to sort the frecuencys found 4. Use huffman code on the letters, symbols or numbers that have frecuencys I created the file, and the frecuency part but i'm having trouble with the huffman and heapsort implementation.
PLEASE PROVIDE COMMENTS ON STEPS Write a C++ program that modifies a string (null terminated) as...
PLEASE PROVIDE COMMENTS ON STEPS Write a C++ program that modifies a string (null terminated) as follows: Consonants are positioned at the beginning of the string and vowels are moved to the end of the string. Example : Original string : washer New string : wshrae Note: The library string functions cannot be used. You must use pointers and the switch statement to execute this program. Assume that the vowels are a, e, i, o, and u. The modification has...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT