ive been working on this for a while and I'm at the point where I'm required to bubble sort my string vector. I looked everywhere on how to do this but no luck..
I'm trying to sort the names of the volunteers by getting the last name to be listed first and then first name. my issue is, is that I have no idea how to get it to sort. be aware that I have objects and header files. this is the portion of my main.
also to note I need the sort to be in a function out side of main.
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include "VolunteerNumber.h"
usingnamespace std;
int main()
{
//create vector
vector <string> mVector;
//Declare variables
string
nameVolGr, //Name of volunteer group
nameLoc, //Name of location of the volunteer group
fileName, //name of output file
clocation, //loction of output file
nameF, //stores first name
nameL, //stores last name
email, //stores email
phone, //stores phone number
data; //stores concat
int numVol; //stores number of volunteers
//Ask user for volunteer group name
cout << "Volunteer Group Name: ";
cin >> nameVolGr;
//Ask user for location
cout << "Location: ";
cin >> nameLoc;
//Ask for number of volunteers
cout << "Number of Volunteers: ";
cin >> numVol;
//Creat output file
fileName = clocation + "_" + nameVolGr + ".txt";
ofstream fout(fileName);
//for loop to count till the number of volunteers on the list id met
for (int i = 1; i <= numVol; i++)
{
//ask user in loop for information
cout << "-----------------------------------" << endl;
cout << "To end program enter -1 in first name" << endl << endl;
//Ask user to enter volunteers first name
//this is out side the if so the user can end using -1 inside first name
cout << "Enter first name: ";
cin >> nameF;
//if statement
if (nameF != "-1")
{
//Ask user to enter volunteers last name
cout << "Enter enter last: ";
cin >> nameL;
//Ask user to enter volunteers email address
cout << "Enter email: ";
cin >> email;
//Ask user to enter volunteers phone number
cout << "Enter phone number: ";
cin >> phone;
}
else
{
break;
}
//Get volunteer information
VolunteerNumber group_1(nameF, nameL, email, phone);
//display information that was added
cout << endl << "Fist name: " << group_1.getNameF() << endl <<
"Last name: " << group_1.getNameL() << endl <<
"Email: " << group_1.getemail() << "Phone #: " << group_1.getphone() << endl;
//concat data all together in to data variable
data = nameL + " " + nameF + " " + email + " " + phone;
//push data variables into mVector
mVector.push_back(data);
//reset variables
data = "";
}
//print vector data
for (int i = 0; i < mVector.size(); i++)
{
cout << mVector[i] << endl;
}
system("pause");
return 0;
}