Advertisement
Razorspined

задача ??// врътката със списъци и изваждане на елементи от списъци

Jan 12th, 2023
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. class Person {
  8. public:
  9. string name;
  10. int age;
  11.  
  12. Person() {}
  13.  
  14. Person(string n, int a) {
  15. name = n;
  16. age = a;
  17. }
  18. };
  19.  
  20. class Spisak {
  21. public:
  22. vector<Person> hora = { Person("pesho", 15), Person("gosho", 25), Person("reni", 34) };
  23.  
  24. vector<string> imena() {
  25. vector<string> names;
  26. for (Person p : hora) {
  27. names.push_back(p.name);
  28. }
  29. return names;
  30. }
  31. };
  32.  
  33. int main() {
  34. Spisak sp;
  35.  
  36. for (string i : sp.imena()) {
  37. cout << i << endl;
  38. }
  39. return 0;
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement