Advertisement
Kagalive

main.cpp

Sep 30th, 2020
889
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.22 KB | None | 0 0
  1.  
  2. #include "includes.h"
  3.  
  4. using namespace std;
  5. int main()
  6. {
  7.  
  8.     //double result = add2(3, 3);
  9.  
  10.     //cout << result;
  11.  
  12.  
  13.     /*
  14.     string name;
  15.     cout << "Enter your name: ";
  16.     cin >> name;
  17.     string greeting = "Hello, " + name;
  18.  
  19.     if (name == "Rick")
  20.     {
  21.         greeting += ", It's me!";
  22.     }
  23.     cout << greeting << "\n";
  24.  
  25.  
  26.  
  27.     int l = greeting.length();
  28.  
  29.     cout << "\"" + greeting + "\" is " << l << " characters long." << "\n";
  30.    
  31.     string beginning = greeting.substr(greeting.find(' ') + 1);
  32.     cout << beginning << "\n";
  33.  
  34.     if (beginning == name)
  35.     {
  36.         cout << "expected result!" << "\n";
  37.  
  38.  
  39.     }*/
  40.  
  41. /*
  42.     //Write a program that asks the user for two words and tells them which is longer
  43.  
  44.  
  45.     string wordOne = "";
  46.     string wordTwo = "";
  47.    
  48.     cout << "Enter the first word: \n";
  49.     cin >> wordOne;
  50.     cout << "Enter the second word: \n";
  51.     cin >> wordTwo;
  52.  
  53.     int l1 = wordOne.length();
  54.     int l2 = wordTwo.length();
  55.  
  56.     if (l1 > l2)
  57.     {
  58.         cout << wordOne + " is longer than " + wordTwo;
  59.  
  60.     }
  61.     else if (l1 == l2) {
  62.         cout << "They are equal!";
  63.     }
  64.     else
  65.     {
  66.         cout << wordTwo + " is longer than " + wordOne;
  67.     }
  68.     */
  69.  
  70.  
  71.  
  72.     vector<int> nums; //A vector of integers - currently with 0 elements in it.
  73.  
  74.     //nums.push_back(3); //push_back adds an element at the end of the set NOTE: Types must match!
  75.  
  76.  
  77.     // Let's populate the collection
  78.     for (int i = 1; i <= 10; i++) {
  79.  
  80.         nums.push_back(i);
  81.     }
  82.  
  83.  
  84.  
  85.     //Range based for loop (Used for iterating through the vector)
  86.  
  87.     for (auto item : nums)   //NOTE: 'item' is NOT a keyword, just an identifier for the iterator
  88.     {
  89.         cout << item << "\n";
  90.     }
  91.  
  92.     //Accessing an element: eg: nums[x] where x is the position (nums is the vector name)
  93.     //eg:
  94.  
  95.     cout << nums[3];
  96.  
  97.     /////////////////
  98.     vector<string> words;
  99.  
  100.     words.push_back("Cat");
  101.     words.push_back("Dog");
  102.     words.push_back("Mouse");
  103.     words.push_back("Rabbit");
  104.     words.push_back("Donkey");
  105.     words.push_back("Rhinoceros");
  106.     words.push_back("Dog");
  107.  
  108.     for (auto word : words) {
  109.         cout << word << "\n";
  110.     }
  111.  
  112.     sort(begin(words), end(words));   //sort comes from <algorithm>
  113.  
  114.  
  115.     for (auto word : words)
  116.     {
  117.         cout << word << "\n";
  118.     }
  119.  
  120.     int result = 0;
  121.     count(begin(nums), end(nums), 2);
  122.  
  123.     cout << "\nHere: " << result;
  124.  
  125.  
  126.     return 0;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement