Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. /*
  2.  * RicercaInFrase.cpp
  3.  *
  4.  *  Created on: 21 feb 2018
  5.  *      Author: Zarmoletti Vincenzo
  6.  */
  7.  
  8. #include <iostream>
  9. #include <string>
  10.  
  11. using namespace std;
  12.  
  13. void leggiFrase(string& frase)
  14. {
  15.     /*
  16.      * La funzione getline รจ utilizzata al posto dell'oggetto cin
  17.      * nel caso in cui la frase dovesse contenere spazi. (In tal caso, cin fallirebbe)
  18.      * */
  19.  
  20.     getline(cin,frase);
  21. }
  22.  
  23. void leggiAst(char& ast)
  24. {
  25.     cin >> ast;
  26. }
  27.  
  28. unsigned int RicercaInFrase(const string& frase, char daTrovare)
  29. {
  30.     unsigned int occorrenze = 0U;
  31.     for(auto x : frase) //range-for (VALIDO SOLO A PARTIRE DAL C++11)
  32.         if(x == daTrovare)
  33.             occorrenze++;
  34.  
  35.     return occorrenze;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement