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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
#include <set>
#include <fstream>
#include <string>
#include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <iomanip>
#include <utility>
const std::map<std::string, std::string> subjects {{"Eng_lit", "English Literature"},
{"Eng", "English"},
{"Civic_ED" , "Civic Education"},
{"Accts" , "Accounts"},
{"Sic" , "Science"},
{"Bio" , "Biology"},
{"PMath" , "Pure Math"},
{"Math", "Mathematics"},
{"Bus_Math", "Business Mathematics"},
{"Phys" , "Physics"},
{"Chem" , "Chemistry"},
{"FnN" , "Food And Nutrition"},
{"R.E" , "Religious Education"},
{"AnM" , "Art and Music"},
{"Geo", "Geography"},
{"Hist" , "History"},
{"I.T", "Information Technology"},
{"Tech" , "Technology studies"}};
using SubMark = std::pair<const std::string, unsigned long>;
using Marks = std::map<std::string, unsigned long>;
struct Student {
std::string first;
std::string last;
char init {};
unsigned long id {};
unsigned long course {};
unsigned long year {};
Marks marks;
};
std::istream& operator>>(std::istream& is, Student& s)
{
std::string line;
s.marks.clear();
if (std::getline(is, line)) {
std::istringstream iss(line);
iss >> s.first >> s.last >> s.init >> s.id >> s.course >> s.year;
for (std::string submark; iss >> submark; ) {
const auto sep {submark.find('-')};
if (sep != std::string::npos) {
const auto ccode {submark.substr(0, sep)};
if (subjects.count(ccode) == 1)
s.marks.emplace(ccode, std::stoul(submark.substr(sep + 1)));
else
std::cout << "Subject " << ccode << " Not found\n";
}
}
}
return is;
}
std::ostream& operator<<(std::ostream& os, const Student& s)
{
return os << s.first << " " << s.last << " " << s.init << " " << s.id << " " << s.course << " " << s.year << "\n";
}
std::ostream& operator<<(std::ostream& os, const SubMark& m)
{
return os << std::left << std::setw(24) << subjects.find(m.first)->second << m.second;
}
bool process(const Marks& marks)
{
unsigned mes {}, other {};
bool OK {marks.size() >= 6};
for (const auto& m : marks) {
std::cout << m << '\n';
if (m.first == "Math" || m.first == "Eng" || m.first == "Sic")
mes += (m.second > 50);
else
other += (m.second > 50);
}
return OK && mes == 3 && other >= 3;
}
int main()
{
std::ifstream studs("students.txt");
std::ifstream marks("marks.txt");
if (!studs.is_open() || !marks.is_open())
return (std::cout << "Cannot open input files\n"), 1;
std::set<unsigned long> sids;
unsigned long sid {};
for (std::string item; studs >> item >> item >> item >> sid; )
sids.insert(sid);
for (Student s; marks >> s; )
if (sids.count(s.id) == 1) {
std::cout << s << '\n';
if (process(s.marks))
std::cout << "\nCriteria met!";
else
std::cout << "\nCriteria not met";
std::cout << "\n\n\n";
}
}
| |