From 7adb051d1638dbb039ced8c34db8bd20bcc2b737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1ndly=20Gerg=C5=91?= Date: Sun, 12 Apr 2020 12:02:41 +0300 Subject: [PATCH] chore: Lab06 --- lab05/tema.cpp | 51 ++++++++++++++++++++++++++++++++++++++ lab06/01.cpp | 36 +++++++++++++++++++++++++++ lab06/02.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 lab05/tema.cpp create mode 100644 lab06/01.cpp create mode 100644 lab06/02.cpp diff --git a/lab05/tema.cpp b/lab05/tema.cpp new file mode 100644 index 0000000..5e90d58 --- /dev/null +++ b/lab05/tema.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include +using namespace std; + +void insertToPlace(list* v, const string* word){ + if(!v->size() || *word < v->front()){ + v->push_front(*word); + return; + } + if(*word == v->front()){ + return; + } + for(list::iterator it = next(v->begin()); it != v->end(); it++){ + if(*word == *it){ + return; + } + if(*word > *prev(it) && *word < *it){ + v->insert(it, *word); + return; + } + } + v->push_back(*word); +} + +int main(){ + ios::sync_with_stdio(false); + + cout<<"Introduce a line: "; + string line; + getline(cin, line); + + list v; + + istringstream sstream(line); + string word; + while(getline(sstream, word, ' ')){ + insertToPlace(&v, &word); + } + + cout<<"Distinct words ordered alphabetically:\n"; + for(list::iterator it = v.begin(); it != v.end(); it++){ + cout<<*it<<"\n"; + } + + cout.flush(); + + return 0; +} diff --git a/lab06/01.cpp b/lab06/01.cpp new file mode 100644 index 0000000..54c9dc0 --- /dev/null +++ b/lab06/01.cpp @@ -0,0 +1,36 @@ +#include +#include +#include +using namespace std; + +int main(){ + ios::sync_with_stdio(false); + + fstream f; + + f.open("examene.txt", ios_base::in); + + if(!f.is_open()){ + cout<<"Error: file does not exist"; + return 1; + } + + int sum=0; + for(int i=0; i<6; i++){ + int buff; + f>>buff; + sum+=buff; + } + + f.close(); + + f.open("media.txt", ios_base::out); + + double avg = (double)sum / 6; + + f< +#include +#include +#include +#include +using namespace std; + +class Student{ +public: + string nume, prenume, grupa; + string stringify(){ + return nume+" "+prenume+" "+grupa; + } +}; + +bool studentCompare(const Student a, const Student b){ + if(a.nume == b.nume){ + if(a.prenume <= b.prenume){ + return true; + } + else{ + return false; + } + } + else if(a.nume <= b.nume){ + return true; + } + else{ + return false; + } +} + +int main(){ + ios::sync_with_stdio(false); + + fstream f; + + f.open("an.txt", ios_base::in); + if(!f.is_open()){ + cout<<"Error: file does not exist"; + return 1; + } + + vector v; + + string buff; + while(f>>buff){ + Student tmp; + tmp.nume = buff; + f>>tmp.prenume; + f>>tmp.grupa; + v.push_back(tmp); + } + f.close(); + + sort(v.begin(), v.end(), studentCompare); + + f.open("an_sort.txt", ios_base::out); + for(vector::iterator it = v.begin(); it < v.end(); it++){ + f<stringify(); + f<<"\n"; + } + f.close(); + + return 0; +}