Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <string>
- #include <vector>
- #include <stdarg.h>
- #include <algorithm>
- using namespace std;
- class CD{
- vector<string> compositions;
- public:
- string name;
- CD(string name)
- {
- this->name = name;
- }
- ~CD(){compositions.clear();}
- vector<string>::iterator begin()
- {
- return compositions.begin();
- }
- vector<string>::iterator end()
- {
- return compositions.end();
- }
- string pick(int i)
- {
- return compositions[i];
- }
- int getSize(){
- return compositions.size();
- }
- void add(string title)
- {
- compositions.push_back(title);
- }
- void pop(string title){
- compositions.erase(find(compositions.begin(), compositions.end(), title));
- }
- void print(){
- if (compositions.size() > 0)
- cout << name + ": \n" << endl;
- for(int i = 0; i < (int)compositions.size(); i++)
- cout << " -" << compositions[i] << endl;
- }
- };
- bool operator < (CD a, CD b)
- {
- int n = a.getSize();
- if (n > b.getSize())
- return false;
- if (n < b.getSize())
- return true;
- for(int i = 0; i < n; ++i)
- {
- if (a.pick(i) == b.pick(i))
- continue;
- if (a.pick(i) < b.pick(i))
- return true;
- return false;
- }
- }
- bool operator == (CD a, CD b){
- if (a.getSize() != b.getSize())
- return false;
- sort(a.begin(), a.end());
- sort(b.begin(), b.end());
- int n = a.getSize();
- for(int i = 0; i < n; ++i)
- if (a.pick(i) != b.pick(i))
- return false;
- return true;
- }
- class Catalog{
- vector<CD> cd;
- public:
- Catalog(){}
- ~Catalog(){cd.clear();}
- void add(CD cd){
- this->cd.push_back(cd);
- }
- void pop(CD cd){
- this->cd.erase(find(this->cd.begin(), this->cd.end(), cd));
- }
- void pop_track(string CD_name, string trackName){
- int n = cd.size();
- for(int i = 0; i < n; ++i)
- if (cd[i].name == CD_name)
- cd[i].pop(trackName);
- }
- void print(){
- int n = cd.size();
- for(int i = 0; i < n; i++)
- {
- cd[i].print();
- cout << endl;
- }
- }
- void print(string CD_name){
- int n = cd.size();
- for(int i = 0; i < n; ++i)
- if (cd[i].name == CD_name)
- cd[i].print();
- }
- };
- int main()
- {
- Catalog myCatalog;
- CD Noize("Noize"), Letov("Letov");
- Noize.add("Sea");
- Noize.add("Work");
- Letov.add("Def");
- myCatalog.add(Noize);
- myCatalog.add(Letov);
- myCatalog.print();
- cout << endl << endl;
- myCatalog.pop_track("Noize", "Sea");
- myCatalog.print();
- cout << endl << endl;
- myCatalog.print("Noize");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement