Misipuk

KP1_2

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