Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C programming! Write a program that prompts a user to input a sequence of characters (including spaces and special characters) and then uses your

In C programming!

Write a program that prompts a user to input a sequence of characters (including spaces and special characters) and then uses your (user defined) functions to output:

  • the number of characters in the string
  • the number of vowels in the string
  • the number of UPPERCASE letters in the string
  • the number of lowercase letters in the string
  • the number of other characters in the string

Your program will need the following 4 functions (use these exact function names):

  • boolean function, IsVowel, that takes a char and returns a true if a given character is a vowel, otherwise returns false
  • int function, CountUC, that takes a string and returns the number of UPPERCASE letters in the string
  • int function, CountLC, that takes a string and returns the number of lowercase letters in the string
  • int function, CountOthers, that takes a string and returns the number of non-letters in the string

RESTRICTIONS: Your program MAY NOT use any predefined function from . You must define and call your own functions.

NOTES: Be sure to include your function prototypes before your main function, and your function definitions after your main function.

Sample output (sample input shown with italics):

Enter a sentence: Is THIS another Test???

There are 23 total characters.

There are 6 vowels.

There are 6 UPPERCASE letters.

There are 11 lowercase letters.

There are 6 other characters.

_____________________________________

Here is the code I have so far:

#include #include

bool isVowel(char ch) { return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U'; }

int countUC(char *str) { int count = 0, i = 0; char ch; while((ch = str[i++])) { if(ch >= 'A' && ch <= 'Z') { ++count; } } return count; }

int countLC(char *str) { int count = 0, i = 0; char ch; while((ch = str[i++])) { if(ch >= 'a' && ch <= 'z') { ++count; } } return count; }

int countOthers(char *str) { int count = 0, i = 0; char ch; while((ch = str[i++])) { if(!((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))) { ++count; } } return count; }

int countVowels(char *str) { int count = 0, i = 0; char ch; while((ch = str[i++])) { if(isVowel(ch)) { ++count; } } return count; }

int countCharacters(char *str) { int count = 0; while(str[count++]); return count-1; }

int main() { char str[100]; printf("Enter a sentence: "); scanf("%s", str); printf("There are %d total characters. ", countCharacters(str)); printf("There are %d vowels. ", countVowels(str)); printf("There are %d UPPERCASE letters. ", countUC(str)); printf("There are %d lowercase letters. ", countLC(str)); printf("There are %d other characters. ", countOthers(str)); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago