Write a C++ program that reads characters (Upper case, Lower case, and Digits ) including white spaces from the keyboard until user enters ‘#’. Then, your program should count total number of characters, uppercase letters, lowercase letters, and digits. Example of a possible input: Hello, welcome to Tempe. Today’s temperature is 117!# Approach: • First write the algorithm • Come up with a flowchart that represents the program logic. • verify your approach with sample data set • Develop the program and test it for various inputs Hint: You will need to use selection within the while loop. library has character related functions (Appendix G2,3,4 - CD). Will be discussed during the lab. Also, string data type has a method length() which gives how many characters are stored in the string.Write a program that reads characters (Upper case, Lower case, and Digits ) including white spaces from the keyboard until user enters ‘#’. Then, your program should count total number of characters, uppercase letters, lowercase letters, and digits.Example of a possible input:Hello, welcome to Tempe. Today’s temperature is 117!#Approach:First write the algorithmCome up with a flowchart that represents the program logic.verify your approach with sample data setDevelop the program and test it for various inputsHint:You will need to use selection within the while loop. library has character related functions (Appendix G2,3,4 - CD). Will be discussed during the lab. Also, string data type has a method length() which gives how many characters are stored in the string.

Respuesta :

tanoli

Answer:

Below is the c++ program with detail explanation on each line

Explanation:

// C++ program to demonstrate  

// accessing of data members  

 

#include <bits/stdc++.h>  

#include <conio.h>

using namespace std;  

 

int main() {  

//Declaring variable for every type that we need to check

 int totalUpperCase=0;

 int totalLowerCase=0;

 int totalWhiteSpaces=0;

 int totalDigits=0;

 //define x variable which will hold character input from user

 char x;

   

 while(x != '#'){ //execute until # character entered by user

 x=getche(); //as we want from user to enter as many character as

 //user wants without pressing enter key, that's why we use getche() which means

 //get one character.

 //isaplha method is used to check whether character is alphabet or not

    if(isalpha(x)){  

 //isupper will check if entered character is upper case or not

      if (isupper(x))  

         totalUpperCase++;

     else  

         totalLowerCase++;  

//isdigit method is used to check number

 } else if(isdigit(x)){

  totalDigits++;

 } else if(x == ' '){

  totalWhiteSpaces++;

 }

     

   }

   //printing all the values here

   cout<<"\n"<<"Total Upper Case Letters :" << totalUpperCase<<"\n";  

cout<<"Total Lower Case Letters :"<<totalLowerCase<<"\n";  

cout <<"Total White Spaces :"<< totalWhiteSpaces<<"\n";

cout << "Total Digits" <<totalDigits<<"\n";

// getche() at the end so that our programs wait until user presses any key

getche();

   return 0;  

}