-
Notifications
You must be signed in to change notification settings - Fork 1
/
Lab_01.cpp
41 lines (30 loc) · 883 Bytes
/
Lab_01.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
void printString(string name)
{
cout << name << endl;
}
bool compareString(string s1, string s2)
{
return s1 < s2;
}
int main()
{
vector<string> dictAnimals {"cat", "dog", "horse", "fish", "bird", "turtle"};
//Print names of animals
for_each(dictAnimals.begin(), dictAnimals.end(), printString);
//Sort vector
sort(dictAnimals.begin(), dictAnimals.end(), compareString);
//Print names of animals
for_each(dictAnimals.begin(), dictAnimals.end(), printString);
cout << "Enter name of the animal you search for" << endl;
string animal;
cin >> animal;
//Find animal by name using find_if()
int nbLetters = 0;
//Sum of words lengths in nbLetters using for_each()
cout << "Sum of words lengths = "<< nbLetters << endl;
return 0;
}