Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- int licz_samogloski(string tekst);
- int licz_spolgloski(string tekst);
- int licz_cyfry(string tekst);
- int licz_znaki(string tekst);
- int main(){
- char wybor;
- do
- {
- system("cls");
- cout << "\n\n\n\n";
- cout << " ***** LICZNIK SAMOGLOSEK, SPOLGLOSEK, CYFR I INNYCH ZNAKOW ***** \n\n";
- cout << " 1 - policz samogloski"<<endl;
- cout << " 2 - policz spolgloski"<<endl;
- cout << " 3 - policz cyfry"<<endl;
- cout << " 4 - policz inne znaki"<<endl;
- cout << " 5 - KONIEC "<<endl;
- cout << "\n";
- cout << " Wybierz cyfre od 1 do 5: ";
- do {
- cin >> wybor;
- if (wybor < '1' || wybor > '5')
- cout << "Wybór nieprawidłowy... Wybierz liczbe [1-5]: ";
- }
- while(wybor<'1' || wybor > '5');
- string tekst;
- int wynik;
- switch(wybor)
- {
- case '1':
- cout << "Podaj ciag znakow: ";
- getline(cin, tekst);
- cout << "Liczb samoglosek w wyrazeniu \"" << tekst << "\" wynosi " << licz_samogloski(tekst)<<endl;
- system ("pause");
- break;
- case '2':
- cout << "Podaj ciag znakow: ";
- cin >> tekst;
- cout << "Liczb spolglosek w wyrazeniu \"" << tekst << "\" wynosi " << licz_spolgloski(tekst)<<endl;
- system ("pause");
- break;
- case '3':
- cout << "Podaj ciag znakow: ";
- cin >> tekst;
- cout << "Liczb cyfr w wyrazeniu \"" << tekst << "\" wynosi " << licz_cyfry(tekst)<<endl;
- system ("pause");
- break;
- case '4':
- cout << "Podaj ciag znakow: ";
- cin >> tekst;
- cout << "Liczb innych znakow w wyrazeniu \"" << tekst << "\" wynosi " << licz_znaki(tekst)<<endl;
- system ("pause");
- break;
- }
- }
- while (wybor != '5');
- }
- int licz_samogloski(string a)
- {
- int wynik=0;
- int dlugosc;
- dlugosc = a.length();
- for (int i = 0;i < dlugosc;i++)
- a[i] = toupper(a[i]);
- for (int i = 0;i < dlugosc;i++)
- {
- 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')
- wynik++;
- }
- return wynik;
- }
- int licz_spolgloski(string a)
- {
- int wynik=0;
- int dlugosc;
- dlugosc = a.length();
- for (int i = 0;i < dlugosc;i++)
- a[i] = toupper(a[i]);
- for (int i = 0;i < dlugosc;i++)
- {
- if ( a[i] == 'A' )
- wynik++;
- }
- return wynik;
- }
- int licz_cyfry(string a)
- {
- int wynik=0;
- int dlugosc;
- dlugosc = a.length();
- for (int i = 0;i < dlugosc;i++)
- {
- if ( isdigit(a[i]) )
- wynik++;
- }
- return wynik;
- }
- int licz_znaki(string a)
- {
- int wynik=0;
- int dlugosc;
- dlugosc = a.length();
- for (int i = 0;i < dlugosc;i++)
- a[i] = toupper(a[i]);
- for (int i = 0;i < dlugosc;i++)
- {
- if ( a[i] == 'A' )
- wynik++;
- }
- return wynik;
- }
Advertisement
Add Comment
Please, Sign In to add comment