Create a Program in C++ without StandardTemplates only with vectors or dynamic a
ID: 3749710 • Letter: C
Question
Create a Program in C++ without StandardTemplates only with vectors or dynamic arrays...
1. Input will be from stdin, takes positive integers only (not zero)
2. Have the following function:
-addElement: takes a + integer and add it to the set
-getElement: take position and return the element at the position (return -1 if bad position)
-getSize: return size of the set
-isSubset: takes a sets object (b) and see if the current set (a) is a subset of b and if so return true, else return false
-isProper: takes sets object (b) and see if the current set (a) is a proper subset of b. Use isSubset first to see if b has at
least one more element than a
-printOrderedPairs: takes a sets object (b) and takes the current set (a) and prints the ordered pairs of of A X B. Print if
setA is a subset of setB and if setA is a proper subset of setB.
-main: create two objects, setA and setB
Explanation / Answer
Vectors are same as unique clusters with the capacity to resize itself naturally when a component is embedded or erased, with their capacity being taken care of consequently by the compartment. Vector components are put in adjoining stockpiling with the goal that they can be gotten to and navigated utilizing iterators. In vectors, information is embedded toward the end. Embeddings toward the end takes differential time, as now and again there might be a need of broadening the exhibit. Expelling the last component takes just consistent time on the grounds that no resizing occurs. Embeddings and eradicating toward the start or in the center is straight in time.
Certain capacities related with the vector are:
Iterators
start() – Returns an iterator indicating the main component in the vector
end() – Returns an iterator indicating the hypothetical component that takes after the last component in the vector
rbegin() – Returns a turn around iterator indicating the last component in the vector (invert starting). It moves from last to first component
rip() – Returns an invert iterator indicating the hypothetical component going before the primary component in the vector (considered as turn around end)
cbegin() – Returns a steady iterator indicating the main component in the vector.
cend() – Returns a consistent iterator indicating the hypothetical component that takes after the last component in the vector.
crbegin() – Returns a consistent switch iterator indicating the last component in the vector (invert starting). It moves from last to first component
crend() – Returns a consistent turn around iterator indicating the hypothetical component going before the principal component in the vector (considered as switch end)
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int main()
{
vector<int> v;
vec.assign(5, 10);
cout << "The vecector elements are: ";
for (int i = 0; i < vec.size(); i++)
cout << vec[i] << " ";
vec.push_back(15);
int n = vec.size();
cout << " The last element is: " << vec[n - 1];
vec.pop_back();
cout << " The vecector elements are: ";
for (int i = 0; i < vec.size(); i++)
cout << vec[i] << " ";
vec.insert(vec.begin(), 5);
cout << " The first element is: " << vec[0];
vec.erase(vec.begin());
cout << " The first element is: " << vec[0];
vec.emplace(vec.begin(), 5);
cout << " The first element is: " << vec[0];
vec.emplace_back(20);
n = vec.size();
cout << " The last element is: " << vec[n - 1];
vec.clear();
cout << " Vector size after erase(): " << vec.size();
vecector<int> vec1, vec2;
vec1.push_back(1);
vec1.push_back(2);
vec2.push_back(3);
vec2.push_back(4);
cout << " Vector 1: ";
for (int i = 0; i < vec1.size(); i++)
cout << vec1[i] << " ";
cout << " Vector 2: ";
for (int i = 0; i < vec2.size(); i++)
cout << vec2[i] << " ";
vec1.swap(vec2);
cout << " After Swap Vector 1: ";
for (int i = 0; i < vec1.size(); i++)
cout << vec1[i] << " ";
cout << " Vector 2: ";
for (int i = 0; i < vec2.size(); i++)
cout << vec2[i] << " ";
}