Question

In: Computer Science

Write a batch program that takes and echoes input data one character at a time until...

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

Solutions

Expert Solution

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!!!!!!!!----------


Related Solutions

Write a complete C++ program that prompts the user for and takes as input, numbers until...
Write a complete C++ program that prompts the user for and takes as input, numbers until the user types in a negative number. the program should add all of the numbers together. Then if the result is less than 20 the program should multiply the result by 3, otherwise subtract 2 from the result. Finally, the program should printout the result.
Write a function that takes a number as input, and returns the character A if the...
Write a function that takes a number as input, and returns the character A if the input is 90 and above, B if it’s 80 and above but less than 90, C if it’s at least 70 but less than 80, D if it’s at least 60 but less than 70, and F if it’s less than 60. If the input is not a number or is negative, the function should exit 1 with an error (by calling the Matlab...
Write a program that accepts a string and character as input, then counts and displays the...
Write a program that accepts a string and character as input, then counts and displays the number of times that character appears (in upper- or lowercase) in the string. Use C++ Enter a string: mallet Enter a character: a "A" appears 1 time(s) Enter a string: Racecar Enter a character: R "R" appears 2 time(s)
Using c# , Write a program using a switch statement that takes one character value from...
Using c# , Write a program using a switch statement that takes one character value from the user and checks whether the entered value is an arithmetic operator (+, -, * , /) If not the program display a message that it not of the operators ( (+, -, * , /) .
Write a program that takes a date as input and outputs the date's season. The input...
Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an int to represent the day. Ex: If the input is: April 11 the output is: Spring In addition, check if the string and int are valid (an actual month and day). Ex: If the input is: Blue 65 the output is: Invalid The dates for each season are: Spring: March 20 - June 20 Summer:...
Statistics are often calculated with varying amounts of input data. Write a program that takes any...
Statistics are often calculated with varying amounts of input data. Write a program that takes any number of non-negative integers as input and outputs the average and max. A negative integer ends the input and is not included in the statistics. Ex: When the input is 15 20 0 5 -1, the output is: 10 20 You can assume that at least one non-negative integer is input. Can this be written in CORAL please!!
Write a program whose input is a string which contains a character and a phrase, and...
Write a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times the character appears in the phrase. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. Ex: If the input is: n Nobody the output is: 0...
Write a basic C++ program with function, whose input is a character and a string, and...
Write a basic C++ program with function, whose input is a character and a string, and whose output indicates the number of times the character appears in the string. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. n is different than N. Ex: If the input is: n...
In objective-C Task: Write a program whose input is a character and a string, and whose...
In objective-C Task: Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in the string. The output should include the input character and use the plural form, n's, if the number of times the characters appears is not exactly 1.You may assume that the string does not contain spaces and will always contain less than 50 characters. Ex: If the input is: n Monday the output is:...
Write a program that takes in a positive integer as input, and outputs a string of...
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x / 2 Note: The above algorithm outputs the 0's and 1's in reverse order. Ex: If the input is: 6 the output is: 011 6 in binary is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT