Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int uppercase_in_text(string testo) {
- int uppercase_counter = 0;
- for (char carattere_testo : testo){
- if (isupper(carattere_testo)){
- uppercase_counter++;
- }
- }
- return uppercase_counter;
- }
- int main(){
- int sum_uppercase = 0, char_in_file = 0;
- ifstream file1{"input_9.1.txt"};
- for (string line; getline(file1, line);){
- char_in_file += sizeof(line);
- int upper_in_line = uppercase_in_text(line);
- sum_uppercase += upper_in_line;
- cout << "Uppercase percent for this line: " << float(upper_in_line) / sizeof(line) * 100 << "%" << endl;
- }
- cout << "Uppercase percent for the whole text: " << float(sum_uppercase) / char_in_file * 100 << "%" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment