fork download
  1. #include <iostream>
  2. #include <array>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. class AcademicDiscipline {
  7. string Name;
  8. int NumberOfSem;
  9. string LessonType;
  10. int Hours;
  11. string ControlType;
  12. array <string, 3> Instructors;
  13.  
  14. public:
  15. AcademicDiscipline(string Name, int NumberOfSem, string LessonType, int Hours, string ControlType,
  16. array <string, 3> Instructor):
  17. Name(Name), NumberOfSem(NumberOfSem), LessonType(LessonType), Hours(Hours), ControlType(ControlType),
  18. Instructors(Instructor)
  19. {
  20. }
  21.  
  22. AcademicDiscipline(const AcademicDiscipline &other) {
  23. *this = other;
  24. }
  25.  
  26. string getName() const {
  27. return Name;
  28. }
  29.  
  30. int getSemNumber() const {
  31. return NumberOfSem;
  32. }
  33.  
  34. string getLessonType() const {
  35. return LessonType;
  36. }
  37.  
  38. int getHours() const {
  39. return Hours;
  40. }
  41.  
  42. string getControlType() const {
  43. return ControlType;
  44. }
  45.  
  46. string getInstructors() const {
  47. string result;
  48. // for(int i =0; i<Instructors.size(); i++)
  49. // {
  50. // result += Instructors[i] + '; ';
  51. // }
  52. for(auto &elem: Instructors)
  53. { result += "Name: " + elem + "; ";}
  54. return result;
  55. }
  56.  
  57. AcademicDiscipline& operator=(const AcademicDiscipline& other){
  58. if (this != &other) {
  59. this->Name = other.Name;
  60. this->NumberOfSem = other.NumberOfSem;
  61. this->LessonType = other.LessonType;
  62. this->Hours = other.Hours;
  63. this->ControlType = other.ControlType;
  64. this->Instructors = other.Instructors;
  65. }
  66. return *this;
  67. }
  68.  
  69. bool operator==(const AcademicDiscipline& other){
  70. bool res;
  71. if (this -> Name == other.Name and this -> NumberOfSem == other.NumberOfSem)
  72. {
  73. res = true;
  74. }
  75. res = false;
  76.  
  77. return res;
  78. }
  79.  
  80. bool operator !=(const AcademicDiscipline& other) {
  81. return !(*this == other);
  82. }
  83.  
  84. ostream& operator << (ostream& os, const AcademicDiscipline &obj) {
  85. os << "Discipline: " << obj.getName() << ", Number of semester: " << obj.getSemNumber();
  86. os << "\nLesson type" << obj.getLessonType() << ", Control type: " << obj.getControlType();
  87. os << "\nAmount of hours: " << obj.getHours();
  88. os << "\nInstructors: " << obj.getInstructors();
  89. return os;
  90. }
  91.  
  92. void AddInstructor(string NewName){
  93. Instructors.fill(NewName);
  94. }
  95.  
  96. void CorrectInstructor(string PrevName, string NewName){
  97. for (auto &elem: Instructors){
  98. if (elem.data() == PrevName){
  99. elem = NewName;
  100. }
  101.  
  102. }
  103. }
  104.  
  105. ~AcademicDiscipline(){
  106.  
  107. }
  108.  
  109. };
  110.  
  111. int main(){
  112.  
  113. array <string,3> proff;
  114. proff.fill("Ivanov Ivan Ivanovich");
  115. proff.fill("Petrov Petr Petrovich");
  116.  
  117. string disc_name = "C++";
  118. string lesson = "lection";
  119. string control = "exam";
  120.  
  121. AcademicDiscipline disc(disc_name, 1, lesson, 60, control, proff);
  122.  
  123. AcademicDiscipline yet_another_disc(disc);
  124.  
  125. cout << disc;
  126.  
  127. disc.AddInstructor("Semenov Semen Semenovich");
  128. disc.CorrectInstructor("Petrov Petr Petrovich", "Sidorov Sidor Sidorovich");
  129.  
  130.  
  131. int res;
  132. cin >> res;
  133. return res;
  134. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from prog.cpp:2:
In file included from /usr/bin/../lib/gcc/i586-linux-gnu/4.9/../../../../include/c++/4.9/array:35:
/usr/bin/../lib/gcc/i586-linux-gnu/4.9/../../../../include/c++/4.9/bits/c++0x_warning.h:32:2: error: This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support for the \
 ^
prog.cpp:12:5: error: unknown type name 'array'
    array <string, 3> Instructors;
    ^
prog.cpp:12:11: error: expected member name or ';' after declaration specifiers
    array <string, 3> Instructors;
    ~~~~~ ^
prog.cpp:16:24: error: unknown type name 'array'
                       array <string, 3> Instructor):
                       ^
