Vectors. Vectors allow you to make resizeable lists of data. With vectors, you can also write functions that will work on data sets of any size To work with the vector class, include the standard namespace header file <vector>. Vectors. To declare a vector, use one of the following :
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
vector <datatype> identifier; //empty, uninitializedvector <datatype> identifier(int size); //size given, uninitialized vector <datatype> identifier(int size, datatype initialvalue); //size + initialized
//empty, uninitialized vector of doubles called myScores.
vector <double> myScores;
//make an uninitialized vector of 3 strings called myNames.
vector <string> myNames(3);
//make a vector of 10 ints, initialized to 5.
vector <int> nums(10,5);
//assign 1st element of string vector myNames
myNames = “Mandi”;
//loop through nums vector counting 5’s
for(int x = 0; x < nums.size(); x++)if(nums[x]== 5)
//a display function
void display(const vector <int> nums)
//fill functionvoid display(vector <int> &nums)
//template display functiontemplate <typename bob>void display(const vector <bob> nums)
names.resize(names.size()-1); //be careful!
Write a program that reads a text file that has a student’s full name (on its own line) and several test scores after it. Make sure there is NO WHITE SPACE after the last number. The number of scores is unknown, and may change since the student’s teacher will open the file and type in new grades whenever they come up. Your program will always open the file, read the student name and then store the grades in a vector. The program will then compute the test average - throw out the lowest score (only if there are at least two scores). A sample text file with output is below. You may want to include more output (like the dropped score, size of the vector, etc… to help you error trap as you are coding.
99.6 77 77 88
33.5 44.9 12 44 33