C++ Programming Instructions Write a program that prompts the user for a sequence of characters (all typed on a single line) and counts the number of vowels ('a', 'e', 'i', 'o', 'u'), consonants, and any other characters that appear in the input. The user terminates input by typing either the period (.) or exclamation mark character (!) followed by the Enter key on your keyboard. Your program will not count white space characters.I.e., you will ignore white space characters.Though, the cin statement will skip white space characters in the input for you. Your program will not be case-sensitive. Thus, the characters 'a' and 'A' are both vowels and the characters 'b' and 'B' are both consonants.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 19PE
icon
Related questions
Question

C++ Programming Instructions

Write a program that prompts the user for a sequence of characters (all typed on a single line) and counts the number of vowels ('a', 'e', 'i', 'o', 'u'), consonants, and any other characters that appear in the input. The user terminates input by typing either the period (.) or exclamation mark character (!) followed by the Enter key on your keyboard.

  • Your program will not count white space characters.I.e., you will ignore white space characters.Though, the cin statement will skip white space characters in the input for you.
  • Your program will not be case-sensitive. Thus, the characters 'a' and 'A' are both vowels and the characters 'b' and 'B' are both consonants.

For example, the input How? 1, 2, 3. contains one vowel, two consonants, and six other kinds of characters.

IMPORTANT: Your program must use the while statement only when looping. I.e., do not use a for statement or any other looping statement.

 

Test 1

> run

Enter text:

.

Your sentence has 0 letter(s).

Number of a's: 0

Number of e's: 0

Number of i's: 0

Number of o's: 0

Number of u's: 0

Number of consonants: 0

Number of digits: 0

Number of other characters: 0

Vowels make up 0% of the sentence.

Test 2

> run

Enter text:

!

Your sentence has 0 letter(s).

Number of a's: 0

Number of e's: 0

Number of i's: 0

Number of o's: 0

Number of u's: 0

Number of consonants: 0

Number of digits: 0

Number of other characters: 0

Vowels make up 0% of the sentence.

Test 3

> run

Enter text:

a.

Your sentence has 1 letter(s).

Number of a's: 1

Number of e's: 0

Number of i's: 0

Number of o's: 0

Number of u's: 0

Number of consonants: 0

Number of digits: 0

Number of other characters: 0

Vowels make up 100.00% of the sentence.

Test 4

> run

Enter text:

ia!

Your sentence has 2 letter(s).

Number of a's: 1

Number of e's: 0

Number of i's: 1

Number of o's: 0

Number of u's: 0

Number of consonants: 0

Number of digits: 0

Number of other characters: 0

Vowels make up 100.00% of the sentence.

Test 5

> run

Enter text:

apple.

Your sentence has 5 letter(s).

Number of a's: 1

Number of e's: 1

Number of i's: 0

Number of o's: 0

Number of u's: 0

Number of consonants: 3

Number of digits: 0

Number of other characters: 0

Vowels make up 40.00% of the sentence.

Test 6

> run

Enter text:

orange#pear!

Your sentence has 11 letter(s).

Number of a's: 2

Number of e's: 2

Number of i's: 0

Number of o's: 1

Number of u's: 0

Number of consonants: 5

Number of digits: 0

Number of other characters: 1

Vowels make up 45.45% of the sentence.

Test 7

> run

Enter text:

JacKsoN,MiSsiSSipPI.

Your sentence has 19 letter(s).

Number of a's: 1

Number of e's: 0

Number of i's: 4

Number of o's: 1

Number of u's: 0

Number of consonants: 12

Number of digits: 0

Number of other characters: 1

Vowels make up 31.58% of the sentence.

Test 8

> run

Enter text:

OsU ruLez, Cols, OH.

Your sentence has 16 letter(s).

Number of a's: 0

Number of e's: 1

Number of i's: 0

Number of o's: 3

Number of u's: 2

Number of consonants: 8

Number of digits: 0

Number of other characters: 2

Vowels make up 37.50% of the sentence.

Test 9

> run

Enter text:

Equation 5 * 3 - 2 / (3 % 5).

Your sentence has 19 letter(s).

Number of a's: 1

Number of e's: 1

Number of i's: 1

Number of o's: 1

Number of u's: 1

Number of consonants: 3

Number of digits: 5

Number of other characters: 6

Vowels make up 26.32% of the sentence.

Test 10

> run

Enter text:

You passed the final test :) AWESOME.

Your sentence has 30 letter(s).

Number of a's: 3

Number of e's: 5

Number of i's: 1

Number of o's: 2

Number of u's: 1

Number of consonants: 16

Number of digits: 0

Number of other characters: 2

