Pageof 3 ZOOM APSC 177 Engineering Computation and Instrumentation Assignment 7
ID: 3729087 • Letter: P
Question
Pageof 3
ZOOM
APSC 177 Engineering Computation and Instrumentation
Assignment 7
Processing Text
APSC 177
Assignment 7
1
Due Date:
Friday
March 16, 2018
at 11 PM
Monday
March 1
9
, 2018
at 11 PM
(Extended)
Submit via Vocareum
NOTE:
You have only
TWO
submission attempts for this assignment.
Program Objective
Write a progr
am that
asks the user to enter
some text and then counts the number of
vowels, consonants, uppercase letters, lowercase letters, punctuati
on characters, and
words.
Program Specifications
You
r
program must:
Ask the user to enter
some text consisting only of letters, spaces, and the
following punctuation characters . , ; : ! ?
The user will signal the end of the text by typing
enter/return.
Use a string object to store the entered text (not a C
-
style string).
Determine how many of the characters in the text entered are:
Vowels
Consonants
Uppercase
Lowercase
Punctuation (. , : ; ! ?)
Determine the number of words in th
e text.
For the purpose of this assignment, vowels are a, e, i, o, u (or A, E, I, O, U). All
other letters (including y and Y) are consonants.
For the purpose of this assignment a word is any group of one or more
characters (letters
and/
or . , ; :
! ?) separated by one or more spaces from
any other group of one or more characters.
Display the number of vowels, consonants, uppercase letters, lowercase letters,
punctuation characters, and words.
NOTE:
The starter code in your Vocareum account conta
ins
nine
cout statements. You
MUST use these
nine
cout statements exactly
as they are given. Do NOT modify these
statements.
Do NOT change the order of these cout statements.
Do NOT add additional
cout statements.
NOTE:
The user may enter one or more sp
aces at the start
and/or end
of the text. Your
code must be able to handle this scenario.
APSC 177
Assignment 7
2
Before you submit your program, make sure you test
it
with a variety of different
texts
.
The following
are
example
s
of c
orrect execution of the program.
Explanation / Answer
#include<iostream>
#include<string>
using namespace std;
int main(){
string input;
getline(cin,input);
int vowels = 0;
int consonants=0;
int uppercase = 0;
int lowercase = 0;
int words = 0;
int punctuation = 0;
int n = input.length();
for(int i=0;i<n;i++){
char ch = input.at(i);
if(ch!=',' && ch!='.' && ch!=';' && ch!=':' && ch!=' '){
if(ch<=96){
uppercase++;
}
else{
lowercase++;
}
ch = tolower(ch);
//cout<<ch<<endl;
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' ||ch =='u'){
vowels++;
}
else{
consonants++;
}
}
else{
if(ch!=' '){
punctuation++;
}
}
}
for(int i=0;i<n;i++){
if(input.at(i)==' '){
words++;
while(input.at(i)==' '){
i++;
}
}
}
words++;
cout<<"Number of Uppercase is "<<uppercase<<endl;
cout<<"Number of Lowercase is "<<lowercase<<endl;
cout<<"Number of consonants is "<<consonants<<endl;
cout<<"Number of punctuation is "<<punctuation<<endl;
cout<<"Number of vowels is "<<vowels<<endl;
cout<<"Number of word is "<<words<<endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.