1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Doss [256]
3 years ago
14

Hardcode the algorithms using if/else and loops not library calls. Write a program that allows the user to input a string and pr

ints the number of vowels, consonants, numerical values 0-9, special symbols in the word. For this exercise assume ‘a’, ‘e’, ‘i’, ‘o’, ‘u’, and ‘y’ are vowels. Make sure to include capitol vowels. Special symbols → [email protected]#$%^&*()_-=+?/" :;<> Please write a short paragraph, bullet points, or psuedocode describing your algorithm for solving the problem. For user input "Harry", the program should print 2 vowels and 3 consonants. For user input "Harry", the program should print "9&&qT" 2 consonants 2 Special Characters 1 numeric value]
Computers and Technology
1 answer:
Brums [2.3K]3 years ago
8 0

Answer:

#include <iostream>

#include <string>

using namespace std;

int

stringLength (string str)

{

 int i = 0;

 int count = 0;

 while (0 == 0)

   {

     if (str[i])

{

  i++;

  count++;

}

     else

{

  break;

}

   }

 return count;

}

int

main ()

{

 string userinput;

 cout << "Enter string ";

 getline (cin, userinput);

 int string_length = stringLength (userinput);

 int vowels=0;int numeric=0;int consonants=0;int special = 0;

 for (int i = 0; i < string_length; i++)

   {

     if (userinput[i] == 'a' ||

  userinput[i] == 'e' ||

  userinput[i] == 'i' ||

  userinput[i] == 'o' ||

  userinput[i] == 'u' ||

  userinput[i] == 'y' ||

  userinput[i] == 'A' ||

  userinput[i] == 'E' ||

  userinput[i] == 'I' ||

  userinput[i] == 'O' || userinput[i] == 'U' || userinput[i] == 'Y')

{

  vowels++;

}

    else if (userinput[i] - 48 > 0 && userinput[i] - 48 <= 9)

{

  numeric++;

}

     else if (userinput[i] == '~' ||

  userinput[i] == '!' ||

  userinput[i] == '@' ||

  userinput[i] == '#' ||

  userinput[i] == '$' ||

  userinput[i] == '%' ||

  userinput[i] == '^' ||

  userinput[i] == '&' ||

  userinput[i] == '*' ||

  userinput[i] == '(' ||

  userinput[i] == ')' ||

  userinput[i] == '_' ||

  userinput[i] == '+' ||

  userinput[i] == '-' ||

  userinput[i] == '+' ||

  userinput[i] == ':' ||

  userinput[i] == ':' ||

  userinput[i] == '?' ||

  userinput[i] == '/' || userinput[i] == '<' || userinput[i] == '>')

{

  special++;

}

     else

{

  consonants++;

}

}

cout << vowels << " vowels and " << consonants << " consonants and " << special

 << " special characters and " << numeric << " numbers." << endl;

return 0;

}

Explanation:

  • Create a string.
  • Take input from user using getline.
  • Write a function to find string length. Iterate through string index in an infinite while loop, check if index is true increase counter and index by 1, if its false break loop and return count.
  • Loop through string using for loop and terminating conditions at index<string length.
  • Create variable vowel,numeric,special,consonant and initialize with 0;
  • For vowels add If statement with condition string[index]=="vowel" for all vowel using OR operator (||).If true increase vowel by 1.
  • For special character add If statement with condition string[index]=="character " for all characters using OR operator (||).If true increase special by 1.
  • For numeric add If statement with condition string[index]-48>0&& string[index]-48<=9 .If true increase vowel by 1.
  • Else increase consonant by 1.
  • Print all variable.
You might be interested in
There is a simple method for constructing a magic square for any odd value of n:
DaniilM [7]

Answer:

See Explaination

Explanation:

class MagicSquare():

def __init__(self,side):

self.side=side

self.two_dimension=[]

for row in range(1,side+1):

row_line=[]

for col in range(1,side+1):

row_line.append(0)

self.two_dimension.append(row_line)

def display(self):

row=0

col=int((self.side-1)/2)

for i in range(1,self.side**2+1):

self.two_dimension[row][col]=i

row-=1

col+=1

if row==-1:

row=self.side-1

if col==self.side:

col=0

if self.two_dimension[row][col]==0:

continue

else:

row+=1

if row==self.side:

row==0

for line in self.two_dimension:

for num in line:

print("{0:>3}".format(num),end=" ")

print()

def main():

for i in range(1,14,2):

square=MagicSquare(i)

square.display()

print("----------------------------------------------------")

if __name__ == '__main__':

main()

3 0
4 years ago
What does it mean if you tell a judge you are “taking the fifth”?
ziro4ka [17]
The fifth amendment states that “no person shall be compelled in any criminal case to be a witness against himself.”
5 0
4 years ago
What word is used today to refer to network-connected hardware devices?.
lions [1.4K]
Th answer to your question is Endpoint
5 0
2 years ago
How do you get a code in C to count down from 5??
Valentin [98]

Answer:

This is what the code should do:

“Lift off in T minus

5

4

3

2

1

Blast-off!”

When I run it, it just keeps printing ''Sum = 5'' forever.

Explanation:

Code:

int main(void) {

int sum = 5;  

int i;      

printf("Lift off in T minus\n");

for (i = 0; i < 5; i=i+i) {

   sum = sum - i;  

   printf("sum = %d\n",sum);  

}  

printf("Blast-off",sum);  

return 0;

5 0
4 years ago
Why students might want headsets for their computers?
VARVARA [1.3K]
It can be noisy and distracting to students to listen to audio speakers when there are multiple computers in the classroom. Headphones help the students
3 0
4 years ago
Other questions:
  • Your crt monitor flickers. what should you do
    6·1 answer
  • Explain the steps you take to complete an Internet search. Do you use a particular search engine every time or do you alternate?
    12·1 answer
  • one business rule is that each project has one manager. Identify two (and no more than two) problems with the data structure or
    9·1 answer
  • What will the scope of a compliance program depend on?
    6·1 answer
  • Can I have help on this
    7·2 answers
  • How are computers located on a network
    5·1 answer
  • C++
    11·2 answers
  • Answer is B because portrait is define that they take only photographs of people and like to communicate with people they are we
    10·1 answer
  • Could u help me on this u just have to compare how its alike please help ​
    5·2 answers
  • What are the similarities and differences in Yahoo International<br> Versions?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!