-
Notifications
You must be signed in to change notification settings - Fork 0
/
Repo.h
107 lines (92 loc) · 1.69 KB
/
Repo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#pragma once
#include "Melodii.h"
#include <vector>
#include <fstream>
class repo {
vector<melodie> melodii;
string fisier;
public:
repo(string fisier_)
{
fisier = fisier_;
ifstream f(fisier);
int a, d;
string b, c;
while (f >> a >> b >> c >> d)
{
melodie m(a, b, c, d);
melodii.push_back(m);
}
bool ok = true;
while (ok)
{
ok = false;
for (int i = 0; i < melodii.size() - 1; i++)
if (melodii[i].rank > melodii[i + 1].rank)
{
melodie aux = melodii[i];
melodii[i] = melodii[i + 1];
melodii[i + 1] = aux;
ok = true;
}
}
}
void Sorteaza_Lista()
{
bool ok = true;
while (ok)
{
ok = false;
for (int i = 0; i < melodii.size() - 1; i++)
if (melodii[i].rank > melodii[i + 1].rank)
{
melodie aux = melodii[i];
melodii[i] = melodii[i + 1];
melodii[i + 1] = aux;
ok = true;
}
}
/// scriem inapoi in fisier
ofstream g(fisier);
for (auto& x : melodii)
g << x.id << " " << x.titlu << " " << x.artist << " " << x.rank << endl;
}
vector<melodie> get_list()
{
return melodii;
}
void modifica(int id,int rank_nou,string titlu_nou)
{
for (auto& x : melodii)
if (x.id == id)
{
x.titlu = titlu_nou;
x.rank = rank_nou;
break;
}
}
string sterge(int id)
{
string autor;
int ind = -1;
for (int i=0;i<melodii.size();i++)
if (melodii[i].id == id)
{
autor = melodii[i].artist;
ind = i;
break;
}
int count = 0;
for (auto& x : melodii)
if (x.artist == autor)
count++;
if (count > 1)
{
for (int i = ind; i < melodii.size() - 1; i++)
melodii[i] = melodii[i + 1];
melodii.pop_back();
return "";
}
return "LAST_SONG";
}
};