1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include <algorithm>
#include <initializer_list>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
struct Student
{
typedef unsigned ID;
ID id;
string last_name;
string first_name;
};
ostream& operator << ( ostream& outs, const Student& student )
{
if (student.id)
return outs << student.id << "\t"
<< student.last_name << "\t"
<< student.first_name;
return outs << "ID\tLNAME\tFNAME";
}
typedef std::string CourseName;
typedef map <CourseName, vector <Student::ID> > Registrations;
typedef map <Student::ID, Student> Students;
int main()
{
Students students = {
{ 1, { 1, "Bourne", "Jason" } },
{ 2, { 2, "Greene", "Alice" } },
{ 3, { 3, "Idol", "Billy" } },
{ 4, { 4, "Moore", "Mandy" } }
};
Registrations registrations = {
{ "Algebra", { 1, 2 } },
{ "English", { 2, 3 } },
{ "Art", { 1, 3, 4 } }
};
cout << "Courses:\n";
for (auto r : registrations)
cout << " " << r.first << "\n";
cout << "\n";
cout << "Enter course name: ";
string course;
getline( cin, course );
if (!registrations.count( course ))
cout << "That course does not exist.\n";
else
{
cout << Student() << "\n";
for (auto id : registrations[ course ])
cout << students[ id ] << "\n";
cout << "\n";
}
}
|