Vowels make up 40.00% of the sentence.

 

 

 

\

Your solution will be graded based upon program behavior (passing tests). Your solution will not receive full
credit (or receives no credit) if you fail to follow these restrictions:
Your program must compile and run. Otherwise it will receive a zero.
• Add your solution to the provided code template.
• DO NOT use the iomanip preprocessor directive (see *hints below).
• Your program must use the while statement only when looping. I.e., do not use a for statement or any
other looping statement.
• Use descriptive variable names. Avoid too short variable names, especially single letter variable names.
• DO NOT start a variable name with a capital letter.
• DO NOT use explicit type casting. Instead use coercion (see lecture notes).
• DO NOT unnecessarily use parenthesis in an expression, e.g. an equation or formula. Parenthesis should
only be used for grouping portions of an expression to change operator precedence order. For example,
parenthesis are unnecessary in the expression (a + b + c). Instead use a + b + c. Parenthesis are necessary in
the expression (a + b + c) / 3.
• DO NOT use the break and continue statements in your solution.
• Your program must be readable including indenting, spaces, and avoid lines that are too long. Use the the
sample programs in the lecture notes as a guide.
• Comment your program. Read the document at the "Lecture" link on Carmen under Modules-
>Commenting Your Program-> Commenting your program. DO NOT comment every line.
• Only use C++ statements presented in the course. I.e. statements and notation presented in the lecture
notes and assigned readings.
To receive full credit, only use C++ statements presented in the PowerPoint slides and assigned readings
up to the slides on the while statement. Your solution will be graded based on passing test cases,
formatting, and good choice of variable names. Write your solution in the provided code template.
Please use the following HINTS to help you formulate your solution:
You are NOT reading your input into a string. You will read each character one at a time into the variable
character. DO NOT use the getline statement. You will use the cin statement (see the provided code
template). Use a while statement to continue reading characters from the input one at a time until the user
enters either the " or !' character. If the user enters white space then the cin statement will skip these for
you.
• Use accumulation variables that compute counts.
• For each character from the input, use mutual exclusion to decide which accumulation variable to update.
• You can use ASCII codes to help you determine whether or not a character is a consonant. The ASCII codes
for the characters 'a' - 'z' are in the range 97-122 and the characters 'A' - 'Z' are in the range 65-90.
• Determine the percentage of vowels in the input by computing the # of vowels divided by the total number
of characters in the input. Display this percentage using:
Transcribed Image Text:Your solution will be graded based upon program behavior (passing tests). Your solution will not receive full credit (or receives no credit) if you fail to follow these restrictions: Your program must compile and run. Otherwise it will receive a zero. • Add your solution to the provided code template. • DO NOT use the iomanip preprocessor directive (see *hints below). • Your program must use the while statement only when looping. I.e., do not use a for statement or any other looping statement. • Use descriptive variable names. Avoid too short variable names, especially single letter variable names. • DO NOT start a variable name with a capital letter. • DO NOT use explicit type casting. Instead use coercion (see lecture notes). • DO NOT unnecessarily use parenthesis in an expression, e.g. an equation or formula. Parenthesis should only be used for grouping portions of an expression to change operator precedence order. For example, parenthesis are unnecessary in the expression (a + b + c). Instead use a + b + c. Parenthesis are necessary in the expression (a + b + c) / 3. • DO NOT use the break and continue statements in your solution. • Your program must be readable including indenting, spaces, and avoid lines that are too long. Use the the sample programs in the lecture notes as a guide. • Comment your program. Read the document at the "Lecture" link on Carmen under Modules- >Commenting Your Program-> Commenting your program. DO NOT comment every line. • Only use C++ statements presented in the course. I.e. statements and notation presented in the lecture notes and assigned readings. To receive full credit, only use C++ statements presented in the PowerPoint slides and assigned readings up to the slides on the while statement. Your solution will be graded based on passing test cases, formatting, and good choice of variable names. Write your solution in the provided code template. Please use the following HINTS to help you formulate your solution: You are NOT reading your input into a string. You will read each character one at a time into the variable character. DO NOT use the getline statement. You will use the cin statement (see the provided code template). Use a while statement to continue reading characters from the input one at a time until the user enters either the " or !' character. If the user enters white space then the cin statement will skip these for you. • Use accumulation variables that compute counts. • For each character from the input, use mutual exclusion to decide which accumulation variable to update. • You can use ASCII codes to help you determine whether or not a character is a consonant. The ASCII codes for the characters 'a' - 'z' are in the range 97-122 and the characters 'A' - 'Z' are in the range 65-90. • Determine the percentage of vowels in the input by computing the # of vowels divided by the total number of characters in the input. Display this percentage using:
To receive full credit, only use C++ statements presented in the PowerPoint slides and assigned readings
up to the slides on the while statement. Your solution will be graded based on passing test cases,
formatting, and good choice of variable names. Write your solution in the provided code template.
Please use the following HINTS to help you formulate your solution:
• You are NOT reading your input into a string. You will read each character one at a time into the variable
character. DO NOT use the getline statement. You will use the cin statement (see the provided code
template). Use a while statement to continue reading characters from the input one at a time until the user
enters either the " or T' character. If the user enters white space then the cin statement will skip these for
you.
• Use accumulation variables that compute counts.
• For each character from the input, use mutual exclusion to decide which accumulation variable to update.
• You can use ASCII codes to help you determine whether or not a character is a consonant. The ASCII codes
for the characters 'a' - 'z' are in the range 97-122 and the characters 'A' - Z' are in the range 65-90.
• Determine the percentage of vowels in the input by computing the # of vowels divided by the total number
of characters in the input. Display this percentage using:
cout.setf(ios:fixed);
cout.precision(2);
DO NOT include the iomanip preprocessor directive!
Important!: Write your code incrementally. This means implement your solution one portion at a time
where you compile, run, and test the code portion before moving on to the next portion. Use the provided
test cases to help you arrive at your final solution.
TASK 1: Study the lecture notes (Powerpoint slides and pre-recorded lectures) and assigned readings
before you start.
TASK 2: Replace "??" with your name, creation date, and a description of the program (synopsis).
NOTE: DO NOT delete nor change the code already given to you in the code template, except for the
comments /* REPLACE THIS COMMENT WITH YOUR VARIABLES */ and /* REPLACE THIS COMMENT
WITH YOUR CODE */. You will insert your solution by replacing these two comments.
TASK 3: Write C++ code using the while statement to repeatedly read a sequence of characters from the
user using the cin statement until the user enters a period (.) or exclamation mark (!).
TASK 4: Write C++ code to count the number of vowels, consonants, numeric digits, and other characters.
TASK 5: Write C++ code to display statistics using the counts computed in TASK 4.
• Be sure that there is a comment documenting each variable (see the document on Carmen under Modules
on how to comment your code).
• Do not start a variable name with a capital letter. Be sure that your code is properly indented, readable,
and use good descriptive names.
Transcribed Image Text:To receive full credit, only use C++ statements presented in the PowerPoint slides and assigned readings up to the slides on the while statement. Your solution will be graded based on passing test cases, formatting, and good choice of variable names. Write your solution in the provided code template. Please use the following HINTS to help you formulate your solution: • You are NOT reading your input into a string. You will read each character one at a time into the variable character. DO NOT use the getline statement. You will use the cin statement (see the provided code template). Use a while statement to continue reading characters from the input one at a time until the user enters either the " or T' character. If the user enters white space then the cin statement will skip these for you. • Use accumulation variables that compute counts. • For each character from the input, use mutual exclusion to decide which accumulation variable to update. • You can use ASCII codes to help you determine whether or not a character is a consonant. The ASCII codes for the characters 'a' - 'z' are in the range 97-122 and the characters 'A' - Z' are in the range 65-90. • Determine the percentage of vowels in the input by computing the # of vowels divided by the total number of characters in the input. Display this percentage using: cout.setf(ios:fixed); cout.precision(2); DO NOT include the iomanip preprocessor directive! Important!: Write your code incrementally. This means implement your solution one portion at a time where you compile, run, and test the code portion before moving on to the next portion. Use the provided test cases to help you arrive at your final solution. TASK 1: Study the lecture notes (Powerpoint slides and pre-recorded lectures) and assigned readings before you start. TASK 2: Replace "??" with your name, creation date, and a description of the program (synopsis). NOTE: DO NOT delete nor change the code already given to you in the code template, except for the comments /* REPLACE THIS COMMENT WITH YOUR VARIABLES */ and /* REPLACE THIS COMMENT WITH YOUR CODE */. You will insert your solution by replacing these two comments. TASK 3: Write C++ code using the while statement to repeatedly read a sequence of characters from the user using the cin statement until the user enters a period (.) or exclamation mark (!). TASK 4: Write C++ code to count the number of vowels, consonants, numeric digits, and other characters. TASK 5: Write C++ code to display statistics using the counts computed in TASK 4. • Be sure that there is a comment documenting each variable (see the document on Carmen under Modules on how to comment your code). • Do not start a variable name with a capital letter. Be sure that your code is properly indented, readable, and use good descriptive names.
Expert Solution
Step 1

Use strlength () function to count the number of characters .

Below is the code:

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr