Kagalive

COLLECTIONS-V-9FINAL

Sep 30th, 2020 (edited)
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. //https://app.pluralsight.com/course-player?clipId=9591b217-52b1-41d4-97d8-498731301073
  2. //https://bit.ly/freePS2020
  3.  
  4. //RECOMMENDED: VS2019 COMMUNITY [FREE IDE] @ https://bit.ly/3mYgad3
  5.  
  6.  
  7. //Different ways to utilize collections, specifically VECTOR
  8.  
  9. //includes.h
  10.  
  11.  
  12. #include <iostream>
  13. using std::cout;
  14. using std::cin;
  15.  
  16. #include <string>
  17. using std::string;
  18.  
  19. #include <vector>
  20. using std::vector;
  21. using std::begin;
  22. using std::count;
  23.  
  24. #include <algorithm>
  25. using std::sort;
  26. using std::count;
  27.  
  28.  
  29.  
  30. //collections.cpp
  31.  
  32. #include "includes.h"
  33.  
  34. int main()
  35. {
  36.  
  37.     vector<int> nums;
  38.        
  39.     for (int i = 0; i < 10; i++)
  40.     {
  41.         nums.push_back(i);
  42.     }
  43.  
  44.     for (auto item : nums)
  45.     {
  46.         cout << item << " ";
  47.     }
  48.     cout << "\n";
  49.  
  50.     vector<string> words;
  51.  
  52.     cout << "Enter Three Words: "
  53.     for (int i = 0; i < 3; i++)
  54.     {
  55.     string s;
  56.     cin >> s;
  57.     words.push_back(s);
  58.     }
  59.  
  60.  
  61.     for (auto item: words)
  62.     {
  63.     cout << item << " ";
  64.     }
  65.     cout << "\n";
  66.  
  67.     cout << "int vector nums has " << nums.size() << " elements." << '\n\;
  68.  
  69.    nums[5] = 3;
  70.    nums[6] = -1;
  71.    nums[1] = 99;
  72.  
  73.    for (auto item: nums)
  74.    {
  75.    cout << item << " ";
  76.    }
  77.    cout << '\n';
  78.  
  79.    for (unsigned int i = 0; i < nums.size(); i++)
  80.    {
  81.    cout << nums[i] << " ";
  82.    }
  83.    cout << "\n";
  84.  
  85.   for (auto i = begin(nums); i != end(nums); i++)
  86.   {
  87.     cout << *i << " ";
  88.   }
  89.   cout << '\n';
  90.  
  91.   sort(begin(words), end(words));
  92.   for (auto item : words)
  93.   {
  94.     cout << item << " ";
  95.   }
  96.   cout << '\n';
  97.  
  98.  
  99.  int threes = count(begin(nums), end(nums), 3);
  100.  cout << "Vector of ints has " << threes << " elements with value 3" << '\n';
  101.  
  102.  int tees = count(begin(words[0]), end(words[0]), 't');
  103.  cout << "first word has " << tees << " letter t's" << "\n";
  104.  
  105.  return 0;
  106.  
  107.  
  108.  
  109.  
  110. }
Add Comment
Please, Sign In to add comment