class FindVowelWords{ vector<string> input; // тут будут лежать слова для обработки vector<string> output; // тут будут лежать обработанные слова vector<char> vowels; // а тут глассные буквы
public: // ... FindVowelWords(const string& inputStr){ vowels = {'a', 'A', 'o', 'O', 'i', 'I', 'u', 'U', 'e', 'E'}; // определяем вектор с гласнымы boost::split(input, inputStr, [](char c){return c == ' ';}); // разбиваем воходную строку на слова }
// поиск слов, которые начинаются с гласных void handle(){ for(auto const& word : input){ // проходимся по всем словам for(auto const& vowel : vowels){ // проходимся по всем гласным if(word.at(0) == vowel){ output.push_back(word); // если первая буква слова - гласная, то заносим слово в результирующий вектор } } } }
int main(){ string test = "Don't be arfraid, just try to understand this code and you'll be a good programmer!"; FindVowelWords findIt(test); cout << "You have entered this string: " << endl; findIt.printInput(); cout << endl << endl;
findIt.handle(); cout << "Words that begin with a vowel: " << endl; findIt.printOutput(); cout << endl; cout << "number of words have been found: " << findIt.getOutputSize() << endl; return 0; }
Using System; namespace Test{ class Program { static double F(double x) { return Math.Sin(x); } static double NewtonCotesOpen4(double a, double b) { const int n = 4; double[] c = {2.0, -1.0, 2.0 }; const double K = 3.0; double h = (b - a) / n; double res = 0; double x; for(int i = 1; i <= n - 1; i++) { x = a + i * h; res += c[i - 1] * F(x); } return res * (b - a) / K; } static double SumSubIntervals(double a, double b, int n) { double res = 0; double h = (b - a) / n; for(int i = 1; i <= n; i++) { res += NewtonCotesOpen4(a + (i - 1) * h, a + i * h); } return res; } static void Main(string[] args) { double a = 0; double b = Math.PI; double EPS = 0.00001; int n = 1; double lcur = SumSubIntervals(a, b, n); double lpre; do { lpre = lcur; n *= 2; lcur = SumSubIntervals(a, b, n); Console.WriteLine("l={0} при n={1} e={2}", Math.Round(lcur, 8), n, Math.Round(Math.Abs(lcur - lpre), 8)); } while (Math.Abs(lcur - lpre) < EPS); Console.WriteLine(""); Console.WriteLine("l={0} при n={1} e={2}", Math.Round(lcur, 8), n, Math.Round(Math.Abs(lcur - lpre), 8)); } }}
0,0(0 оценок)
Полный доступ
Позволит учиться лучше и быстрее. Неограниченный доступ к базе и ответам от экспертов и ai-bota
Оформи подписку