Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 02
diff options
context:
space:
mode:
Commit8cf1283a4ffb9fe1901c29c087fa376de82726af (patch)
Author
 angeld55 <angel_dimitriev@abv.bg>
2022-02-19 23:30:52 +0200
Committer
 angeld55 <angel_dimitriev@abv.bg>
2022-02-19 23:30:52 +0200
Filesabdfe6bf526100dcce87a88563100e02adf7605e /Sem. 02
Object-oriented_programming_FMI-8cf1283a4ffb9fe1901c29c087fa376de82726af.tar
Object-oriented_programming_FMI-8cf1283a4ffb9fe1901c29c087fa376de82726af.tar.gz
Object-oriented_programming_FMI-8cf1283a4ffb9fe1901c29c087fa376de82726af.zip
Parentd73a7ec225516657dec74472a0491330e9999217 (diff)
clean up
5 files changed, 0 insertions, 426 deletions
-rw-r--r--Sem. 02/README.md137
-rw-r--r--Sem. 02/notes_02.pdfbin75732 -> 0 bytes
-rw-r--r--Sem. 02/task1/selfPrintingTask.cpp26
-rw-r--r--Sem. 02/task2/students.csv10
-rw-r--r--Sem. 02/task2/studentsDatabase.cpp253
diff --git a/Sem. 02/README.md b/Sem. 02/README.md
deleted file mode 100644
index 1a4c845..0000000
--- a/Sem. 02/README.md
+++ /dev/null
@@ -1,137 +0,0 @@
-## Файлове (част 1). Текстови файлове.
-Видове потоци:
- - Потоци за вход (istream).
- - Потоци за изход (ostream).
-
-##### Пример за работа с поток за вход (cin)
- ```c++
-#include <iostream>
-using namespace std;
-
-int main()
-{
- int a, b;
- cin >> a >> b;
-}
- ```
- Четем от стандартния вход.
-
-##### Пример за работа с поток за изход (cout)
- ```c++
-#include <iostream>
-using namespace std;
-
-int main()
-{
- int a = 10;
- int b = 12;
- int c = a + b;
-
- cout << a << " + " << b << " = " << c << endl;
-}
- ```
-
-### Работа с поток за вход от файл (ifstream)
-Пример за четене от файл!
- ```c++
-#include <iostream>
-#include <fstream>
-using namespace std;
-
-int main()
-{
- ifstream file("myFile.txt");
-
- if (!file.is_open())
- {
- cout << "Error!" << endl;
- return -1;
- }
- int a, b;
-
- file >> a >> b;
-
- file.close();
-}
-```
-Пример за прочитане на цялото съдържание файл:
- ```c++
-#include <iostream>
-#include <fstream>
-using namespace std;
-
-const int BUFF_SIZE = 1024;
-int main()
-{
- ifstream file("myFile.txt");
-
- if (!file.is_open())
- {
- cout << "Error!" << endl;
- return -1;
- }
- while (!file.eof())
- {
- char buff[BUFF_SIZE];
- file.getline(buff, BUFF_SIZE);
-
- //do something with the line
- cout << line << endl;
- }
- file.close();
-}
-```
-### Работа с поток за изход към файл (ofstream)
-
- ```c++
-#include <iostream>
-#include <fstream>
-
-using namespace std;
-
-int main()
-{
- ofstream file("myFile.txt");
-
- if (!file.is_open())
- {
- cout << "Error!" << endl;
- return -1;
- }
- int a = 3;
- int b = 10;
-
- file << a << " " << b << " " << a + b << endl;
-
- if(!file.eof()) //check if the file has ended
- cout << "The file contains more data after the two integers!" << endl;
-
- file.close();
-}
- ```
- ## Задачи
-
-**Задача 1**: Напишете програма, която отпечатва собствения си код.
-
-**Задача 2**: Напишете програма, която чете comma-separated values (**CSV**) файл със студенти **със следните 4 полета**: Първо име, Фамилно име, Имейл, Факултетен номер.
-1. Със стартирането на програмата потребителят да въвежда име на файл, който да бъде зареден в паметта.
-2. Напишете функция, която след зареждане на файла да отпечатва на **стандартния изход** информация за студента при подаден **факултетен номер**.
-3. Напишете функция, която **по подаден факултетен номер и низ**, променя първото име на студента, който има дадения факултетен номер, с подадения низ.
-4. Напишете функцията , която приема низ (име на файл) и запазва студентите в същия формат (**CSV**). Т.е. при повторно пускане на програмата да може да прочете новия генериран файл.
-
-Да се реализира прост интерфейс, с който да се извикват написаните фунцкии през конзолата:
-
-**Пример** (входът от потребителя започва с '>'):
-
- ```
-Open file:
->students.csv
-File successfully opened!
->print 80000
-Name = Stefan Velkov, Email: stefan@yahoo.com, FN: 80000
->edit 80000 Krum
->print 80000
-Name = Krum Velkov, Email: stefan@yahoo.com, FN: 80000
->save students2.csv
-file students2.csv successfully saved!
-```
diff --git a/Sem. 02/notes_02.pdf b/Sem. 02/notes_02.pdf
deleted file mode 100644
index a7372af..0000000
--- a/Sem. 02/notes_02.pdf
+++ /dev/null
Binary files differ
diff --git a/Sem. 02/task1/selfPrintingTask.cpp b/Sem. 02/task1/selfPrintingTask.cpp
deleted file mode 100644
index 862cf07..0000000
--- a/Sem. 02/task1/selfPrintingTask.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#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;
- }
- inputFile.close()
-
- return 0;
-}
diff --git a/Sem. 02/task2/students.csv b/Sem. 02/task2/students.csv
deleted file mode 100644
index 1d7debc..0000000
--- a/Sem. 02/task2/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/task2/studentsDatabase.cpp b/Sem. 02/task2/studentsDatabase.cpp
deleted file mode 100644
index 7f9a5f5..0000000
--- a/Sem. 02/task2/studentsDatabase.cpp
+++ /dev/null
@@ -1,253 +0,0 @@
-#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 = 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;
-}