Question

In: Computer Science

(b) You will write a program that will do the following: prompt the user enter characters...

(b) You will write a program that will do the following: prompt the user enter characters from the keyboard, you will read the characters until reading the letter ‘Q’ You will compute statistics concerning the type of characters entered. In this lab we will use a while loop. We will read characters from stdin until we read the character ‘Q’.

Example input mJ0*5/]+x1@3qcxQ

The ‘Q’ should be included when computing the statistics properties of the input. Since characters are integers you will determine the average character (average when one looks at the character as an integer (its ASCII value). To achieve this you will need to compute the sum of the ASCII values of the characters. We are interested in determining the following statistics

1.The number of lowercase alphabetical characters

2.The number of even digits ‘0’, ‘2’, ‘4’, ‘6’, ‘8’

3.The total number of characters inputted (include ‘Q’)

4.The number of line feeds (ASCII value of 10)

5.The average character (here we treat the characters as an integer based on their ASCII values)

6.The average alphabetical character that is read (include the ‘Q’)

Output each in a formatted manner (in your output describe what the output is,

for example The number of even digits is 5

THIS CODE HAS TO BE WRITTEN USING THE C PROGRAMMING LANGUAGE.

Solutions

Expert Solution

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.

If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.

Thank You!
===========================================================================

#include<stdio.h>

int main(){

   int lowercases = 0,
       evendigits =0,
       total_chars =0,
       line_feeds =0,
       total_sum =0,
       alphabetical_sum = 0,
       total_alphabets = 0;
      
       char input;
       printf("Enter a character (Q to exit): ");  
       while(input!='Q')   {
          
           input = getchar();
           if(input==10) line_feeds+=1;
           else if('a'<=input && input<='z'){
               lowercases+=1;
               total_alphabets+=1;
               alphabetical_sum+= int(input);
           } else if('A'<=input && input<='Z'){
               total_alphabets+=1;
               alphabetical_sum+= int(input);
           }
           else if(input=='0' || input=='2' || input=='4' || input=='8') {
               evendigits+=1;
           }
           total_sum += int(input);
           total_chars+=1;
       }
      
       //1.The number of lowercase alphabetical characters
       printf("Total number of lowercases: %d\n",lowercases);
       //2.The number of even digits ‘0’, ‘2’, ‘4’, ‘6’, ‘8’
       printf("Even digits: %d\n",evendigits);
       //3.The total number of characters inputted (include ‘Q’)
       printf("Total number of characters: %d\n",total_chars);
       //4.The number of line feeds (ASCII value of 10)
       printf("Line feeds entered: %d\n",line_feeds);
       //5.The average character
       printf("Average Character: %d\n",total_sum/total_chars);
       //6.The average alphabetical character that is read (include the ‘Q’)
       printf("Average alphabetical character: %d\n",alphabetical_sum/total_alphabets);
  
}


Related Solutions

Write a program that asks the user to enter an array of 8 characters then you...
Write a program that asks the user to enter an array of 8 characters then you have to check if characters ‘b’ or ‘a’ appears within the characters and replace them with ‘B’ or ‘A’. For example you enter “a m a l a a b d” The output should be “A m A l A A B d”
IN C This assignment is to write a program that will prompt the user to enter...
IN C This assignment is to write a program that will prompt the user to enter a character, e.g., a percent sign (%), and then the number of percent signs (%) they want on a line. Your program should first read a character from the keyboard, excluding whitespaces; and then print a message indicating that the number must be in the range 1 to 79 (including both ends) if the user enters a number outside of that range. Your program...
Write a C program Your program will prompt the user to enter a value for the...
Write a C program Your program will prompt the user to enter a value for the amount of expenses on the credit card. Retrieve the user input using fgets()/sscanf() and save the input value in a variable. The value should be read as type double. The user may or may not enter cents as part of the input. In other words, expect the user to enter values such as 500, 500.00 and 500.10. The program will then prompt the user...
Write a program that prompts the user to enter two characters and display the corresponding major...
Write a program that prompts the user to enter two characters and display the corresponding major and year status. The first character indicates the major. And the second character is a number character 1, 2, 3, 4, which indicates whether a student is a freshman, sophomore, junior, or senior. We consider only the following majors: B (or b): Biology C (or c): Computer Science I (or i): Information Technology and Systems M (or m): Marketing H (or h): Healthcare Management...
Write a C program that prompt the user to enter 10 numbers andstores the numbers...
Write a C program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
Write a C++ program that prompt the user to enter 10 numbers andstores the numbers...
Write a C++ program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
A. Write a program 1. Prompt the user to enter a positive integer n and read...
A. Write a program 1. Prompt the user to enter a positive integer n and read in the input. 2. Print out n of Z shape of size n X n side by side which made up of *. B. Write a C++ program that 1. Prompt user to enter an odd integer and read in the value to n. 2. Terminate the program if n is not odd. 3. Print out a cross shape of size n X n...
Using Java! Write a program that ask prompt the user to enter a dollar amount as...
Using Java! Write a program that ask prompt the user to enter a dollar amount as double. Then, calculate how many quarters, dimes, nickels and pennies are in the dollar amount. For example: $2.56 = 10 quarters, 1 dime, 1 nickel and 1 cent. Print all of the values. Hint: Use Modulus operator and integer division when necessary.
Java Programming Language Scenario: write a program that will prompt a user for 10 legendary people/characters....
Java Programming Language Scenario: write a program that will prompt a user for 10 legendary people/characters. After the entries are complete the program will display all 10 characters information. Store these characters in an array. Requirements: Create a user-defined class with the fields below: First Last Nickname Role Origin Create a main-source that will use the user-defined class and do the prompting. Create get/set methods in your user-defined class and methods in the main-source. Use an array to store the...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT