Advertisement
canezzy

binucit

Dec 4th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.63 KB | None | 0 0
  1. void ucitajIzBinarne(GroupOfStudents& gos,string path) {
  2.    
  3.     ifstream file;
  4.  
  5.     //cout << "Unesite putanju do datoteke gde zelite da sacuvate nesto";
  6.     //cin >> gos.path;
  7.    
  8.     file.open(path, ios::in | ios::binary);
  9.     gos.binarna = true;
  10.     if (!(file.is_open())) {
  11.         throw Menu::InvalidFile();
  12.     }
  13.     else {
  14.        
  15.         //metodaZaGenerisanjeBin();
  16.         const char tabulator = '\t';
  17.         const char newline = '\n';
  18.        
  19.         GroupOfStudents gofo = GroupOfStudents();
  20.         vector<StudentCourses> gofov = vector<StudentCourses>();
  21.         while (!(file.eof())) {
  22.             char temp;
  23.             int itemp;
  24.             char burn;
  25.             string fn = "";
  26.             string ln = "";
  27.             string id = "";
  28.             vector<int> q = vector<int>();
  29.             vector<int> h = vector<int>();
  30.             vector<int> t = vector<int>();
  31.             do {
  32.                 file.read(reinterpret_cast<char*>(&temp), sizeof(char));
  33.                 if (temp != tabulator) {
  34.                     fn += temp;
  35.                 }
  36.             } while (temp != tabulator);
  37.             do {
  38.                 file.read(reinterpret_cast<char*>(&temp), sizeof(char));
  39.                 if (temp != tabulator) {
  40.                     ln += temp;
  41.                 }
  42.             } while (temp != tabulator);
  43.             do {
  44.                 file.read(reinterpret_cast<char*>(&temp), sizeof(char));
  45.                 if (temp != newline) {
  46.                     id += temp;
  47.                 }
  48.             } while (temp != newline);
  49.             for (int j = 0; j < Courses::NUM_QUIZZES; ++j) {
  50.                 file.read(reinterpret_cast<char*>(&itemp), sizeof(int));
  51.                 file.read(reinterpret_cast<char*>(&burn), sizeof(char));
  52.                 if (itemp > 100 || itemp < 0) {
  53.                     throw Menu::InvalidData();
  54.                 }
  55.                 q.push_back(itemp);
  56.             }
  57.             file.read(reinterpret_cast<char*>(&burn), sizeof(char));
  58.             for (int j = 0; j < Courses::NUM_HW; ++j) {
  59.                 file.read(reinterpret_cast<char*>(&itemp), sizeof(int));
  60.                 file.read(reinterpret_cast<char*>(&burn), sizeof(char));
  61.                 if (itemp > 100 || itemp < 0) {
  62.                     throw Menu::InvalidData();
  63.                 }
  64.                 h.push_back(itemp);
  65.             }
  66.             file.read(reinterpret_cast<char*>(&burn), sizeof(char));
  67.             for (int j = 0; j < Courses::NUM_TESTS; ++j) {
  68.                 file.read(reinterpret_cast<char*>(&itemp), sizeof(int));
  69.                 file.read(reinterpret_cast<char*>(&burn), sizeof(char));
  70.                 if (itemp > 100 || itemp < 0) {
  71.                     throw Menu::InvalidData();
  72.                 }
  73.                 t.push_back(itemp);
  74.             }
  75.             file.read(reinterpret_cast<char*>(&burn), sizeof(char));
  76.             Student stud = Student(fn, ln, id);
  77.             Courses cour = Courses(q, h, t);
  78.             cour.calc_final_score();
  79.             cour.calc_letter_grade();
  80.             StudentCourses stco = StudentCourses(stud, cour);
  81.             gofov.push_back(stco);
  82.            
  83.             file.read(reinterpret_cast<char*>(&burn), sizeof(char));
  84.             if (!(burn == tabulator || burn == newline)) {
  85.                 file.unget();
  86.             }
  87.         }
  88.  
  89.  
  90.         gos.set_student_courses(gofov);
  91.  
  92.     }
  93.  
  94.  
  95.     file.close();
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement