Question

Write a C++ console application that reverses an array of characters, and counts the number of:...

Write a C++ console application that reverses an array of characters, and counts the number of:

          Lower case characters (islower)

          Upper case characters (isupper)

          Digits (isdigit)

          Other (not one of previous)

Create four global variables to hold these counts. Create function void count(char input[], char reverse[]) that takes as input two arrays: one that contains characters and another that will contain the reverse of that array. The function will reverse the input array and do the counts. In the main function, prompt for and get from the user a string and store it in the input array. You can assume the length of the array is less than 50. Function cin.getline can read characters into a char array. Call function count and then print the resulting counts.

Example input: AaBbCc123!@#

Output:

          Lowercase: 3

          Uppercase: 3

          Digits: 3

          Other: 3

Reversed array: #@!321cCbBaA

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
using namespace std;
int lowercase=0,upper=0,digits=0,others=0;

void count(char input[], char rev[]){
int length=0;
for(int i=0;input[i]!='\0';i++){
length++;
if(isupper(input[i]))
upper++;
else if(islower(input[i]))
lowercase++;
else if(isdigit(input[i]))
digits++;
else
others++;
}
int i,j;
for(i=0,j=length-1;i<length;i++,j--)
rev[i]=input[j];
rev[i]='\0';
}
int main()
{
char str[50],rev[50];
cout<<"Enter string : ";
cin.getline(str, 50);
count(str,rev);
cout<<"Lowercase: "<<lowercase<<endl;
cout<<"Uppercase: "<<upper<<endl;
cout<<"Digits : "<<digits<<endl;
cout<<"Other: "<<others<<endl;
cout<<"Reversed array: "<<rev<<endl;
return 0;
}

9 #include iostream» 10 using namespace std; 11 int lowercase-0, upper-0,digits-0,others-0; 12 13 void count (char input[], c

Add a comment
Know the answer?
Add Answer to:
Write a C++ console application that reverses an array of characters, and counts the number of:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help with this exercise. Than you for the help. Language is C++ 2 Enumeration...

    I need help with this exercise. Than you for the help. Language is C++ 2 Enumeration Data Types Reformat is the shell of a program designed to read characters and process them in the following way Lowercase character Uppercase character Digit Blank Newline Any other character Converts to uppercase and writes the character Writes the character Writes the digit Writes a blank Writes newline Does nothing / Program Reformat reads characters from file DataIn and // writes them to DataOut...

  • I need eclipse code for : Write a program that analyzes text written in the console...

    I need eclipse code for : Write a program that analyzes text written in the console by counting the number of times each of the 26 letters in the alphabet occurs. Uppercase and lowercase letters should be counted together (for example, both ‘A’ and ‘a’ should count as an A). Any characters that are not letters should be ignored. You must prompt the user to enter the text to be analyzed. Then, for any letter that appeared at least once...

  • u also need to store the letters' ASCII number in the freq array 4. [8] Write...

    u also need to store the letters' ASCII number in the freq array 4. [8] Write a C function with prototype · void letter_freq(const char word[], int freq []); This function computes the number of appearances of each letter in the string word and stores them in array freq of size 26. The letters are the 26 letters of the Latin alphabet whose ASCII values are in the range 97-122 for the lower case letters, and in the range 65-90...

  • You're to write a C++ program that analyzes the contents of an external file called data.txt....

    You're to write a C++ program that analyzes the contents of an external file called data.txt. (You can create this file yourself using nano, that produces a simple ASCII text file.) The program you write will open data.txt, look at its contents and determine the number of uppercase, lowercase, digit, punctuation and whitespace characters contained in the file so that the caller can report the results to stdout. Additionally, the function will return the total number of characters read to...

  • ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels...

    ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels in the string B) Count the number of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current string X) Exit the program The program should start with a user prompt to enter a string, and let them type it in. Then the menu would be displayed. User may enter option in small case...

  • In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

  • This is for C++ Write a program that reads in a sequence of characters entered by...

    This is for C++ Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along with the number of times it occured. All non-alphabetic characters must...

  • 4. [8] Write a C function with prototype void letter_freq(const char wordll, int freaq ); This...

    4. [8] Write a C function with prototype void letter_freq(const char wordll, int freaq ); This function computes the number of appearances of each letter in the string word and stores them irn array freq of size 26. The letters are the 26 letters of the Latin alphabet whose ASCII values are in the range 97-122 for the lower case letters, and in the range 65-90 for the uppercase letters. You must account for uppercase and lowercase letter variants, which...

  • Please make this Python code execute properly. User needs to create a password with at least...

    Please make this Python code execute properly. User needs to create a password with at least one digit, one uppercase, one lowercase, one symbol (see code), and the password has to be atleast 8 characters long. try1me is the example I used, but I couldn't get the program to execute properly. PLEASE INDENT PROPERLY. def policy(password): digit = 0 upper = 0 lower = 0 symbol = 0 length = 0 for i in range(0, len(password)): if password[i].isdigit(): # checks...

  • My C++ program is not compiling. Please explain how you fixed with detailed inline comments. I am using Visual Studio 2017. It's a character count program that keeps and displays a count of all th...

    My C++ program is not compiling. Please explain how you fixed with detailed inline comments. I am using Visual Studio 2017. It's a character count program that keeps and displays a count of all the upper, lower case and digits in a .txt file. The requirement is to use classes to implement it. -----------------------------------------------------------------HEADER FILE - Text.h--------------------------------------------------------------------------------------------- /* Header file contains only the class declarations and method prototypes. Comple class definitions will be in the class file.*/ #ifndef TEXT_H #define...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT