1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#include "flesch.h"
#include <iostream>
#include <string>
using namespace std;
double fre(double syl, double w, double sen) {
double a=84.6, b=1.015;
double index=206.835-(a*(syl/w))-(b*(w/sen));
return index;
}
double fk(double syl, double w, double sen) {
double a=0.39, b=11.8;
double index= ((a)*(w/sen))+((b)*(syl/w))-10.59; //years old
return index;
}
double psk (double syl, double w, double sen) {
double a=0.0778, b=0.0455;
double index=(a*(w/sen))+(b*(syl/w))-2.7971;
return index;
}
int main() {
//gets input
bool done=false;
string tmp,s;
while (done==false) {
cout<<"enter text";
getline(cin, tmp);
if (tmp!="###") {
s+=(" "+tmp);
}
else {
done=true;
}
}
//copying string to be a constant
const string arr=s;
//processing
double syllcount, wordcount, sentcount, sen100, syl100, hund=100.0;
unsigned int i;
for (i=1;i<=s.length(); i++) {
if (sentencepunct(arr[i])==true){sentcount++;}
//Not a sentence
else if (isspace(arr[i-1])==false && isspace(arr[1])==true) { //prev is not whitespace and current is whitespace
wordcount++;
}//closes not a sentence
//did not add to wordcount
else if( isvowel(arr[i-1])==false && isvowel(arr[i])==true) {syllcount+=1.0;} //syllable counter
//not a syllable
else {continue;}
if (wordcount==hund) { //
sen100=sentcount;
syl100=syllcount;
}
}//closes processing aka for loop
//menu for kind of calculations
cout<<"Which formula would you like to use to solve for the index?"<<endl<<"1.) Flesch Reading Ease\n2.) Flesch Kincaid \n3.) Powers Sumner Kearl";
int choice;
cout<<"Use formula number: ";
cin>>choice;
switch (choice) {
case 1:
cout<<"The Flesch Reading Ease index is"<<fre(syllcount, wordcount, sentcount);
break;
case 2:
cout<<"The Flesch Kincaid index is"<<fk(syllcount, wordcount, sentcount);
break;
case 3:
cout<<"The Powers Sumner Kearl index is"<<psk(syl100, 100, sen100);
break;
}
}//closes main
|