
...
ex2_main.cpp
#include <stdio.h>
#include <stdlib.h>
#include "lab2_ex2.h"
#define FILENAME "statement11.txt"
int main()
{
// 1. Acquire the text from file
char *text = read_text_file(FILENAME); // Note: Caller should free the memory allocated
printf("%s\n", text);
// 2. Compute the readability and display the grade level
float readability = get_readability(text);
printf("Readability index = %f\n", readability);
display_level(readability);
// 3. Free resources, e.g. allocated memory by read_text_file() function
free(text);
return 0;
}
...
lab2_ex2.cpp
/*
EDIT THIS FILE TO SOLVE THE LABORATORY EXERCISES
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include "lab2_ex2.h"
/*
Assume that a letter is any lowercase character from a to z
or any uppercase character from A to Z
*/
int alpanumeric_count(const char *text)
{
int count = 0;
/* YOUR CODE HERE!!! */
return count;
}
/*
Assume that any sequence of characters separated by spaces or new line or tab , etc. should count as a word.
' ' space
'\t' horizontal tab
'\n' newline
'\r' carriage return
*/
int word_count(const char *text)
{
int count = 0;
/* YOUR CODE HERE!!! */
return count;
}
/*
Assume that any occurrence of a period, exclamation point, or
question mark indicates the end of a sentence.
*/
int sentence_count(const char *text)
{
int count = 0;
/* YOUR CODE HERE!!! */
return count;
}
/*
This function computes the readability according to the formula:
Coleman–Liau Index Formula
CLI = 0.0588 * L - 0.296 * S - 15.8
https://en.wikipedia.org/wiki/Coleman%E2%80%93Liau_index
The Coleman–Liau index is a readability test designed by Meri Coleman and T. L. Liau to
gauge the understandability of a text. Like the Flesch–Kincaid Grade Level, Gunning fog index,
SMOG index, and Automated Readability Index, its output approximates the U.S. grade level thought
necessary to comprehend the text.
Like the ARI but unlike most of the other indices, Coleman–Liau relies on characters instead of
syllables per word. Although opinion varies on its accuracy as compared to the syllable/word and
complex word indices, characters are more readily and accurately counted by computer programs than
are syllables.
The Coleman–Liau index was designed to be easily calculated mechanically from samples of hard-copy text.
Unlike syllable-based readability indices, it does not require that the character content of words be
analyzed, only their length in characters. Therefore, it could be used in conjunction with theoretically
simple
*/
float get_readability(const char *text)
{
/* YOUR CODE HERE!!! */
return 0.0f;
}
/*
This function accepts readability and displays the readability grade level for the text
*/
void display_level(float readability)
{
int level = round(readability);
if (level < 1)
{
printf("Before Grade level 1\n");
}
else if (level > 16)
{
printf("Grade level 16+\n");
}
else
{
printf("Grade level %i\n", level);
}
}
/*
This function reads in a text file given the filename
WARN: The caller needs to free the memory to avoid leaks
*/
char *read_text_file(const char *filename)
{
FILE *fp = fopen(filename, "r");
if (fp == NULL)
{
printf("Error: could not open file %s", filename);
return NULL;
}
fseek(fp, 0, SEEK_END);
long length = ftell(fp);
fseek(fp, 0, SEEK_SET);
char *buffer = (char *)malloc(length + 1);
buffer[length] = '\0';
fread(buffer, 1, length, fp);
fclose(fp);
return buffer;
}
...
lab2_ex2.h
#ifndef lab2_ex2_h
#define lab2_ex2_h
int sentence_count(const char *);
int alpanumeric_count(const char *);
int word_count(const char *);
float get_readability(const char *);
void display_level(float);
char *read_text_file(const char *);
...
VERY IMPORTANT NOTE: Modify/edit/fix only lab2_ex1.cpp to make the program work.
i'm using VS Code on Windows

Trending nowThis is a popular solution!
Step by stepSolved in 6 steps with 2 images

- Chapter 4. Homework Assignment (read instructions carefully) Write a program that asks the user for the name of a file. The program should read all the numbers from the given file and display the total and average of all numbers in the following format (three decimal digits): Total: nnnnn.nnn Average: nnnnn.nnn Class name: FileTotalAndAverage est Case 1 Please enter the file name or type QUIT to exit:\ninput1.txtENTERTotal: 11.800\nAverage: 2.950\n Test Case 2 Please enter the file name or type QUIT to exit:\ninput2.txtENTERTotal: 17.300\nAverage: 3.460\n Test Case 3 Please enter the file name or type QUIT to exit:\ninput3.txtENTERTotal: 1.124\nAverage: 1.124\n Test Case 4 Please enter the file name or type QUIT to exit:\ninput4.txtENTERFile input4.txt is empty.\n Test Case 5 Please enter the file name or type QUIT to exit:\ninput5.txtENTERFile: input5.txt does not exist.\nPlease enter the file name again or type QUIT to…arrow_forward1. Create a file that contains 20 integers or download the attached file twenty-integers.txttwenty-integers.txt reads:12 20 13 45 67 90 100 34 56 89 33 44 66 77 88 99 20 69 45 20 Create a program that: 2. Declares a c-style string array that will store a filename. 3. Prompts the user to enter a filename. Store the file name declared in the c-string. 4. Opens the file. Write code to check the file state. If the file fails to open, display a message and exit the program. 5. Declare an array that holds 20 integers. Read the 20 integers from the file into the array. 6. Write a function that accepts the filled array as a parameter and determines the MAXIMUM value in the array. Return the maximum value from the function (the function will be of type int). 7. Print ALL the array values AND print the maximum value in the array using a range-based for loop. Use informational messages. Ensure the output is readable.arrow_forwardUsing these files BinaryFileRead.cpp // BinaryFileRead.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> using namespace std; int main() { int *arrayToSort; char fileName[50]; int size,readVal; cout << "Enter a filename to sort => "; cin >> fileName; FILE *inFile; fopen_s(&inFile,fileName, "rb"); fread(&size, sizeof(size), 1, inFile); arrayToSort = new int[size]; for (int i = 0; i < size; i++) { fread(&readVal, sizeof(readVal), 1, inFile); arrayToSort[i] = readVal; } fclose(inFile); return 0; } Timing.cpp // Timing.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <time.h> //ctime #include <sys/timeb.h> //_timeb _ftime_s using namespace std; int main() { struct _timeb timebuffer; char timeline[26]; _ftime_s(&timebuffer); ctime_s(timeline,sizeof(timeline), &(timebuffer.time)); printf("The time is %.19s.%hu %s",…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





