Advertisement
Misipuk

KP1_bUp

Oct 25th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.13 KB | None | 0 0
  1. #include <conio.h>
  2. #include <cstdio>
  3. #include <time.h>
  4. #include <string.h>
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. class Date{
  10.     private:
  11.         int day;
  12.         int month;
  13.         int year;
  14.  
  15.     public:
  16.         Date(){
  17.             time_t t=time(NULL);
  18.             struct tm* aTm = localtime(&t);
  19.             day=aTm->tm_mday;
  20.             month=aTm->tm_mon+1;
  21.             year=aTm->tm_year+1900;
  22.         }
  23.  
  24.         ~Date(){}
  25.  
  26.         Date(int d, int m, int y){
  27.             day = d;
  28.             month = m;
  29.             year = y;
  30.         }
  31.  
  32.         Date(const Date &d){
  33.             day=d.day;
  34.             month=d.month;
  35.             year=d.year;
  36.         }
  37.  
  38.         int getDay(){
  39.             return day;
  40.         }
  41.  
  42.         Date& setDay(int d){
  43.             day = d;
  44.             return *this;
  45.         }
  46.  
  47.         int getMonth(){
  48.             return month;
  49.         }
  50.  
  51.         Date& setMonth(int m){
  52.             month = m;
  53.             return *this;
  54.         }
  55.  
  56.         int getYear(){
  57.             return year;
  58.         }
  59.  
  60.         Date& setYear(int y){
  61.             year = y;
  62.             return *this;
  63.         }
  64.  
  65.         void printDate(){
  66.             printf("Date: %02d.%02d.%02d\n", day, month, year);
  67.         }
  68. };
  69.  
  70. enum Type {instrumental,vocal, stishok, proza};
  71.  
  72. class Artist{
  73.     private:
  74.         char* name;
  75.         char* surname;
  76.  
  77.     public:
  78.         Artist(){
  79.             name = "Null";
  80.             surname = "Null";
  81.         }
  82.  
  83.         Artist(char* n, char* m){
  84.             name = new char[strlen(n)+1];
  85.             surname = new char[strlen(m)+1];
  86.             strcpy(name, n);
  87.             strcpy(surname, m);
  88.         }
  89.  
  90.         Artist(const Artist &a){
  91.             name = new char[strlen(a.name)+1];
  92.             surname = new char[strlen(a.surname)+1];
  93.             strcpy(name, a.name);
  94.             strcpy(surname, a.surname);
  95.         }
  96.  
  97.         ~Artist(){}
  98.  
  99.         char* getName(){
  100.             return name;
  101.         }
  102.  
  103.         char* getSurname(){
  104.             return surname;
  105.         }
  106.  
  107.         Artist& setName(char* n){
  108.             name = new char[strlen(n)+1];
  109.             strcpy(name, n);
  110.             cout << name << " " << n << endl;
  111.             return *this;
  112.         }
  113.  
  114.         Artist& setSurname(char* n){
  115.             surname = new char[strlen(n)+1];
  116.             strcpy(surname, n);
  117.             return *this;
  118.         }
  119.  
  120.         void printInfo(){
  121.             cout << "Name: " << name << endl;
  122.             cout << "Surname: " << surname << endl;
  123.         }
  124. };
  125.  
  126. class Scene{
  127.     private:
  128.         Type type;
  129.         Artist* artist;
  130.         int dur;
  131.         char* title;
  132.  
  133.     public:
  134.         Scene(){
  135.             type = stishok;
  136.             artist = new Artist();
  137.             title = "Null";
  138.             dur = 0;
  139.         }
  140.  
  141.         Scene(Type ty, Artist* a, char* t, int d){
  142.             type = ty;
  143.             artist = a;
  144.             title = new char[strlen(t)+1];
  145.             strcpy(title, t);
  146.             dur = d;
  147.         }
  148.  
  149.         Scene(const Scene& sc){
  150.             type = sc.type;
  151.             artist = sc.artist;
  152.             title = sc.title;
  153.             dur = sc.dur;
  154.         }
  155.  
  156.         ~Scene(){}
  157.  
  158.         void printInfo(){
  159.             switch(type){
  160.             case(instrumental):
  161.                 {
  162.                     cout << "Type: " << "Instrumental" << endl;
  163.                     break;
  164.                 }
  165.             case(vocal):
  166.                 {
  167.                     cout << "Type: " << "Vocal" << endl;
  168.                     break;
  169.                 }
  170.             case(stishok):
  171.                 {
  172.                     cout << "Type: " << "Stishok" << endl;
  173.                     break;
  174.                 }
  175.             case(proza):
  176.                 {
  177.                     cout << "Type: " << "Proza" << endl;
  178.                     break;
  179.                 }
  180.             }
  181.             cout << "Title: " << title << endl;
  182.             cout << "Artist info: " << endl;
  183.             artist->printInfo();
  184.             cout << "Duration: " << dur << endl;
  185.         }
  186.  
  187.         char* getTitle(){
  188.             return title;
  189.         }
  190.  
  191.         Scene& setTitle(char* t){
  192.             title = new char[strlen(t)+1];
  193.             strcpy(title, t);
  194.             return *this;
  195.         }
  196.  
  197.         Type getType(){
  198.             return type;
  199.         }
  200.  
  201.         Scene& setType(Type t){
  202.             type = t;
  203.             return *this;
  204.         }
  205.  
  206.         Artist* getArtist(){
  207.             return artist;
  208.         }
  209.  
  210.         Scene& setArtist(Artist* a){
  211.             artist = a;
  212.             return *this;
  213.         }
  214.  
  215.         int getDur(){
  216.             return dur;
  217.         }
  218.  
  219.         Scene& setDur(int d){
  220.             dur = d;
  221.             return *this;
  222.         }
  223.  
  224. };
  225.  
  226. class Concert{
  227.     private:
  228.         char* org;
  229.         Date date;
  230.         Scene* scenes;
  231.         int cnt;
  232.     public:
  233.         Concert(){
  234.             org = "Null";
  235.             date = Date();
  236.             cnt = 0;
  237.         }
  238.  
  239.         Concert(char* o, Date& d, Scene* sc, int c){
  240.             org = new char[strlen(o)+1];
  241.             strcpy(org, o);
  242.             date = Date(d);
  243.             cnt = c;
  244.             scenes = new Scene[cnt];
  245.             for(int i=0; i<cnt; i++){
  246.                 scenes[i] = sc[i];
  247.             }
  248.         }
  249.  
  250.         Concert(Concert const &c){
  251.             org = new char[strlen(c.org)+1];
  252.             strcpy(org, c.org);
  253.             date = c.date;
  254.             cnt = c.cnt;
  255.             scenes = new Scene[cnt];
  256.             for(int i=0; i<cnt; i++){
  257.                 scenes[i] = c.scenes[i];
  258.             }
  259.         }
  260.  
  261.         ~Concert(){}
  262.  
  263.         char* getOrg(){
  264.             return org;
  265.         }
  266.  
  267.         Concert& setOrg(char* o){
  268.             org = new char[strlen(o)+1];
  269.             strcpy(org, o);
  270.             return *this;
  271.         }
  272.  
  273.         Date& getDate(){
  274.             return date;
  275.         }
  276.  
  277.         Concert& setDate(Date d){
  278.             date = d;
  279.             return *this;
  280.         }
  281.  
  282.         Scene* getScenes(){
  283.             return scenes;
  284.         }
  285.  
  286.         Concert& setScenes(int c, Scene* sc){
  287.             cnt = c;
  288.             scenes = new Scene[cnt];
  289.             for(int i=0; i<cnt; i++){
  290.                 scenes[i] = sc[i];
  291.             }
  292.             return *this;
  293.         }
  294.  
  295.         int getCount(){
  296.             return cnt;
  297.         }
  298.  
  299.         Concert& addOne(const Scene& sc){
  300.             Scene* newScenes = new Scene[cnt+1];
  301.             for (int i=0; i<cnt; i++){
  302.                 newScenes[i] = scenes[i];
  303.             }
  304.             newScenes[cnt] = sc;
  305.             cnt++;
  306.             scenes = new Scene[cnt];
  307.             for(int i=0; i<cnt; i++){
  308.                 scenes[i] = newScenes[i];
  309.             }
  310.             return *this;
  311.         }
  312.  
  313.         void printInfo(){
  314.             cout << "Org: " << org << endl;
  315.             for (int i=0; i<cnt; i++){
  316.                 cout << "Scene " << i+1 << ":" << endl;
  317.                 scenes[i].printInfo();
  318.                 cout << endl;
  319.             }
  320.             cout << "Date: ";
  321.             date.printDate();
  322.             cout << "Count: " << cnt << endl;
  323.         }
  324.  
  325.         void shortInfo(){
  326.             cout << "Org: " << org << endl;
  327.             for (int i=0; i<cnt; i++){
  328.                 cout << "Title:" << scenes[i].getTitle() << endl;
  329.                 cout << "Duration: " << scenes[i].getDur() << endl;
  330.                 cout << endl;
  331.             }
  332.         }
  333.  
  334. };
  335.  
  336. int main()
  337. {
  338. //    cout << "<< Date example >>" << endl;
  339.     Date d;
  340. //    d.printDate();
  341. //    cout << endl;
  342. //    cout << "<< Artist example >>" << endl;
  343.     Artist* a = new Artist("Vasya", "Pupkin");
  344. //    a->printInfo();
  345. //    cout << endl;
  346. //    cout << "<< Scene example >>" << endl;
  347.     Scene sc1(stishok, a, "Yeah1", 1);
  348.     sc1.printInfo();
  349. //    cout << endl;
  350.     a->setName("Vasiok");
  351. //    sc1.printInfo();
  352. //    cout << endl;
  353.     Scene sc2(proza, a, "Yeah2", 2);
  354.     Scene sc3(stishok, a, "Yeah3", 3);
  355.     Scene sc4(sc3);
  356.     sc1.printInfo();
  357.     Scene scs[3] = {sc1,sc2,sc3};
  358.     cout << endl;
  359.     cout << "<< Concert example >>" << endl;
  360.     Concert* c = new Concert("Slava", d, scs, 3);
  361.     c->printInfo();
  362.     return 0;
  363. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement