Posts

Auto in C++

 // C++ program to demonstrate that we can use auto to // save time when creating iterators #include <bits/stdc++.h> using namespace std; int main() { // Create a set of strings set<string> st; st.insert({ "geeks", "for", "geeks", "org" }); // 'it' evaluates to iterator to set of string // type automatically for (auto it = st.begin(); it != st.end(); it++) cout << *it << " "; return 0; };

Classes and Objects C++

  Kristen is a contender for valedictorian of her high school. She wants to know how many students (if any) have scored higher than her in the   exams given during this semester. Create a class named   with the following specifications: An instance variable named   to hold a student's   exam scores. A  void input()  function that reads   integers and saves them to  . An  int calculateTotalScore()  function that returns the sum of the student's scores. Input Format Most of the input is handled for you by the locked code in the editor. In the  void Student::input()  function, you must read   scores from stdin and save them to your   instance variable. Constraints Output Format In the  int Student::calculateTotalScore()  function, you must return the student's total grade (the sum of the values in  ). The locked code in the editor will determine how many scores are l...

Structs or Structures in C++

  https://www.w3schools.com/cpp/cpp_structs.asp

Vectors STL in C++

Image
  #include   < cmath > #include   < cstdio > #include   < vector > #include   < iostream > #include   < algorithm > using   namespace  std; void  display(vector< int >v2){     sort(v2.begin(),v2.end());      for  ( int  i; i<v2.size(); i++) {     cout<<v2[i]<< " " ;     }     cout<<endl; } int  main() {      /* Enter your code here. Read input from STDIN. Print output to STDOUT */       vector< int >v;      int  size, a;     cin>>size;      for  ( int  i; i < size; i++) {     cin>>a;   ...