From 7d45bd49582ad610670cce7fdfbcee172952518f Mon Sep 17 00:00:00 2001 From: Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> Date: Thu, 7 Dec 2023 05:44:34 +0000 Subject: Wed, Dec 6, 2023, 9:44 PM -08:00 --- wk2/lab2/scrabble/scrabble.c | 28 ++++++++++++++++++ wk2/pset2/readability/readability.c | 58 +++++++++++++++++++++++++++++++++++++ wk2/sect2/scrabble/scrabble.c | 27 ----------------- 3 files changed, 86 insertions(+), 27 deletions(-) create mode 100644 wk2/lab2/scrabble/scrabble.c create mode 100644 wk2/pset2/readability/readability.c delete mode 100644 wk2/sect2/scrabble/scrabble.c diff --git a/wk2/lab2/scrabble/scrabble.c b/wk2/lab2/scrabble/scrabble.c new file mode 100644 index 0000000..5674efe --- /dev/null +++ b/wk2/lab2/scrabble/scrabble.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include + +// Points assigned to each letter of the alphabet +int POINTS[] = {1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10}; + +int compute_score(string word); + +int main(void) +{ + // Get input words from both players + string word1 = get_string("Player 1: "); + string word2 = get_string("Player 2: "); + + // Score both words + int score1 = compute_score(word1); + int score2 = compute_score(word2); + + // TODO: Print the winner +} + +int compute_score(string word) +{ + // TODO: Compute and return score for string + +} diff --git a/wk2/pset2/readability/readability.c b/wk2/pset2/readability/readability.c new file mode 100644 index 0000000..58fc18a --- /dev/null +++ b/wk2/pset2/readability/readability.c @@ -0,0 +1,58 @@ +#include +#include + +int main(void) +{ + string text = get_string("Text: "); + int s = 0; + int w = 1; + int l = 0; + int i = 0; + char c; + do + { + c = text[i]; + int j = c; + i++; + //printf("%i ", j); + if (c == '.' || c == '!' || c == '?') + { + s++; + } + else if (c == ' ') + { + w++; + } + else if ((64 < j && j < 91) || (96 < j && j < 123)) + { + l++; + } + } + while (c != '\0'); + printf("s: %i w: %i l: %i\n", s, w, l); + float L = (float)(l / w) * 100; + float S = (float)(s / w) * 100; + float index = 0.0588 * L - 0.296 * S - 15.8; + printf("L: %f, S: %f, Grade: %f\n", L, S, index); +} +/* + +*DONE* Your program must prompt the user for a string of text using get_string. + +*DONE* Your program should count the number of letters, words, and sentences + in the text. You may assume that a letter is any lowercase + character from a to z or any uppercase character from A to Z, + any sequence of characters separated by spaces should count as + a word, and that any occurrence of a period, exclamation point, + or question mark indicates the end of a sentence. + +Your program should print as output "Grade X" where X is the grade + level computed by the Coleman-Liau formula, rounded to the nearest + integer. + +If the resulting index number is 16 or higher (equivalent to or + greater than a senior undergraduate reading level), your program + should output "Grade 16+" instead of giving the exact index + number. If the index number is less than 1, your program should + output "Before Grade 1". +*/ diff --git a/wk2/sect2/scrabble/scrabble.c b/wk2/sect2/scrabble/scrabble.c deleted file mode 100644 index b682df2..0000000 --- a/wk2/sect2/scrabble/scrabble.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include -#include - -// Points assigned to each letter of the alphabet -int POINTS[] = {1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10}; - -int compute_score(string word); - -int main(void) -{ - // Get input words from both players - string word1 = get_string("Player 1: "); - string word2 = get_string("Player 2: "); - - // Score both words - int score1 = compute_score(word1); - int score2 = compute_score(word2); - - // TODO: Print the winner -} - -int compute_score(string word) -{ - // TODO: Compute and return score for string -} -- cgit v1.2.3