Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
4 files changed, 202 insertions, 0 deletions
-rw-r--r--Sem. 02/README.md52
-rw-r--r--Sem. 02/notes_02.pdfbin0 -> 75732 bytes
-rw-r--r--Sem. 02/selfPrintingTask.cpp26
-rw-r--r--Sem. 02/studentsDatabase.cpp124
diff --git a/Sem. 02/README.md b/Sem. 02/README.md
new file mode 100644
index 0000000..b59d8ac
--- /dev/null
+++ b/Sem. 02/README.md
@@ -0,0 +1,52 @@
+
+
+## Сруктури
+
+Структурите в C++ се използват за групиране на елементи. Елементите, наричани още членове, могат да бъдат от различен тип и с различна дължина.
+
+ struct Box
+ {
+ int height;
+ int weight;
+ }
+
+
+### Деклариране на обекти от новия тип
+
+ Box b; //default values to height and weight
+
+ Box b2 = {3, 4} // height = 3, weight = 3;
+
+ Box b3;
+ b3.height = 13;
+ b3.weight = 14;
+
+
+### Подаване във функции
+Ако няма да променяме обекта го подаваме по **константна референция.**
+
+ void calculcateArea(const Box& b)
+ {
+ return b.height * b.weight;
+ }
+ Може и само по **референция**, но тогава промените ще се отразят върху подадения аргумент.
+
+
+ void readBox(Box& b)
+ {
+ cin >> b.height >> b.weight;
+ }
+.Може и да го подаваме по **копие**.
+
+ Box revertBox(Box b)
+ {
+ int temp = b.height;
+ b.height = b.weight;
+ b.weight = temp;
+
+ return b;
+ }
+**Задача**:
+Вход: Въвежда се цяло число **N** и после **N** тригъгълника в равнината, определени от 3 точки ( 6 координати).
+
+Отпечатайте тригълниците **сортирани по лицата им.** \ No newline at end of file
diff --git a/Sem. 02/notes_02.pdf b/Sem. 02/notes_02.pdf
new file mode 100644
index 0000000..a7372af
--- /dev/null
+++ b/Sem. 02/notes_02.pdf
Binary files differ
diff --git a/Sem. 02/selfPrintingTask.cpp b/Sem. 02/selfPrintingTask.cpp
new file mode 100644
index 0000000..e269707
--- /dev/null
+++ b/Sem. 02/selfPrintingTask.cpp
@@ -0,0 +1,26 @@
+#include <iostream>
+#include <fstream>
+
+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;
+ }
+
+
+ return 0;
+} \ No newline at end of file
diff --git a/Sem. 02/studentsDatabase.cpp b/Sem. 02/studentsDatabase.cpp
new file mode 100644
index 0000000..ba3e420
--- /dev/null
+++ b/Sem. 02/studentsDatabase.cpp
@@ -0,0 +1,124 @@
+#include <iostream>
+#include <fstream>
+
+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;
+
+};
+
+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';
+
+ //fn
+ //??
+}
+
+void saveStudentsToFile(const OOPstudent* studentsCollection,int len, const char* fileName)
+{
+ ofstream outFile(fileName);
+
+ if (!outFile.is_open())
+ return;
+
+ for (int i = 0; i < len; i++)
+ outFile << studentsCollection[i].firstName << " " << studentsCollection[i].lastName << " " << studentsCollection[i].email << endl;
+
+ outFile.close();
+}
+
+int main()
+{
+
+ int studentsCount = countLines("students.csv") - 1; // We ignore the first line
+
+ OOPstudent* studentsCollection = new OOPstudent[studentsCount];
+
+ ifstream f("students.csv");
+
+ 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();
+
+
+ //Do stuff
+
+ saveStudentsToFile(studentsCollection, studentsCount, "result.txt");
+
+
+
+
+ delete[] studentsCollection;
+ return 0;
+} \ No newline at end of file