64 712
Assignments Done
99,4%
Successfully Done
In September 2018

Answer to Question #62248 in C++ for Daniel Greef

Question #62248
Could you please make a program for me, using any type of style.

If I input a string, it will count and print all the small letters, capital letters, numerical digits and others (such as !@#).
Expert's answer
#include <iostream>
#include <string>
#include <cctype>

int main()
{
std::string input;

std::cout << "Enter text: ";
std::getline(std::cin, input);

size_t num_uppers = 0, num_lowers = 0, num_digits = 0, num_graphs = 0, num_others = 0;
std::string uppers, lowers, digits, graphs, others;

for (size_t i = 0; i < input.size(); ++i) {
char c = input[i];

if (isupper(c)) {num_uppers++; uppers.push_back(c);}
else if (islower(c)) {num_lowers++; lowers.push_back(c);}
else if (isdigit(c)) {num_digits++; digits.push_back(c);}
else if (isgraph(c)) {num_graphs++; graphs.push_back(c);}
else {num_others++; others.push_back(c);}
}

std::cout << "N, Uppers: " << num_uppers << " - " << uppers << std::endl;
std::cout << "N, Lowers: " << num_lowers << " - " << lowers << std::endl;
std::cout << "N, Digits: " << num_digits << " - " << digits << std::endl;
std::cout << "N, Graphs: " << num_graphs << " - " << graphs << std::endl;
std::cout << "N, Others: " << num_others << " - " << "Oops!" << std::endl;
std::cin.ignore();

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions