The Standard Template Library (STL) includes the collection of data types and
- A special data type called vector is offered by STL which is useful for standard arrays.
A vector stores the elements or values in sequence order and the values are stored in continuous memory locations.
- The subscript operator “[]” in the vector helps to read the content of each element.
Initialization of vector:
In C++, the vector is initialized with the respective value as like the array but it does not use the “=” operator before the list and uses the keyword “vector”.
- The initialization list values are enclosed with the braces.
Consider the following statement:
//Declaring a vector with four values
vector <int> values {40, 32, 15, 17};
In the above line, the keyword “vector” represents the vector declaration, “<int>” represents that the vector holds integer type values, “values” represents the name of the vector, and the values inside the braces refers the values of the vector “values”.
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
- matrix = {{1,2},{4,5}} this in c++arrow_forwardGame of Hunt in C++ language Create the 'Game of Hunt'. The computer ‘hides’ the treasure at a random location in a 10x10 matrix. The user guesses the location by entering a row and column values. The game ends when the user locates the treasure or the treasure value is less than or equal to zero. Guesses in the wrong location will provide clues such as a compass direction or number of squares horizontally or vertically to the treasure. Using the random number generator, display one of the following in the board where the player made their guess: U# Treasure is up ‘#’ on the vertical axis (where # represents an integer number). D# Treasure is down ‘#’ on the vertical axis (where # represents an integer number) || Treasure is in this row, not up or down from the guess location. -> Treasure is to the right. <- Treasure is to the left. -- Treasure is in the same column, not left or right. +$ Adds $50 to treasure and no $50 turn loss. -$ Subtracts…arrow_forwardR4arrow_forward
- module 4: Differentiate between Writing Functions for Array and Writing Functions for Structures.arrow_forward#include #include #include "Product.h" using namespace std; int main() { vector productList; Product currProduct; int currPrice; string currName; unsigned int i; Product resultProduct; cin>> currPrice; while (currPrice > 0) { } cin>> currPrice; main.cpp cin>> currName; currProduct.SetPriceAndName (currPrice, currName); productList.push_back(currProduct); resultProduct = productList.at (0); for (i = 0; i < productList.size(); ++i) { Type the program's output Product.h 1 CSE Scanned Product.cpp if (productList.at (i).GetPrice () < resultProduct.GetPrice ()) { resultProduct = productList.at(i); } AM cout << "$" << resultProduct.GetPrice() << " " << resultProduct. GetName() << endl; return 0; Input 10 Cheese 6 Foil 7 Socks -1 Outputarrow_forwardfunction carLambda = [rank, &price] ()->int { cout name); model Car:: carModel; auto testLambdaPtr = testLambda (); cout << testLambdaPtr () << endl; return 0; I a. In which memory area is this element stored? Please state your choice and explain why? b. The lifetime, beginning & end, of this element? Why?arrow_forward
- typedef _people { int age; char name[ 32 ] ; } People_T ; People_T data [ 3 ]; Using string lib function, Assign 30 and Cathy to the first cell, Assign 40 and John to the second cell and Assign 50 and Tom to the third cell People_T *ptr ; Declare a pointer pointing to the structure data and print the age and name using the pointer. your output can be : 30 Cathy 40 John 50 Tomarrow_forwardSubmerging is the phenomenon wherein the pointer vanishes when you move it too quickly.arrow_forwardWhat kinds of aggregation procedures are permitted for struct variables but are not permitted for array variables?arrow_forward
- C programming pseudocode pointers help. { totalInAGivenHour+=*(rawReadings+ monthNo*30*14*4 + 14*4*nThDateOfMonth+ 4*nThHourOfDateFrom7AM + nThReadingTimeOfHour); // the pointer is to assign the values in the bracket and storing them in totalInAGivenHour }arrow_forward#include #include #include "Product.h". using namespace std; int main() { vector productList; Product currProduct; int currPrice; string currName; unsigned int i; Product resultProduct; cin >> currPrice; while (currPrice > 0) { cin >> currName; currProduct.SetPriceAndName (currPrice, currName); productList.push_back (currProduct); cin >> currPrice; } resultProduct = productList.at(0); for (i = 0; i resultProduct.GetPrice()) { resultProduct = productList.at(i); } CS re 0; ultProduct.GetName() << " " << result Product.GetPrice() << endl; Input 10 Berries 8 Paper 7 Socks -1 Output ||^arrow_forwardCreate functions using the R language that take five arguments and multiplies them according to the type of object they are: Scalar Vector Matrix Plot each of the functions that you have constructed.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage