Sclafus

Contatore lettere da file

Dec 6th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. int main(){
  6.     int contatore_a = 0;
  7.     int contatore_b = 0;
  8.     int contatore_c = 0;
  9.     int contatore_d = 0;
  10.     int contatore_e = 0;
  11.     int contatore_f = 0;
  12.     int contatore_g = 0;
  13.     int contatore_h = 0;
  14.     int contatore_i = 0;
  15.     int contatore_j = 0;
  16.     int contatore_k = 0;
  17.     int contatore_l = 0;
  18.     int contatore_m = 0;
  19.     int contatore_n = 0;
  20.     int contatore_o = 0;
  21.     int contatore_p = 0;
  22.     int contatore_q = 0;
  23.     int contatore_r = 0;
  24.     int contatore_s = 0;
  25.     int contatore_t = 0;
  26.     int contatore_u = 0;
  27.     int contatore_v = 0;
  28.     int contatore_w = 0;
  29.     int contatore_x = 0;
  30.     int contatore_y = 0;
  31.     int contatore_z = 0;
  32.     int lunghezza_file = 0;
  33.     int contatore_simboli = 0;
  34.     ifstream file1{"input_10.3.txt"};
  35.     for (string line; getline(file1, line);){
  36.         lunghezza_file += sizeof(line);
  37.         for(int i = 0; i < line.size(); i++){
  38.  
  39.  
  40.             if (line[i] == 'a' || line[i] == 'A'){
  41.                 contatore_a++;
  42.             }
  43.             if (line[i] == 'b' || line[i] == 'B'){
  44.                 contatore_b++;
  45.             }
  46.             if (line[i] == 'c' || line[i] == 'C'){
  47.                 contatore_c++;
  48.             }
  49.             if (line[i] == 'd' || line[i] == 'D'){
  50.                 contatore_d++;
  51.             }
  52.             if (line[i] == 'e' || line[i] == 'E'){
  53.                 contatore_e++;
  54.             }
  55.             if (line[i] == 'f' || line[i] == 'F'){
  56.                 contatore_f++;
  57.             }
  58.             if (line[i] == 'g' || line[i] == 'G'){
  59.                 contatore_g++;
  60.             }
  61.             if (line[i] == 'h' || line[i] == 'H'){
  62.                 contatore_h++;
  63.             }
  64.             if (line[i] == 'i' || line[i] == 'I'){
  65.                 contatore_i++;
  66.             }
  67.             if (line[i] == 'l' || line[i] == 'L'){
  68.                 contatore_l++;
  69.             }
  70.             if (line[i] == 'm' || line[i] == 'M'){
  71.                 contatore_m++;
  72.             }
  73.             if (line[i] == 'n' || line[i] == 'N'){
  74.                 contatore_n++;
  75.             }
  76.             if (line[i] == 'o' || line[i] == 'O'){
  77.                 contatore_o++;
  78.             }
  79.             if (line[i] == 'p' || line[i] == 'P'){
  80.                 contatore_p++;
  81.             }
  82.             if (line[i] == 'q' || line[i] == 'Q'){
  83.                 contatore_q++;
  84.             }
  85.             if (line[i] == 'r' || line[i] == 'R'){
  86.                 contatore_r++;
  87.             }
  88.             if (line[i] == 's' || line[i] == 'S'){
  89.                 contatore_s++;
  90.             }
  91.             if (line[i] == 't' || line[i] == 'T'){
  92.                 contatore_t++;
  93.             }
  94.             if (line[i] == 'u' || line[i] == 'U'){
  95.                 contatore_u++;
  96.             }
  97.             if (line[i] == 'v' || line[i] == 'V'){
  98.                 contatore_v++;
  99.             }
  100.             if (line[i] == 'w' || line[i] == 'W'){
  101.                 contatore_w++;
  102.             }
  103.             if (line[i] == 'x' || line[i] == 'X'){
  104.                 contatore_x++;
  105.             }
  106.             if (line[i] == 'y' || line[i] == 'Y'){
  107.                 contatore_y++;
  108.             }
  109.             if (line[i] == 'z' || line[i] == 'Z'){
  110.                 contatore_z++;
  111.             } else{
  112.                 contatore_simboli++;
  113.             }
  114.  
  115.         }
  116.     }
  117.  
  118.     cout << "Percentuale a: " << float(contatore_a) / float(lunghezza_file) *100<< " %" <<endl;
  119.     cout << "Percentuale b: " << float(contatore_b) / float(lunghezza_file) *100<< " %" <<endl;
  120.     cout << "Percentuale c: " << float(contatore_c) / float(lunghezza_file) *100<< " %" <<endl;
  121.     cout << "Percentuale d: " << float(contatore_d) / float(lunghezza_file) *100<< " %" <<endl;
  122.     cout << "Percentuale e: " << float(contatore_e) / float(lunghezza_file) *100<< " %" <<endl;
  123.     cout << "Percentuale f: " << float(contatore_f) / float(lunghezza_file) *100<< " %" <<endl;
  124.     cout << "Percentuale g: " << float(contatore_g) / float(lunghezza_file) *100<< " %" <<endl;
  125.     cout << "Percentuale h: " << float(contatore_h) / float(lunghezza_file) *100<< " %" <<endl;
  126.     cout << "Percentuale i: " << float(contatore_i) / float(lunghezza_file) *100<< " %" <<endl;
  127.     cout << "Percentuale j: " << float(contatore_j) / float(lunghezza_file) *100<< " %" <<endl;
  128.     cout << "Percentuale k: " << float(contatore_k) / float(lunghezza_file) *100<< " %" <<endl;
  129.     cout << "Percentuale l: " << float(contatore_l) / float(lunghezza_file) *100<< " %" <<endl;
  130.     cout << "Percentuale m: " << float(contatore_m) / float(lunghezza_file) *100<< " %" <<endl;
  131.     cout << "Percentuale n: " << float(contatore_n) / float(lunghezza_file) *100<< " %" <<endl;
  132.     cout << "Percentuale o: " << float(contatore_o) / float(lunghezza_file) *100<< " %" <<endl;
  133.     cout << "Percentuale p: " << float(contatore_p) / float(lunghezza_file) *100<< " %" <<endl;
  134.     cout << "Percentuale q: " << float(contatore_q) / float(lunghezza_file) *100<< " %" <<endl;
  135.     cout << "Percentuale r: " << float(contatore_r) / float(lunghezza_file) *100<< " %" <<endl;
  136.     cout << "Percentuale s: " << float(contatore_s) / float(lunghezza_file) *100<< " %" <<endl;
  137.     cout << "Percentuale t: " << float(contatore_t) / float(lunghezza_file) *100<< " %" <<endl;
  138.     cout << "Percentuale u: " << float(contatore_u) / float(lunghezza_file) *100<< " %" <<endl;
  139.     cout << "Percentuale v: " << float(contatore_v) / float(lunghezza_file) *100<< " %" <<endl;
  140.     cout << "Percentuale w: " << float(contatore_w) / float(lunghezza_file) *100<< " %" <<endl;
  141.     cout << "Percentuale x: " << float(contatore_x) / float(lunghezza_file) *100<< " %" <<endl;
  142.     cout << "Percentuale y: " << float(contatore_y) / float(lunghezza_file) *100<< " %" <<endl;
  143.     cout << "Percentuale z: " << float(contatore_z) / float(lunghezza_file) *100<< " %" <<endl;
  144.     cout << "Percentuale altri simboli: " << float(contatore_simboli) / float(lunghezza_file) * 100 << " %" << endl;
  145. }
Advertisement
Add Comment
Please, Sign In to add comment