Answer to Question #175104 in C++ for meng

Question #175104

Based on the English alphabet, it includes just 128 basic characters: numbers 0 to 9, lowercase letters a to z, uppercase letters A to Z, basic punctuation symbols, the space character, and a few other non-printing characters.Here are all the printable ASCII characters—including a space—enclosed in single quotes.


‘ !”#$%&\’( )*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[ \ \ ]^_’abcdefghijklmnopqrstuvwxyz{ | }~’


Using the string above, write a program that prompts a user to enter a text. Compare this text to the ASCII string and print out the following information.

 

(Here is a sample running of the program:)

 

Enter a text to analyze: Let’s go to the cafe’ on Sullivan St.

The total number of characters (including spaces) in the text : 36

The total number of ASCII characters in the text : 34

The total number of non-ASCII characters in the text : 2


1
Expert's answer
2021-03-24T17:11:46-0400
#include<iostream>
#include <string>
using namespace std;

int main(){
    string string1= "//'!#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
    int char_count = 0;
    int white_space_count = 0;
    int ascii_count = 0;
    int non_ascii_count = 0;
    int non_ascii_chars_count=0;// =[];
    string text;
    cout<<"Please enter the the statement"<<endl;
    cin>>text;

    for(int i=0;i<=text.length();i++){
        if(string1.find(text)){
        char_count += 1;
        if (string1.find(text))
            white_space_count += 1;
        if (string1.find(text))
            ascii_count += 1;
        else
            //non_ascii_chars.join(text);
            non_ascii_count += 1;
        }
    }
cout<<"test"<<string1<<endl;


    cout<<"Total number of characters: "<<char_count<<endl;
    cout<<"Total number of white spaces: "<<white_space_count<<endl;
    cout<<"Total number of ASCII characters: "<<ascii_count<<endl;
    cout<<"Total number of non-ASCII characters:"<<non_ascii_count<<endl;
    cout<<"The non-ASCII letters were: "<<endl;



return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS