Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "std_lib_facilities.h"
- #include "Courses.h"
- #include "GroupOfStudents.h"
- #include "Student.h"
- #include "StudentCourses.h"
- void metodaZaGenerisanjeBin() {
- fstream file;
- string path;
- string upath;
- GroupOfStudents g;
- cout << "Putanja do ulazne txt sa sve nazivom : ";
- cin >> upath;
- ucitajIzTekstualne(g, upath);
- cout << "Putanja do izlazne bin sa sve nazivom : ";
- cin >> path;
- file.open(path, ios::out | ios_base::binary);
- const char tabulator = '\t';
- const char newline = '\n';
- if (!file) {
- std::cout << "Error in creating file...\n";
- }
- for (StudentCourses sc : g.get_student_courses()) {
- for (char c : sc.get_student().get_first_name()) {
- file.write(&c, sizeof(char));
- }
- file.write(&tabulator, sizeof(char));
- for (char c : sc.get_student().get_last_name()) {
- file.write(&c, sizeof(char));
- }
- file.write(&tabulator, sizeof(char));
- for (char c : sc.get_student().get_id()) {
- file.write(&c, sizeof(char));
- }
- file.write(&newline, sizeof(char));
- for (int i : sc.get_courses().get_quiz()) {
- file.write(reinterpret_cast<char*>(&i), sizeof(int));
- file.write(&tabulator, sizeof(char));
- }
- file.write(&newline, sizeof(char));
- for (int i : sc.get_courses().get_homework()) {
- file.write(reinterpret_cast<char*>(&i), sizeof(int));
- file.write(&tabulator, sizeof(char));
- }
- file.write(&newline, sizeof(char));
- for (int i : sc.get_courses().get_test()) {
- file.write(reinterpret_cast<char*>(&i), sizeof(int));
- file.write(&tabulator, sizeof(char));
- }
- file.write(&newline, sizeof(char));
- }
- file.close();
- }
- void ucitajIzTekstualne(GroupOfStudents& gos, string path) {
- ifstream file;
- file.open(path, ios::in);
- StudentCourses sc;
- vector<StudentCourses> vect = vector<StudentCourses>();
- if (!(file.is_open())) {
- throw 1;
- }
- else {
- while (!(file.eof())) {
- if (file.fail() || file.bad()) {
- throw 1;
- }
- file >> sc;
- vect.push_back(sc);
- }
- }
- gos.set_student_courses(vect);
- }
- int main() {
- string a = "";
- while (a != "dosta") {
- metodaZaGenerisanjeBin();
- cin.clear();
- cin >> a;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement