Advertisement
Emanuele_Bruno

Esercizio 2

Nov 30th, 2015
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. void asterischi (string a[],int l)
  8. {
  9.     int i=0,j=0,m=0,k;
  10.     while (i<l)
  11.     {
  12.         if ((a[i].length())>5)
  13.         {
  14.             m+=a[i].length();
  15.             j++;
  16.         }
  17.         i++;
  18.     }
  19.     j=m/j;
  20.  
  21.     cout << "Valore di m: " << m << endl;
  22.     cout << "il valore medio e' :" << j << endl;
  23.  
  24.     string b[j];
  25.     i=0;
  26.  
  27.     string j_asterischi;
  28.     while (i<j)
  29.     {
  30.         j_asterischi+=char('*');
  31.         i++;
  32.     }
  33.  
  34.     cout << "questo e' j_asterischi :" << j_asterischi<< "\n";
  35.  
  36.     i=0;
  37.     while (i<j)
  38.     {
  39.         if (i==0)
  40.             b[i]="";
  41.         else
  42.         {
  43.             k=0;
  44.             while (k<i)
  45.             {
  46.                 b[i]+=j_asterischi;
  47.                 k++;
  48.             }
  49.         }
  50.         i++;
  51.     }
  52.  
  53.     i=0;
  54.     while (i<j)
  55.     {
  56.         cout << "b[" << i << "]=" << b[i] << endl;
  57.         i++;
  58.     }
  59. }
  60.  
  61. int main()
  62. {
  63.     int h,i=0,j,k; // i variaibile contatore, j-> lunghezza a, k-> lunghezza b
  64.     cout << "Inserire la grandezza dell'array A: ";
  65.     cin >> j;
  66.     string a[j];
  67.     while (i<j)
  68.     {
  69.         h=0;
  70.         while (h<=rand()%10+1)
  71.         {
  72.             a[i]+=rand()%26+int(char('a'));
  73.             h++;
  74.         }
  75.         cout << a[i] << endl;
  76.         i++;
  77.     }
  78.     asterischi (a,j);
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement