Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
// The language is c++
//please explain step by step
By using
"This is C++ code with no commas semicolons of fullstops:;
Expert Solution
arrow_forward
Step 1
NOTE: - To clearly demonstrating the concept, the size of the vector is printed at multiple places.
EXPLANATION: -
Defining Vector Dynamically: -
vector<string>* myVector = new vector<string>(5);
- The above line dynamically creates and initializes the vector named myVector with 5 empty strings.
- Right now myVector is already having 5 elements.
- Vector is dynamic in nature, it automatically increases its size when more elements are added to it.
- The size function on myVector gives the current size of the vector. Since it is a pointer, so arrow pointer is used to access the method
- cout<<"vector size: "<< myVector->size() <<endl;
- Any push_back operation will result in an increment in the size of the vector named myVector.
push_back function: -
- This function adds elements at end of the vector, and each operation increments the vector size by 1.
- myVector->push_back(message);//message is added at index 5
- Vector also follows zero-based indexing.
- A total of 5 push_back operations are performed.
- Hence, the vector size becomes 10 now.
Now vector contains 5 empty strings, and 5 messages, a total of 10 elements.
Displaying the vector: -
- The vector elements are printed using for loop which runs from index 0 till the size of the vector - 1 that is 9.
- To access the element of the vector, dereferencing is required, since it is a pointer.
- First, the vector variable myVector is dereferenced, then the element present at the index variable i is stored in variable myStringusing the rectangular brackets.
- string myString = (*myVector)[i];
- First, the vector variable myVector is dereferenced, then the element present at the index variable i is stored in variable myStringusing the rectangular brackets.
- Initially, there are five empty strings, so to prevent printing the empty strings, if the condition is applied, only if the string is not empty, it is printed on the console.
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- In C++, define an integer vector and ask the user to give you values for the vector. Because you used a vector, so you don't need to know the size. user should be able to enter a number until he wants(you can use while loop for termination. for example if the user enters any negative number, but until he enters a positive number, your program should read and push it inside of the vector). the calculate the average of all numbers he entered.arrow_forwardUsing C++ Using only these simpler vector methods Create a vector of at least 10 integers. Cout the vector with spaces in between the integers. Cout the vector backward. Using loops that traverse the elements, create a new vector with the elements arranged from high to low. Cout the new vector. Do not use iterators for this exercise, or any other advanced methods--only the ones listed below. Hint: Use multiple vectors, including the copying of vectors. vector<int> grades1 = {45, 67, 88, 45, 23}; vector<int> grades2 = grades1; May Only Use These Vector Methods: size() // Returns the number of elements empty() // Returns a boolean True if the vector is empty push_back(element) // Adds an element to the back of the vector pop_back() // Removes the element at the back of the vector front() // Returns the element at the front of the vector back()…arrow_forwardUSING C++ Program Specifications: Write a program to calculate the minimum, maximum, mean, median, mode, and whether a vector is a palindrome. Step 0. Review the starter code in main(). A vector is filled with integers from standard input. The first value indicates how many numbers are to follow and be placed in the vector. Step 1. Use a loop to process each vector element and output the minimum and maximum values. Submit for grading to confirm one test passes. Ex: If the input is: 6 4 1 5 4 99 17 the output is: Minimum: 1 Maximum: 99 Step 2. Use a loop to sum all vector elements and calculate the mean (or average). Output the mean with one decimal place using cout << fixed << setprecision(1); once before all other cout statements. Submit for grading to confirm two tests pass. Ex: If the input is: 6 4 1 5 4 99 17 the output is: Minimum: 1 Maximum: 99 Mean: 21.7 Step 3. Use a loop to determine if the vector is a palindrome, meaning values are the same from front to back and…arrow_forward
- Write a C++ Program that does the following: Implement a sort function using a vector.Ask the user to enter numbers to be sorted. Add them to the vector. The user will signal the end of input bygiving you a negative number.Then, sort the vector. Because this is a vector, you don’t need to pass the number of entriesin the vector.Then, print out the vector in order.Remember the following things about vectors.a) You declare a vector v of ints by saying vector⟨int⟩ v;b) You add elements to a vector by saying v.push back(thing to be added);c) You access elements of a vector with [ ] just like an array;d) One of the vector member functions is .length()arrow_forwardCreate a flowchart for this program in c++, #include <iostream>#include <vector> // for vectors#include <algorithm>#include <cmath> // math for function like pow ,sin, log#include <numeric>using std::vector;using namespace std;int main(){ vector <float> x, y;//vector x for x and y for y float x_tmp = -2.5; // initial value of x float my_function(float x); while (x_tmp <= 2.5) // the last value of x { x.push_back(x_tmp); y.push_back(my_function(x_tmp)); // calculate function's value for given x x_tmp += 1;// add step } cout << "my name's khaled , my variant is 21 ," << " my function is y = 0.05 * x^3 + 6sin(3x) + 4 " << endl; cout << "x\t"; for (auto x_tmp1 : x) cout << '\t' << x_tmp1;//printing x values with tops cout << endl; cout << "y\t"; for (auto y_tmp1 : y) cout << '\t' << y_tmp1;//printing y values with tops…arrow_forwardIn C++ please follow the instructions Write two code blocks -- one code block to declare a bag and its companion type-tracking array (both using the STL vector), and another code block to create and declare a Cat object and put it into the bag. Name the arrays and variables as you wish. Use any data type tracking and any designation for cats -- your choices. Assume that struct Cat is already defined and that all required libraries are properly included -- just write the two separate code blocks, separated by one or more blank lines.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education