In: Computer Science
Write a batch program that takes and echoes input data one character at a time until EOF is encountered and then prints a summary such as
The 14 lines of text processed contained 20 capital letters, 607 lowercase letters, and 32 punctuation marks.
Program: C
SOLUTION-
I have solve the problem in C code with comments for easy
understanding :)
CODE-
//c code
#include <stdio.h>
#include <ctype.h>
//main()function declaration
int main(void)
{
//Local variables
int ch, line,upper,punct,lower;
//Assigning values to variables
line=0;
upper=0;
punct=0;
lower=0;
//check the condition using for loop
for(ch=getchar(); ch!=EOF; ch=getchar())
{
putchar(ch);
//check the condition whether it encountered a
//new line
if(ch =='\n')
++line;
//check the condition whether it encountered a
//punctuation
else if(ispunct(ch))
++punct;
//check the condition whether it encountered a
//lower case letter
else if(islower(ch))
++lower;
//check the condition whether it encountered a
//upper case letter
else if(isupper(ch))
++upper;
}
//Printing the result
printf("\n The %d lines of text processed ",line);
printf("contained %d capital letters,",upper);
printf("%d lowercase letters,\n",lower);
printf("and %d punctuation marks\n",punct);
//return successfully
return 0;
}
Sample Output:
strings are important in computer, science, strings are the
because many computer, applications, are concerned with the
are concerned with the MANIPULATION, OF TEXTUAl data,string
rather - than numerical, data, rather than numerical data a
computer - based word, processing systems, computer based a
enable - a user to compose letters, enable a user to the is
term paper, newspaper, articles, term paper newspaper strin
and even books at a computer, terminal instead, and even th
of at a typewriter. of at a typewriter string are in the is
storing the text, in the computer’s memory allows, storing
check the spelling, electronically, check the spelling then
move whole paragraphs, move whole paragraphs and then print
and then print a fresh, copy without, mistakes or erasures.
strings, play an important, role in science, as well. and a
The 14 lines of text processed contained 20 capital letters, 607 lowercase letters, and 32 punctuation marks.
IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I
WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK
YOU!!!!!!!!----------