Advertisement
canezzy

binTestGenerator

Dec 4th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. #include "std_lib_facilities.h"
  2. #include "Courses.h"
  3. #include "GroupOfStudents.h"
  4. #include "Student.h"
  5. #include "StudentCourses.h"
  6.  
  7. void metodaZaGenerisanjeBin() {
  8.     fstream file;
  9.     string path;
  10.     string upath;
  11.     GroupOfStudents g;
  12.     cout << "Putanja do ulazne txt sa sve nazivom : ";
  13.     cin >> upath;
  14.     ucitajIzTekstualne(g, upath);
  15.     cout << "Putanja do izlazne bin sa sve nazivom : ";
  16.     cin >> path;
  17.     file.open(path, ios::out | ios_base::binary);
  18.     const char tabulator = '\t';
  19.     const char newline = '\n';
  20.     if (!file) {
  21.         std::cout << "Error in creating file...\n";
  22.     }
  23.     for (StudentCourses sc : g.get_student_courses()) {
  24.         for (char c : sc.get_student().get_first_name()) {
  25.             file.write(&c, sizeof(char));
  26.         }
  27.         file.write(&tabulator, sizeof(char));
  28.         for (char c : sc.get_student().get_last_name()) {
  29.             file.write(&c, sizeof(char));
  30.         }
  31.         file.write(&tabulator, sizeof(char));
  32.         for (char c : sc.get_student().get_id()) {
  33.             file.write(&c, sizeof(char));
  34.         }
  35.         file.write(&newline, sizeof(char));
  36.         for (int i : sc.get_courses().get_quiz()) {
  37.             file.write(reinterpret_cast<char*>(&i), sizeof(int));
  38.             file.write(&tabulator, sizeof(char));
  39.         }
  40.         file.write(&newline, sizeof(char));
  41.         for (int i : sc.get_courses().get_homework()) {
  42.             file.write(reinterpret_cast<char*>(&i), sizeof(int));
  43.             file.write(&tabulator, sizeof(char));
  44.         }
  45.         file.write(&newline, sizeof(char));
  46.         for (int i : sc.get_courses().get_test()) {
  47.             file.write(reinterpret_cast<char*>(&i), sizeof(int));
  48.             file.write(&tabulator, sizeof(char));
  49.         }
  50.         file.write(&newline, sizeof(char));
  51.  
  52.  
  53.     }
  54.     file.close();
  55.  
  56. }
  57.  
  58. void ucitajIzTekstualne(GroupOfStudents& gos, string path) {
  59.     ifstream file;
  60.  
  61.     file.open(path, ios::in);
  62.     StudentCourses sc;
  63.     vector<StudentCourses> vect = vector<StudentCourses>();
  64.     if (!(file.is_open())) {
  65.         throw 1;
  66.     }
  67.     else {
  68.  
  69.         while (!(file.eof())) {
  70.             if (file.fail() || file.bad()) {
  71.                 throw 1;
  72.             }
  73.             file >> sc;
  74.  
  75.             vect.push_back(sc);
  76.         }
  77.  
  78.     }
  79.     gos.set_student_courses(vect);
  80. }
  81.  
  82. int main() {
  83.     string a = "";
  84.     while (a != "dosta") {
  85.         metodaZaGenerisanjeBin();
  86.         cin.clear();
  87.         cin >> a;
  88.     }
  89.    
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement