Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ucitajIzBinarne(GroupOfStudents& gos,string path) {
- ifstream file;
- //cout << "Unesite putanju do datoteke gde zelite da sacuvate nesto";
- //cin >> gos.path;
- file.open(path, ios::in | ios::binary);
- gos.binarna = true;
- if (!(file.is_open())) {
- throw Menu::InvalidFile();
- }
- else {
- //metodaZaGenerisanjeBin();
- const char tabulator = '\t';
- const char newline = '\n';
- GroupOfStudents gofo = GroupOfStudents();
- vector<StudentCourses> gofov = vector<StudentCourses>();
- while (!(file.eof())) {
- char temp;
- int itemp;
- char burn;
- string fn = "";
- string ln = "";
- string id = "";
- vector<int> q = vector<int>();
- vector<int> h = vector<int>();
- vector<int> t = vector<int>();
- do {
- file.read(reinterpret_cast<char*>(&temp), sizeof(char));
- if (temp != tabulator) {
- fn += temp;
- }
- } while (temp != tabulator);
- do {
- file.read(reinterpret_cast<char*>(&temp), sizeof(char));
- if (temp != tabulator) {
- ln += temp;
- }
- } while (temp != tabulator);
- do {
- file.read(reinterpret_cast<char*>(&temp), sizeof(char));
- if (temp != newline) {
- id += temp;
- }
- } while (temp != newline);
- for (int j = 0; j < Courses::NUM_QUIZZES; ++j) {
- file.read(reinterpret_cast<char*>(&itemp), sizeof(int));
- file.read(reinterpret_cast<char*>(&burn), sizeof(char));
- if (itemp > 100 || itemp < 0) {
- throw Menu::InvalidData();
- }
- q.push_back(itemp);
- }
- file.read(reinterpret_cast<char*>(&burn), sizeof(char));
- for (int j = 0; j < Courses::NUM_HW; ++j) {
- file.read(reinterpret_cast<char*>(&itemp), sizeof(int));
- file.read(reinterpret_cast<char*>(&burn), sizeof(char));
- if (itemp > 100 || itemp < 0) {
- throw Menu::InvalidData();
- }
- h.push_back(itemp);
- }
- file.read(reinterpret_cast<char*>(&burn), sizeof(char));
- for (int j = 0; j < Courses::NUM_TESTS; ++j) {
- file.read(reinterpret_cast<char*>(&itemp), sizeof(int));
- file.read(reinterpret_cast<char*>(&burn), sizeof(char));
- if (itemp > 100 || itemp < 0) {
- throw Menu::InvalidData();
- }
- t.push_back(itemp);
- }
- file.read(reinterpret_cast<char*>(&burn), sizeof(char));
- Student stud = Student(fn, ln, id);
- Courses cour = Courses(q, h, t);
- cour.calc_final_score();
- cour.calc_letter_grade();
- StudentCourses stco = StudentCourses(stud, cour);
- gofov.push_back(stco);
- file.read(reinterpret_cast<char*>(&burn), sizeof(char));
- if (!(burn == tabulator || burn == newline)) {
- file.unget();
- }
- }
- gos.set_student_courses(gofov);
- }
- file.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement