#include "stdafx.h" //don't worry about this line
#include <iostream>
#include <vector>
#include<algorithm>
usingnamespace std;
bool myfunction (int i,int j) { return (i<j); }
struct myclass {
booloperator() (int i,int j) { return (i<j);}
}myobject;
int main()
{
vector<double> student_marks(05);
for (vector<double>::size_type i = 0; i < 05; i++)
{
cout << "Please enter grades for student #" << i+1
<< ": " << flush;
cin >> student_marks[i];
}
// ... Do some stuff with the values
//remove an element
cout<<"Please enter the position where you would like the value to be removed \n";
int i;
cin>>i;
student_marks.erase (student_marks.begin()+i-1);
//displaying the vector
cout << "My Vector Contains the following below:\n";
for (unsigned i=0; i<student_marks.size(); ++i)
cout << ' ' << student_marks[i];
cout << "\n \n";
cout<<"Sorted Vector contains \n \n";
//sorting and displaying again
std::sort(student_marks.begin(), student_marks.end());
// print out content:
cout << "My Vector contains:";
for (unsigned i=0; i<student_marks.size(); ++i)
cout << ' ' << student_marks[i];
cout << '\n';
system ("Pause");
return 0;
}
My code compiles just fine. and i have no problem except for when i debug. Everything is fine but the part where it says: sorted vector contains: shows nothing. Any idea/help would be much appreciated. Should I increase the marks from 5 to 20 or something higher???? I'm alil confused what did I do wrong.
Thanks
Here's the initial question:
Create a simple program that manipulates vectors as follows: