From bd9ffde20d67674041712a6686340b0c619b791b Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 15 May 2021 12:31:51 +0300 Subject: minor fixes --- Sem. 01/task1.cpp | 127 +++------------ Sem. 01/task1/task1.cpp | 126 +++++++++++++++ Sem. 02/selfPrintingTask.cpp | 26 --- Sem. 02/students.csv | 10 -- Sem. 02/studentsDatabase.cpp | 253 ------------------------------ Sem. 02/task1/selfPrintingTask.cpp | 26 +++ Sem. 02/task2/students.csv | 10 ++ Sem. 02/task2/studentsDatabase.cpp | 253 ++++++++++++++++++++++++++++++ Sem. 04/uni_task(not finished).cpp | 156 ------------------ Sem. 06/Time/Time.cpp | 6 +- Sem. 07/PersonAdvanced/PersonAdvanced.cpp | 5 + Sem. 08/Nvector/Source.cpp | 1 + Sem. 12/task1/Drinks/AlcoholDrink.cpp | 1 + Sem. 12/task1/Drinks/Drink.cpp | 1 + Sem. 12/task1/Drinks/EnergyDrink.cpp | 1 + Sem. 12/task1/main.cpp | 5 +- 16 files changed, 450 insertions(+), 557 deletions(-) create mode 100644 Sem. 01/task1/task1.cpp delete mode 100644 Sem. 02/selfPrintingTask.cpp delete mode 100644 Sem. 02/students.csv delete mode 100644 Sem. 02/studentsDatabase.cpp create mode 100644 Sem. 02/task1/selfPrintingTask.cpp create mode 100644 Sem. 02/task2/students.csv create mode 100644 Sem. 02/task2/studentsDatabase.cpp delete mode 100644 Sem. 04/uni_task(not finished).cpp diff --git a/Sem. 01/task1.cpp b/Sem. 01/task1.cpp index 67ad5b1..e6f4661 100644 --- a/Sem. 01/task1.cpp +++ b/Sem. 01/task1.cpp @@ -3,124 +3,35 @@ using namespace std; - -struct point -{ - int x; - int y; -}; -void print(const point& ptr) -{ - cout << ptr.x << " " << ptr.y << endl; -} -point readPoint() -{ - int x, y; - cin >> x >> y; - return{ x, y }; -} -double getDist(const point& origin, const point& dest) -{ - double dx = origin.x - dest.x; - double dy = origin.y - dest.y; - - return sqrt(dx*dx + dy*dy); -} - - -struct triangle -{ - point p1; - point p2; - point p3; -}; - -double getArea(const triangle& tr) -{ - double sideA = getDist(tr.p1, tr.p2); - double sideB = getDist(tr.p2, tr.p3); - double sideC = getDist(tr.p3, tr.p1); - - double halfP = (sideA + sideB + sideC) / 2; - return sqrt(halfP * (halfP - sideA) * (halfP - sideB) * (halfP - sideC)); - -} - -void print(const triangle& tr) -{ - cout << "Point1: "; - print(tr.p1); - cout << "Point2: "; - print(tr.p2); - cout << "Point3: "; - print(tr.p3); - cout << getArea(tr) << endl << endl; -} - -void swap(int * arr, int i, int j) -{ - int temp = arr[i]; - arr[i] = arr[j]; - arr[j] = temp; -} -void swap(triangle* arr, int i, int j) -{ - triangle temp = arr[i]; - arr[i] = arr[j]; - arr[j] = temp; -} -void selectionSort(int* areas, triangle* triangles, int len) +bool checkIfObratim(size_t element, size_t Z) { - for (int i = 0; i < len-1; i++) + for (int i = 1; i < Z; i++) { - int currPos = i; - int min = i; - - for (int j = i; j < len; j++) + if ((i * element) % Z == 0) { - if (areas[j] < areas[min]) - min = j; + std::cout << "Obratniq element na " << element << " e " << i << std::endl; + return true; } - - if (min != i) + } + return false; +} +size_t countDivisers(size_t Z) +{ + size_t count = 0; + for (int i = 1; i < Z; i++) + { + if (checkIfObratim(i,Z)) + count++; + else { - swap(areas, i, min); - swap(triangles, i, min); + std::cout << "Neobratim " << i << std::endl; } } + return count; } int main() { - - int n; - cin >> n; - - triangle* triangles = new triangle[n]; - - for (int i = 0; i < n; i++) - { - point p1 = readPoint(); - point p2 = readPoint(); - point p3 = readPoint(); - - triangles[i].p1 = p1; - triangles[i].p2 = p2; - triangles[i].p3 = p3; - } - - int* areas = new int[n]; - - - for (int i = 0; i < n; i++) - areas[i] = getArea(triangles[i]); - - selectionSort(areas, triangles, n); - - for (int i = 0; i < n; i++) - print(triangles[i]); - - delete[] triangles; - delete[] areas; + cout << countDivisers(4096) << endl; } diff --git a/Sem. 01/task1/task1.cpp b/Sem. 01/task1/task1.cpp new file mode 100644 index 0000000..67ad5b1 --- /dev/null +++ b/Sem. 01/task1/task1.cpp @@ -0,0 +1,126 @@ +#include +#include + +using namespace std; + + +struct point +{ + int x; + int y; +}; +void print(const point& ptr) +{ + cout << ptr.x << " " << ptr.y << endl; +} +point readPoint() +{ + int x, y; + cin >> x >> y; + return{ x, y }; +} +double getDist(const point& origin, const point& dest) +{ + double dx = origin.x - dest.x; + double dy = origin.y - dest.y; + + return sqrt(dx*dx + dy*dy); +} + + +struct triangle +{ + point p1; + point p2; + point p3; +}; + +double getArea(const triangle& tr) +{ + double sideA = getDist(tr.p1, tr.p2); + double sideB = getDist(tr.p2, tr.p3); + double sideC = getDist(tr.p3, tr.p1); + + double halfP = (sideA + sideB + sideC) / 2; + return sqrt(halfP * (halfP - sideA) * (halfP - sideB) * (halfP - sideC)); + +} + +void print(const triangle& tr) +{ + cout << "Point1: "; + print(tr.p1); + cout << "Point2: "; + print(tr.p2); + cout << "Point3: "; + print(tr.p3); + cout << getArea(tr) << endl << endl; +} + +void swap(int * arr, int i, int j) +{ + int temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; +} +void swap(triangle* arr, int i, int j) +{ + triangle temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; +} +void selectionSort(int* areas, triangle* triangles, int len) +{ + for (int i = 0; i < len-1; i++) + { + int currPos = i; + int min = i; + + for (int j = i; j < len; j++) + { + if (areas[j] < areas[min]) + min = j; + } + + if (min != i) + { + swap(areas, i, min); + swap(triangles, i, min); + } + } +} +int main() +{ + + + int n; + cin >> n; + + triangle* triangles = new triangle[n]; + + for (int i = 0; i < n; i++) + { + point p1 = readPoint(); + point p2 = readPoint(); + point p3 = readPoint(); + + triangles[i].p1 = p1; + triangles[i].p2 = p2; + triangles[i].p3 = p3; + } + + int* areas = new int[n]; + + + for (int i = 0; i < n; i++) + areas[i] = getArea(triangles[i]); + + selectionSort(areas, triangles, n); + + for (int i = 0; i < n; i++) + print(triangles[i]); + + delete[] triangles; + delete[] areas; + +} diff --git a/Sem. 02/selfPrintingTask.cpp b/Sem. 02/selfPrintingTask.cpp deleted file mode 100644 index 862cf07..0000000 --- a/Sem. 02/selfPrintingTask.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include - -using namespace std; - -const int MAX_SIZE = 1024; -int main() -{ - ifstream inputFile("selfPrintingTask.cpp"); - - if (inputFile.fail()) - { - cout << "Error!" << endl; - return -1; - } - - while (!inputFile.eof()) - { - char buff[MAX_SIZE]; - inputFile.getline(buff, MAX_SIZE); - cout << buff << endl; - } - inputFile.close() - - return 0; -} diff --git a/Sem. 02/students.csv b/Sem. 02/students.csv deleted file mode 100644 index 1d7debc..0000000 --- a/Sem. 02/students.csv +++ /dev/null @@ -1,10 +0,0 @@ -Име,Фамилия,"Имейл адрес","Факултетен номер" -Peter,Ivanov,peter@mail.bg,81235 -Alexander,Popov,popov@abv.bg,81234 -Stefan,Velikov,velikov@mail.bg,81876 -Krasimir,Petkov,krasi@abv.bg,81234 -Stefani,Angelova,stef@gmail.com,81876 -Ivana,Marinova,ivana@abv.bg,81321 -Stefan,Velkov,stefan@yahoo.com,80000 -Krasimira,Markova,krasi@mail.bg,81234 -Wladimir,Klitschko,wlad@kiev.com,89999 \ No newline at end of file diff --git a/Sem. 02/studentsDatabase.cpp b/Sem. 02/studentsDatabase.cpp deleted file mode 100644 index 7f9a5f5..0000000 --- a/Sem. 02/studentsDatabase.cpp +++ /dev/null @@ -1,253 +0,0 @@ -#include -#include - -using namespace std; - -const int FIELD_MAX_SIZE = 50; -const int BUFFER_LINE_SIZE = 1024; - -struct OOPstudent -{ - char firstName[FIELD_MAX_SIZE]; - char lastName[FIELD_MAX_SIZE]; - char email[FIELD_MAX_SIZE]; - int fn = 0; - -}; - -int countLines(const char* fileName) -{ - ifstream f(fileName); - if (!f.is_open()) - return -1; - int linesCount = 0; - - while (!f.eof()) - { - char buff[1024]; - f.getline(buff, 1024); - linesCount++; - } - f.close(); - - return linesCount; - -} -// abc,bcd,ab@Abv.bg,fn -void readStudent(const char* input, OOPstudent& student) -{ - int ind = 0; - - // first name - while (input[ind] != ',') - { - student.firstName[ind] = input[ind]; - ind++; - } - student.firstName[ind] = '\0'; - ind++; - - //last name - int lastNameInd = 0; - while (input[ind] != ',') - student.lastName[lastNameInd++] = input[ind++]; - student.lastName[lastNameInd] = '\0'; - ind++; - - //email - int emailInd = 0; - - while (input[ind] != ',') - student.email[emailInd++] = input[ind++]; - student.email[emailInd] = '\0'; - ind++; - - //fn - while (input[ind] != '\0') - (student.fn *= 10) += (input[ind++] - '0'); - -} - -bool saveStudentsToFile(const OOPstudent* studentsCollection, int len, const char* fileName) -{ - ofstream outFile(fileName); - - if (!outFile.is_open()) - return false; - - outFile << "First name, Last name, email, fn" << endl; - - for (int i = 0; i < len; i++) - outFile << studentsCollection[i].firstName << "," << studentsCollection[i].lastName << "," << studentsCollection[i].email << "," << studentsCollection[i].fn << endl; - - outFile.close(); - - return true; -} - -int indexOfFirstSpaceOrTerminatingZero(const char* command) -{ - int ind = 0; - while (*command != ' ' && *command != '\t' && *command != '\0') - { - command++; - ind++; - } - return ind; - -} - -bool printStudent(const OOPstudent* arrayOfStudents, int len, int fn) -{ - for (int i = 0; i < len; i++) - { - if (arrayOfStudents[i].fn == fn) - { - cout << arrayOfStudents[i].firstName << "," << arrayOfStudents[i].lastName << "," << arrayOfStudents[i].email << "," << arrayOfStudents[i].fn << endl; - return true; - } - } - return false; -} -bool editFirstName(OOPstudent* arrayOfStudents, int len, int fn, const char* newFirstName) -{ - for (int i = 0; i < len; i++) - { - if (arrayOfStudents[i].fn == fn) - { - strcpy(arrayOfStudents[i].firstName, newFirstName); - return true; //success! - } - } - return false; //no such student -} -int main() -{ - - cout << "Open file:" << endl << ">"; - - char fileName[BUFFER_LINE_SIZE]; - cin.getline(fileName, BUFFER_LINE_SIZE); - - int studentsCount = countLines(fileName) - 1; // We ignore the first line - - - if (studentsCount <= 0) - { - cout << "Error while reading data from the file " << endl; - return -1; - } - - OOPstudent* studentsCollection = new OOPstudent[studentsCount]; - - - ifstream f(fileName, ios::_Nocreate); - - if (!f.is_open()) - { - cout << "Error!" << endl; - delete[] studentsCollection; - return -1; - } - - int line = 1; - while (!f.eof()) - { - char buff[BUFFER_LINE_SIZE]; - f.getline(buff, BUFFER_LINE_SIZE); - - if (line == 1) - { - line++; - continue; - } - - readStudent(buff, studentsCollection[line - 2]); - line++; - } - f.close(); - - cout << "File successfully opened!" << endl; - - char commandLine[BUFFER_LINE_SIZE]; - do - { - cout << ">"; - cin.getline(commandLine, 1024); - size_t len = strlen(commandLine); - - - - //first argument (edit, save ...) - size_t firstArgSize = indexOfFirstSpaceOrTerminatingZero(commandLine); - char* commandFirstArg = new char[firstArgSize + 1]; - - for (int i = 0; i < firstArgSize; i++) - commandFirstArg[i] = commandLine[i]; - commandFirstArg[firstArgSize] = '\0'; - - - - - if (len == firstArgSize) //no more arguments - quit? Check is bellow - continue; - - //second argument (students.csv, 45543 ...) - size_t secondArgSize = len - firstArgSize - 1; - char* commandSecondArg = new char[secondArgSize + 1]; - - for (int i = 0; i < secondArgSize; i++) - commandSecondArg[i] = commandLine[firstArgSize + 1 + i]; - commandSecondArg[secondArgSize] = '\0'; - if (strcmp(commandFirstArg, "print") == 0) - { - int fn = atoi(commandSecondArg); - - bool res = printStudent(studentsCollection, studentsCount, fn); - - if (!res) - cout << "Student with fn: " << fn << " doesn't exist!" << endl;; - } - else if (strcmp(commandFirstArg, "edit") == 0) - { - int fn = atoi(commandSecondArg); - - //we have a third argument here. It's in the second arguments string - - size_t seprator = indexOfFirstSpaceOrTerminatingZero(commandSecondArg); - - size_t thirdArgumentSize = secondArgSize - seprator; - char* commandThirdArg = new char[thirdArgumentSize + 1]; - - for (int i = 0; i < thirdArgumentSize; i++) - commandThirdArg[i] = commandSecondArg[seprator + 1 + i]; - commandThirdArg[thirdArgumentSize] = '\0'; - - bool result = editFirstName(studentsCollection, studentsCount, fn, commandThirdArg); - - if (result) - cout << "Succesfully changed name!" << endl; - else - cout << "Student with fn: " << fn << "doesn't exist!" << endl; - - delete[] commandThirdArg; - } - else if (strcmp(commandFirstArg, "save") == 0) - { - - bool res = saveStudentsToFile(studentsCollection, studentsCount, commandSecondArg); - - if (res) - cout << "Successfully saved to file: " << commandSecondArg << endl; - else - cout << "Error while saving in file: " << commandSecondArg << endl; - - } - delete[] commandFirstArg; - delete[] commandSecondArg; - - } while (strcmp(commandLine, "Quit")); - - delete[] studentsCollection; - return 0; -} diff --git a/Sem. 02/task1/selfPrintingTask.cpp b/Sem. 02/task1/selfPrintingTask.cpp new file mode 100644 index 0000000..862cf07 --- /dev/null +++ b/Sem. 02/task1/selfPrintingTask.cpp @@ -0,0 +1,26 @@ +#include +#include + +using namespace std; + +const int MAX_SIZE = 1024; +int main() +{ + ifstream inputFile("selfPrintingTask.cpp"); + + if (inputFile.fail()) + { + cout << "Error!" << endl; + return -1; + } + + while (!inputFile.eof()) + { + char buff[MAX_SIZE]; + inputFile.getline(buff, MAX_SIZE); + cout << buff << endl; + } + inputFile.close() + + return 0; +} diff --git a/Sem. 02/task2/students.csv b/Sem. 02/task2/students.csv new file mode 100644 index 0000000..1d7debc --- /dev/null +++ b/Sem. 02/task2/students.csv @@ -0,0 +1,10 @@ +Име,Фамилия,"Имейл адрес","Факултетен номер" +Peter,Ivanov,peter@mail.bg,81235 +Alexander,Popov,popov@abv.bg,81234 +Stefan,Velikov,velikov@mail.bg,81876 +Krasimir,Petkov,krasi@abv.bg,81234 +Stefani,Angelova,stef@gmail.com,81876 +Ivana,Marinova,ivana@abv.bg,81321 +Stefan,Velkov,stefan@yahoo.com,80000 +Krasimira,Markova,krasi@mail.bg,81234 +Wladimir,Klitschko,wlad@kiev.com,89999 \ No newline at end of file diff --git a/Sem. 02/task2/studentsDatabase.cpp b/Sem. 02/task2/studentsDatabase.cpp new file mode 100644 index 0000000..7f9a5f5 --- /dev/null +++ b/Sem. 02/task2/studentsDatabase.cpp @@ -0,0 +1,253 @@ +#include +#include + +using namespace std; + +const int FIELD_MAX_SIZE = 50; +const int BUFFER_LINE_SIZE = 1024; + +struct OOPstudent +{ + char firstName[FIELD_MAX_SIZE]; + char lastName[FIELD_MAX_SIZE]; + char email[FIELD_MAX_SIZE]; + int fn = 0; + +}; + +int countLines(const char* fileName) +{ + ifstream f(fileName); + if (!f.is_open()) + return -1; + int linesCount = 0; + + while (!f.eof()) + { + char buff[1024]; + f.getline(buff, 1024); + linesCount++; + } + f.close(); + + return linesCount; + +} +// abc,bcd,ab@Abv.bg,fn +void readStudent(const char* input, OOPstudent& student) +{ + int ind = 0; + + // first name + while (input[ind] != ',') + { + student.firstName[ind] = input[ind]; + ind++; + } + student.firstName[ind] = '\0'; + ind++; + + //last name + int lastNameInd = 0; + while (input[ind] != ',') + student.lastName[lastNameInd++] = input[ind++]; + student.lastName[lastNameInd] = '\0'; + ind++; + + //email + int emailInd = 0; + + while (input[ind] != ',') + student.email[emailInd++] = input[ind++]; + student.email[emailInd] = '\0'; + ind++; + + //fn + while (input[ind] != '\0') + (student.fn *= 10) += (input[ind++] - '0'); + +} + +bool saveStudentsToFile(const OOPstudent* studentsCollection, int len, const char* fileName) +{ + ofstream outFile(fileName); + + if (!outFile.is_open()) + return false; + + outFile << "First name, Last name, email, fn" << endl; + + for (int i = 0; i < len; i++) + outFile << studentsCollection[i].firstName << "," << studentsCollection[i].lastName << "," << studentsCollection[i].email << "," << studentsCollection[i].fn << endl; + + outFile.close(); + + return true; +} + +int indexOfFirstSpaceOrTerminatingZero(const char* command) +{ + int ind = 0; + while (*command != ' ' && *command != '\t' && *command != '\0') + { + command++; + ind++; + } + return ind; + +} + +bool printStudent(const OOPstudent* arrayOfStudents, int len, int fn) +{ + for (int i = 0; i < len; i++) + { + if (arrayOfStudents[i].fn == fn) + { + cout << arrayOfStudents[i].firstName << "," << arrayOfStudents[i].lastName << "," << arrayOfStudents[i].email << "," << arrayOfStudents[i].fn << endl; + return true; + } + } + return false; +} +bool editFirstName(OOPstudent* arrayOfStudents, int len, int fn, const char* newFirstName) +{ + for (int i = 0; i < len; i++) + { + if (arrayOfStudents[i].fn == fn) + { + strcpy(arrayOfStudents[i].firstName, newFirstName); + return true; //success! + } + } + return false; //no such student +} +int main() +{ + + cout << "Open file:" << endl << ">"; + + char fileName[BUFFER_LINE_SIZE]; + cin.getline(fileName, BUFFER_LINE_SIZE); + + int studentsCount = countLines(fileName) - 1; // We ignore the first line + + + if (studentsCount <= 0) + { + cout << "Error while reading data from the file " << endl; + return -1; + } + + OOPstudent* studentsCollection = new OOPstudent[studentsCount]; + + + ifstream f(fileName, ios::_Nocreate); + + if (!f.is_open()) + { + cout << "Error!" << endl; + delete[] studentsCollection; + return -1; + } + + int line = 1; + while (!f.eof()) + { + char buff[BUFFER_LINE_SIZE]; + f.getline(buff, BUFFER_LINE_SIZE); + + if (line == 1) + { + line++; + continue; + } + + readStudent(buff, studentsCollection[line - 2]); + line++; + } + f.close(); + + cout << "File successfully opened!" << endl; + + char commandLine[BUFFER_LINE_SIZE]; + do + { + cout << ">"; + cin.getline(commandLine, 1024); + size_t len = strlen(commandLine); + + + + //first argument (edit, save ...) + size_t firstArgSize = indexOfFirstSpaceOrTerminatingZero(commandLine); + char* commandFirstArg = new char[firstArgSize + 1]; + + for (int i = 0; i < firstArgSize; i++) + commandFirstArg[i] = commandLine[i]; + commandFirstArg[firstArgSize] = '\0'; + + + + + if (len == firstArgSize) //no more arguments - quit? Check is bellow + continue; + + //second argument (students.csv, 45543 ...) + size_t secondArgSize = len - firstArgSize - 1; + char* commandSecondArg = new char[secondArgSize + 1]; + + for (int i = 0; i < secondArgSize; i++) + commandSecondArg[i] = commandLine[firstArgSize + 1 + i]; + commandSecondArg[secondArgSize] = '\0'; + if (strcmp(commandFirstArg, "print") == 0) + { + int fn = atoi(commandSecondArg); + + bool res = printStudent(studentsCollection, studentsCount, fn); + + if (!res) + cout << "Student with fn: " << fn << " doesn't exist!" << endl;; + } + else if (strcmp(commandFirstArg, "edit") == 0) + { + int fn = atoi(commandSecondArg); + + //we have a third argument here. It's in the second arguments string + + size_t seprator = indexOfFirstSpaceOrTerminatingZero(commandSecondArg); + + size_t thirdArgumentSize = secondArgSize - seprator; + char* commandThirdArg = new char[thirdArgumentSize + 1]; + + for (int i = 0; i < thirdArgumentSize; i++) + commandThirdArg[i] = commandSecondArg[seprator + 1 + i]; + commandThirdArg[thirdArgumentSize] = '\0'; + + bool result = editFirstName(studentsCollection, studentsCount, fn, commandThirdArg); + + if (result) + cout << "Succesfully changed name!" << endl; + else + cout << "Student with fn: " << fn << "doesn't exist!" << endl; + + delete[] commandThirdArg; + } + else if (strcmp(commandFirstArg, "save") == 0) + { + + bool res = saveStudentsToFile(studentsCollection, studentsCount, commandSecondArg); + + if (res) + cout << "Successfully saved to file: " << commandSecondArg << endl; + else + cout << "Error while saving in file: " << commandSecondArg << endl; + + } + delete[] commandFirstArg; + delete[] commandSecondArg; + + } while (strcmp(commandLine, "Quit")); + + delete[] studentsCollection; + return 0; +} diff --git a/Sem. 04/uni_task(not finished).cpp b/Sem. 04/uni_task(not finished).cpp deleted file mode 100644 index 7bf3a70..0000000 --- a/Sem. 04/uni_task(not finished).cpp +++ /dev/null @@ -1,156 +0,0 @@ -#include -#include - -using namespace std; - - -struct Student -{ - char* name; - int fn; - int gradesCount; - double averageGrade; -}; -void print(const Student& st) -{ - cout << st.name << " " << st.fn << " " << st.gradesCount << " " << st.averageGrade << endl; -} -Student createStudent(const char* name, int fn, int gradesCount, double avGrade) -{ - Student obj; - - size_t nameLen = strlen(name); - - obj.name = new char[nameLen + 1]; - strcpy(obj.name, name); - - obj.fn = fn; - obj.gradesCount = gradesCount; - obj.averageGrade = avGrade; - - return obj; -} -void saveStudentToFile(ofstream& f, const Student& st) -{ - size_t nameLen = strlen(st.name); - f.write((const char*)&nameLen, sizeof(nameLen)); //first we write the size of the name! - f.write(st.name, nameLen); - f.write((const char*)&st.fn, sizeof(st.fn)); - f.write((const char*)&st.gradesCount, sizeof(st.gradesCount)); - f.write((const char*)&st.averageGrade, sizeof(st.averageGrade)); - -} -Student readStudentFromFile(ifstream& f) -{ - Student res; - - size_t nameLen; - - f.read((char *)&nameLen, sizeof(nameLen)); //first we read the size of the name! - - res.name = new char[nameLen + 1]; - f.read(res.name, nameLen); - res.name[nameLen] = '\0'; - - f.read((char *)&res.fn, sizeof(res.fn)); - f.read((char*)&res.gradesCount, sizeof(res.gradesCount)); - f.read((char*)&res.averageGrade, sizeof(res.averageGrade)); - - return res; -} -void freeStudent(Student& s) -{ - delete[] s.name; - - s.averageGrade = s.fn = s.gradesCount = 0; - -} - -const int UNI_NAME_MAX = 32; -struct Uni -{ - char name[UNI_NAME_MAX]; - size_t studentsCount; - Student* students; -}; - -void saveUniToFile(ofstream& f, const Uni& uni) -{ - - f.write(uni.name, sizeof(uni.name)); - f.write((const char*)&uni.studentsCount, sizeof(uni.studentsCount)); //first we write how many students we have! - - for (int i = 0; i < uni.studentsCount; i++) - saveStudentToFile(f, uni.students[i]); -} - -void readUniFromFile(ifstream& f, Uni& uni) -{ - f.read(uni.name, sizeof(uni.name)); - f.read((char*) &uni.studentsCount, sizeof(uni.studentsCount)); //we read how many students are saved in the file! - - uni.students = new Student[uni.studentsCount]; - - for (int i = 0; i < uni.studentsCount; i++) - uni.students[i] = readStudentFromFile(f); -} -void freeUni(Uni& uni) -{ - for (int i = 0; i < uni.studentsCount; i++) - freeStudent(uni.students[i]); - strcpy(uni.name, ""); - uni.studentsCount = 0; -} -void print(const Uni& u) -{ - cout << u.name << " " << u.studentsCount << endl; - for (int i = 0; i < u.studentsCount; i++) - print(u.students[i]); -} -int main() -{ - { //Creating an university and saving to file - Uni u; - strcpy(u.name, "FMI"); - u.studentsCount = 3; - - u.students = new Student[u.studentsCount]; - u.students[0] = createStudent("Ivan", 81234, 3, 4.5); - u.students[1] = createStudent("Angel", 12345, 4, 5); - u.students[2] = createStudent("Mariq", 81234, 5, 5.5); - - - ofstream f("uni.dat", ios::binary); - - if (!f.is_open()) - { - cout << "Error" << endl; - return -1; - } - - saveUniToFile(f, u); - freeUni(u); - } - - { //Reading an university from file - - Uni myUni; - ifstream f("uni.dat", ios::binary); - - if (!f.is_open()) - { - cout << "Error" << endl; - return -1; - } - - readUniFromFile(f, myUni); - - print(myUni); - - f.close(); - - freeUni(myUni); - - } -} - diff --git a/Sem. 06/Time/Time.cpp b/Sem. 06/Time/Time.cpp index 65549f7..9cd8620 100644 --- a/Sem. 06/Time/Time.cpp +++ b/Sem. 06/Time/Time.cpp @@ -10,15 +10,15 @@ Time::Time(size_t hours, size_t mins, size_t seconds) setSeconds(seconds); } -size_t Time::getHours() +size_t Time::getHours() const { return hours; } -size_t Time::getMins() +size_t Time::getMins() const { return mins; } -size_t Time::getSeconds() +size_t Time::getSeconds() const { return seconds; } diff --git a/Sem. 07/PersonAdvanced/PersonAdvanced.cpp b/Sem. 07/PersonAdvanced/PersonAdvanced.cpp index fbea6c3..e4e062f 100644 --- a/Sem. 07/PersonAdvanced/PersonAdvanced.cpp +++ b/Sem. 07/PersonAdvanced/PersonAdvanced.cpp @@ -61,4 +61,9 @@ void PersonAdvanced::free() { delete[] name; age = 0; +} + +void PersonAdvanced::print() +{ + std::cout <<"Name: "<< name << ", age: " << age << std::endl; } \ No newline at end of file diff --git a/Sem. 08/Nvector/Source.cpp b/Sem. 08/Nvector/Source.cpp index 332ac22..291b683 100644 --- a/Sem. 08/Nvector/Source.cpp +++ b/Sem. 08/Nvector/Source.cpp @@ -9,6 +9,7 @@ using namespace std; int main() { Nvector v(3); + v[2] = 10; Nvector v2 = 3 * v; cout << v2; diff --git a/Sem. 12/task1/Drinks/AlcoholDrink.cpp b/Sem. 12/task1/Drinks/AlcoholDrink.cpp index 2f61087..4171ff0 100644 --- a/Sem. 12/task1/Drinks/AlcoholDrink.cpp +++ b/Sem. 12/task1/Drinks/AlcoholDrink.cpp @@ -1,3 +1,4 @@ +#pragma warning(disable: 4996) #include "AlcoholDrink.h" AlcoholDrink::AlcoholDrink() : AlcoholDrink("Unknown", 0, 0){} diff --git a/Sem. 12/task1/Drinks/Drink.cpp b/Sem. 12/task1/Drinks/Drink.cpp index 6f41b55..55b3e3a 100644 --- a/Sem. 12/task1/Drinks/Drink.cpp +++ b/Sem. 12/task1/Drinks/Drink.cpp @@ -1,3 +1,4 @@ +#pragma warning(disable: 4996) #include "Drink.h" #include diff --git a/Sem. 12/task1/Drinks/EnergyDrink.cpp b/Sem. 12/task1/Drinks/EnergyDrink.cpp index a8ffac5..ef61456 100644 --- a/Sem. 12/task1/Drinks/EnergyDrink.cpp +++ b/Sem. 12/task1/Drinks/EnergyDrink.cpp @@ -1,3 +1,4 @@ +#pragma warning(disable: 4996) #include "EnergyDrink.h" #include diff --git a/Sem. 12/task1/main.cpp b/Sem. 12/task1/main.cpp index 296f09f..ba367d8 100644 --- a/Sem. 12/task1/main.cpp +++ b/Sem. 12/task1/main.cpp @@ -1,4 +1,7 @@ -#include +#pragma warning(disable: 4996) + + +#include #include "Bar/Bar.h" #include "Drinks/EnergyDrink.h" -- cgit v1.3.1-23-gd82d