Guest User

Untitled

a guest
Mar 16th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int licz_samogloski(string tekst);
  6. int licz_spolgloski(string tekst);
  7. int licz_cyfry(string tekst);
  8. int licz_znaki(string tekst);
  9.  
  10. int main(){
  11.     char wybor;
  12.    do
  13.     {
  14.     system("cls");
  15.     cout << "\n\n\n\n";
  16.     cout << "                ***** LICZNIK SAMOGLOSEK, SPOLGLOSEK, CYFR I INNYCH ZNAKOW ***** \n\n";
  17.     cout << "          1 - policz samogloski"<<endl;
  18.     cout << "          2 - policz spolgloski"<<endl;
  19.     cout << "          3 - policz cyfry"<<endl;
  20.     cout << "          4 - policz inne znaki"<<endl;
  21.     cout << "          5 - KONIEC "<<endl;
  22.    
  23.     cout << "\n";
  24.     cout << "           Wybierz cyfre od 1 do 5: ";
  25.    
  26.     do {
  27.         cin >> wybor;
  28.         if (wybor < '1' || wybor > '5')
  29.            cout << "Wybór nieprawidłowy... Wybierz liczbe [1-5]: ";
  30.         }
  31.     while(wybor<'1' || wybor > '5');
  32.    
  33.     string tekst;
  34.     int wynik;
  35.  
  36.     switch(wybor)
  37.     {
  38.       case '1':
  39.           cout << "Podaj ciag znakow: ";
  40.           getline(cin, tekst);
  41.           cout << "Liczb samoglosek w wyrazeniu \"" << tekst << "\" wynosi " << licz_samogloski(tekst)<<endl;
  42.           system ("pause");
  43.           break;
  44.       case '2':
  45.           cout << "Podaj ciag znakow: ";
  46.           cin >> tekst;  
  47.           cout << "Liczb spolglosek w wyrazeniu \"" << tekst << "\" wynosi " << licz_spolgloski(tekst)<<endl;
  48.            system ("pause");    
  49.            break;
  50.       case '3':
  51.           cout << "Podaj ciag znakow: ";
  52.           cin >> tekst;  
  53.           cout << "Liczb cyfr w wyrazeniu \"" << tekst << "\" wynosi " << licz_cyfry(tekst)<<endl;
  54.            system ("pause");        
  55.            break;
  56.       case '4':
  57.            cout << "Podaj ciag znakow: ";
  58.            cin >> tekst;  
  59.            cout << "Liczb innych znakow w wyrazeniu \"" << tekst << "\" wynosi " << licz_znaki(tekst)<<endl;
  60.            system ("pause");
  61.            break;          
  62.     }
  63.                    
  64. }
  65.    while (wybor != '5');
  66. }
  67. int licz_samogloski(string a)
  68. {
  69.      int wynik=0;
  70.      int dlugosc;
  71.      dlugosc = a.length();
  72.      for (int i = 0;i < dlugosc;i++)
  73.         a[i] = toupper(a[i]);
  74.      for (int i = 0;i < dlugosc;i++)
  75.      {
  76.         if ( a[i] == 'A' ||  a[i] == 'Ą' ||  a[i] == 'E' ||  a[i] == 'Ę' ||  a[i] == 'I' ||  a[i] == 'O' ||  a[i] == 'Ó' ||  a[i] == 'U' ||  a[i] == 'Y')
  77.             wynik++;
  78.      }    
  79.      return wynik;
  80.    
  81. }
  82.  
  83. int licz_spolgloski(string a)
  84. {
  85.      int wynik=0;
  86.      int dlugosc;
  87.      dlugosc = a.length();
  88.      for (int i = 0;i < dlugosc;i++)
  89.         a[i] = toupper(a[i]);
  90.      for (int i = 0;i < dlugosc;i++)
  91.      {
  92.         if ( a[i] == 'A' )
  93.             wynik++;
  94.      }    
  95.      return wynik;
  96.    
  97. }
  98.  
  99. int licz_cyfry(string a)
  100. {
  101.      int wynik=0;
  102.      int dlugosc;
  103.      dlugosc = a.length();
  104.  
  105.      for (int i = 0;i < dlugosc;i++)
  106.      {
  107.         if ( isdigit(a[i]) )
  108.             wynik++;
  109.      }    
  110.      return wynik;
  111.    
  112. }
  113.  
  114. int licz_znaki(string a)
  115. {
  116.      int wynik=0;
  117.      int dlugosc;
  118.      dlugosc = a.length();
  119.      for (int i = 0;i < dlugosc;i++)
  120.         a[i] = toupper(a[i]);
  121.      for (int i = 0;i < dlugosc;i++)
  122.      {
  123.         if ( a[i] == 'A' )
  124.             wynik++;
  125.      }    
  126.      return wynik;
  127.    
  128. }
Advertisement
Add Comment
Please, Sign In to add comment