The goal is to store the students names in an STL list and sort them based on the last name.
- Your primary tasks for this exercise are to edit the main.cpp file so that it does the following:
- inputs students’ names from input.txt into the STL list
- sorts the list based on the last name
- outputs the students’ names in order
- Steps include:
- Read each line from input.txt. Store the firstname and the lastname into the temporary student structure “currStudent”.
- Hint: You can use the following format:
while(studentFile >> currStudent.firstname >> currStudent.lastname)_x000D_
- Push the current student into the list (“students”)
- Build and run the executable file. If you get an error like this:
error C2679: binary '<<' : no operator defined which takes a right-hand operand_x000D_
of type 'DataType' (or there is no acceptable conversion)_x000D_
- Notice that the compiler is complaining about the ‘<<‘. You are trying to output a DataType but, there is no existing definition for cout << DataType.
- Solve this problem by overloading the “<<” operator.
- Because the packets haven’t been sorted yet, your output should look like the following:
Jacob Anderson_x000D_
Michael Thomson_x000D_
Joshua Smith_x000D_
Mathew Matheis_x000D_
Ethan Evans _x000D_
Emily Drake_x000D_
Emma Patterson_x000D_
Madison McPhee_x000D_
Hannah Briens_x000D_
Ashley Schmidt_x000D_
Press any key to continue_x000D_
- Add code to sort the list (students), and print the correctly ordered list of students (using the iterator).
- Build and run the executable. If you get this error:
error C2784: 'bool std::operator <(const std::list<_Ty,_Alloc> &, _x000D_
const std::list<_Ty,_Alloc> &)' : could not deduce template argument for _x000D_
'const std::list<_Ty,_Alloc> &' from 'DataType'_x000D_
- Reread the description of sort. This error is complaining about the following comparison in the sort function: DataType < DataType
- When you correct this problem, consider using getKey(). Why?
- (later, if you wanted to sort by firstname, how would you do it?)
- Your output should look like the following:
Jacob Anderson_x000D_
Michael Thomson_x000D_
Joshua Smith_x000D_
Mathew Matheis_x000D_
Ethan Evans_x000D_
Emily Drake_x000D_
Emma Patterson_x000D_
Madison McPhee_x000D_
Hannah Briens_x000D_
Ashley Schmidt_x000D_
Sorting........._x000D_
Jacob Anderson_x000D_
Hannah Briens_x000D_
Emily Drake_x000D_
Ethan Evans_x000D_
Mathew Matheis_x000D_
Madison McPhee_x000D_
Emma Patterson_x000D_
Ashley Schmidt_x000D_
Joshua Smith_x000D_
Michael Thomson_x000D_
Press any key to continue_x000D_
————————————————————————————————————————–
main.cpp
#include <iostream>_x000D_
#include <fstream>_x000D_
#include <string>_x000D_
#include <list>_x000D_
_x000D_
using namespace std;_x000D_
_x000D_
struct DataType _x000D_
{_x000D_
string lastname; // Student's Last Name_x000D_
string firstname; // Student's First Name_x000D_
_x000D_
string getKey () const_x000D_
{ return lastname; } // Returns the key field_x000D_
};_x000D_
_x000D_
//---------Need to add code to overload operator <<_x000D_
//------- Need to add code to fix error C2784: 'bool __cdecl std::operator <_x000D_
_x000D_
bool operator < (DataType lhs, DataType rhs)_x000D_
{_x000D_
_x000D_
}_x000D_
_x000D_
void main() _x000D_
{_x000D_
ifstream studentFile ("input.txt"); // Student file_x000D_
list <DataType> students; // Students_x000D_
DataType currStudent; // One Student (has firstname,lastname)_x000D_
// Read each line from input.txt:_x000D_
//Store the firstname and the lastname into _x000D_
//the temporary student structure "currStudent"._x000D_
// Push the current student into the list ("students") _x000D_
// Use an iterator to print the unsorted list of students._x000D_
// Sort the list of students._x000D_
// Use an iterator to print the sorted list of students._x000D_
}








Jermaine Byrant
Nicole Johnson