prog.cpp:16:30: error: expected ')'
                       array <string, 3> Instructor):
                             ^
prog.cpp:15:23: note: to match this '('
    AcademicDiscipline(string Name, int NumberOfSem, string LessonType, int Hours, string ControlType,
                      ^
prog.cpp:84:14: error: overloaded 'operator<<' must be a binary operator (has 3 parameters)
    ostream& operator << (ostream& os, const AcademicDiscipline  &obj) {
             ^
prog.cpp:18:25: error: use of undeclared identifier 'Instructor'; did you mean 'AddInstructor'?
            Instructors(Instructor)
                        ^~~~~~~~~~
                        AddInstructor
prog.cpp:92:10: note: 'AddInstructor' declared here
    void AddInstructor(string NewName){
         ^
prog.cpp:18:13: error: member initializer 'Instructors' does not name a non-static data member or base class
            Instructors(Instructor)
            ^~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:52:13: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
        for(auto &elem: Instructors)
            ^
prog.cpp:52:23: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
        for(auto &elem: Instructors)
                      ^
prog.cpp:52:25: error: use of undeclared identifier 'Instructors'; did you mean 'getInstructors'?
        for(auto &elem: Instructors)
                        ^~~~~~~~~~~
                        getInstructors
prog.cpp:46:12: note: 'getInstructors' declared here
    string getInstructors() const {
           ^
prog.cpp:52:25: error: reference to non-static member function must be called; did you mean to call it with no arguments?
        for(auto &elem: Instructors)
                        ^~~~~~~~~~~
                                   ()
prog.cpp:53:30: warning: adding 'char' to a string does not append to the string [-Wstring-plus-int]
        { result += "Name: " + elem + "; ";}
                    ~~~~~~~~~^~~~~~
prog.cpp:53:30: note: use array indexing to silence this warning
        { result += "Name: " + elem + "; ";}
                             ^
                    &        [     ]
prog.cpp:53:37: error: invalid operands to binary expression ('const char *' and 'const char *')
        { result += "Name: " + elem + "; ";}
                    ~~~~~~~~~~~~~~~ ^ ~~~~
prog.cpp:64:19: error: no member named 'Instructors' in 'AcademicDiscipline'
            this->Instructors = other.Instructors;
            ~~~~  ^
prog.cpp:64:39: error: no member named 'Instructors' in 'AcademicDiscipline'
            this->Instructors = other.Instructors;
                                ~~~~~ ^
prog.cpp:93:9: error: use of undeclared identifier 'Instructors'; did you mean 'getInstructors'?
        Instructors.fill(NewName);
        ^~~~~~~~~~~
        getInstructors
prog.cpp:46:12: note: 'getInstructors' declared here
    string getInstructors() const {
           ^
prog.cpp:93:9: error: reference to non-static member function must be called; did you mean to call it with no arguments?
        Instructors.fill(NewName);
        ^~~~~~~~~~~
                   ()
prog.cpp:93:21: error: no member named 'fill' in 'std::basic_string<char>'
        Instructors.fill(NewName);
        ~~~~~~~~~~~ ^
prog.cpp:97:13: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
       for (auto &elem: Instructors){
            ^
prog.cpp:97:23: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
       for (auto &elem: Instructors){
                      ^
prog.cpp:97:25: error: use of undeclared identifier 'Instructors'; did you mean 'getInstructors'?
       for (auto &elem: Instructors){
                        ^~~~~~~~~~~
                        getInstructors
prog.cpp:46:12: note: 'getInstructors' declared here
    string getInstructors() const {
           ^
prog.cpp:97:25: error: reference to non-static member function must be called; did you mean to call it with no arguments?
       for (auto &elem: Instructors){
                        ^~~~~~~~~~~
                                   ()
prog.cpp:98:20: error: member reference base type 'char' is not a structure or union
           if (elem.data() ==  PrevName){
               ~~~~^~~~~
fatal error: too many errors emitted, stopping now [-ferror-limit=]
5 warnings and 20 errors generated.
stdout
Standard output is empty