parent
							
								
									2ce480443b
								
							
						
					
					
						commit
						73498b9b57
					
				@ -0,0 +1,8 @@ | 
				
			||||
# Default ignored files | 
				
			||||
/shelf/ | 
				
			||||
/workspace.xml | 
				
			||||
# Editor-based HTTP Client requests | 
				
			||||
/httpRequests/ | 
				
			||||
# Datasource local storage ignored files | 
				
			||||
/dataSources/ | 
				
			||||
/dataSources.local.xml | 
				
			||||
@ -0,0 +1,14 @@ | 
				
			||||
<?xml version="1.0" encoding="UTF-8"?> | 
				
			||||
<project version="4"> | 
				
			||||
  <component name="PublishConfigData" remoteFilesAllowedToDisappearOnAutoupload="false"> | 
				
			||||
    <serverData> | 
				
			||||
      <paths name="remote_linux (563cc454-127a-4c53-a847-5bf281087bb1)"> | 
				
			||||
        <serverdata> | 
				
			||||
          <mappings> | 
				
			||||
            <mapping local="$PROJECT_DIR$" web="/" /> | 
				
			||||
          </mappings> | 
				
			||||
        </serverdata> | 
				
			||||
      </paths> | 
				
			||||
    </serverData> | 
				
			||||
  </component> | 
				
			||||
</project> | 
				
			||||
@ -0,0 +1,6 @@ | 
				
			||||
<?xml version="1.0" encoding="UTF-8"?> | 
				
			||||
<project version="4"> | 
				
			||||
  <component name="Encoding"> | 
				
			||||
    <file url="file://$PROJECT_DIR$/date" charset="GBK" /> | 
				
			||||
  </component> | 
				
			||||
</project> | 
				
			||||
@ -0,0 +1,4 @@ | 
				
			||||
<?xml version="1.0" encoding="UTF-8"?> | 
				
			||||
<project version="4"> | 
				
			||||
  <component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" /> | 
				
			||||
</project> | 
				
			||||
@ -0,0 +1,8 @@ | 
				
			||||
<?xml version="1.0" encoding="UTF-8"?> | 
				
			||||
<project version="4"> | 
				
			||||
  <component name="ProjectModuleManager"> | 
				
			||||
    <modules> | 
				
			||||
      <module fileurl="file://$PROJECT_DIR$/.idea/work20220330.iml" filepath="$PROJECT_DIR$/.idea/work20220330.iml" /> | 
				
			||||
    </modules> | 
				
			||||
  </component> | 
				
			||||
</project> | 
				
			||||
@ -0,0 +1,6 @@ | 
				
			||||
<?xml version="1.0" encoding="UTF-8"?> | 
				
			||||
<project version="4"> | 
				
			||||
  <component name="VcsDirectoryMappings"> | 
				
			||||
    <mapping directory="$PROJECT_DIR$/.." vcs="Git" /> | 
				
			||||
  </component> | 
				
			||||
</project> | 
				
			||||
@ -0,0 +1,2 @@ | 
				
			||||
<?xml version="1.0" encoding="UTF-8"?> | 
				
			||||
<module classpath="CMake" type="CPP_MODULE" version="4" /> | 
				
			||||
@ -0,0 +1,6 @@ | 
				
			||||
cmake_minimum_required(VERSION 3.21) | 
				
			||||
project(work20220330) | 
				
			||||
 | 
				
			||||
set(CMAKE_CXX_STANDARD 14) | 
				
			||||
 | 
				
			||||
add_executable(work20220330 main.cpp Leader.cpp Leader.h Staff.cpp Staff.h date/Date.h date/Date.cpp Teacher.cpp Teacher.h DbTeacher.cpp DbTeacher.h) | 
				
			||||
@ -0,0 +1,24 @@ | 
				
			||||
//
 | 
				
			||||
// Created by lensferno on 2022/3/30.
 | 
				
			||||
//
 | 
				
			||||
 | 
				
			||||
#include <sstream> | 
				
			||||
#include "DbTeacher.h" | 
				
			||||
 | 
				
			||||
 | 
				
			||||
DbTeacher::DbTeacher(const Staff &staff, const std::string &title, const std::string &job, | 
				
			||||
                     int salary) : Teacher(staff, title), Leader(staff, job), Staff(staff), salary(salary) {} | 
				
			||||
 | 
				
			||||
DbTeacher::DbTeacher(const DbTeacher &dbTeacher) : Teacher(dbTeacher), Leader(dbTeacher), Staff(dbTeacher), | 
				
			||||
                                                   salary(dbTeacher.salary) {} | 
				
			||||
 | 
				
			||||
std::string DbTeacher::toString() { | 
				
			||||
    std::stringstream output; | 
				
			||||
    output | 
				
			||||
            << "--> as leader:" << '\n' | 
				
			||||
            << Leader::toString() << '\n' | 
				
			||||
            << "--> as teacher:" << '\n' | 
				
			||||
            << Teacher::toString() << '\n' | 
				
			||||
            << "in DbTeacher:\nsalary:" << salary; | 
				
			||||
    return output.str(); | 
				
			||||
}; | 
				
			||||
@ -0,0 +1,24 @@ | 
				
			||||
//
 | 
				
			||||
// Created by lensferno on 2022/3/30.
 | 
				
			||||
//
 | 
				
			||||
 | 
				
			||||
#ifndef WORK20220330_DBTEACHER_H | 
				
			||||
#define WORK20220330_DBTEACHER_H | 
				
			||||
 | 
				
			||||
 | 
				
			||||
#include "Leader.h" | 
				
			||||
#include "Teacher.h" | 
				
			||||
 | 
				
			||||
class DbTeacher : public Teacher, public Leader{ | 
				
			||||
private: | 
				
			||||
    int salary; | 
				
			||||
 | 
				
			||||
public: | 
				
			||||
    DbTeacher(const Staff &staff, const std::string &title, const std::string &job, int salary); | 
				
			||||
    DbTeacher(const DbTeacher &dbTeacher); | 
				
			||||
    DbTeacher() = delete; | 
				
			||||
    std::string toString(); | 
				
			||||
}; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
#endif //WORK20220330_DBTEACHER_H
 | 
				
			||||
@ -0,0 +1,21 @@ | 
				
			||||
//
 | 
				
			||||
// Created by lensferno on 2022/3/30.
 | 
				
			||||
//
 | 
				
			||||
 | 
				
			||||
#include <sstream> | 
				
			||||
#include "Leader.h" | 
				
			||||
 | 
				
			||||
Leader::Leader(const std::string &name, char sex, const std::string &phone, const Date &birthday, | 
				
			||||
               const std::string &job) : Staff(name, sex, phone, birthday), job(job) {} | 
				
			||||
 | 
				
			||||
Leader::Leader(const Staff &staff, const std::string &job) : Staff(staff), job(job) {} | 
				
			||||
 | 
				
			||||
std::string Leader::toString() { | 
				
			||||
    std::stringstream out; | 
				
			||||
    out | 
				
			||||
            << Staff::toString() << '\n' | 
				
			||||
            << "job: " << job << '\n'; | 
				
			||||
    return out.str(); | 
				
			||||
} | 
				
			||||
 | 
				
			||||
Leader::Leader(const Leader &leader) : Staff(leader), job(leader.job) {} | 
				
			||||
@ -0,0 +1,27 @@ | 
				
			||||
//
 | 
				
			||||
// Created by lensferno on 2022/3/30.
 | 
				
			||||
//
 | 
				
			||||
 | 
				
			||||
#ifndef WORK20220330_LEADER_H | 
				
			||||
#define WORK20220330_LEADER_H | 
				
			||||
 | 
				
			||||
 | 
				
			||||
#include "Staff.h" | 
				
			||||
 | 
				
			||||
class Leader : virtual public Staff { | 
				
			||||
protected: | 
				
			||||
    std::string job; | 
				
			||||
 | 
				
			||||
public: | 
				
			||||
 | 
				
			||||
    Leader(const std::string &name, char sex, const std::string &phone, const Date &birthday, const std::string &job); | 
				
			||||
 | 
				
			||||
    Leader(const Staff &staff, const std::string &job); | 
				
			||||
 | 
				
			||||
    Leader(const Leader &leader); | 
				
			||||
 | 
				
			||||
    std::string toString(); | 
				
			||||
}; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
#endif //WORK20220330_LEADER_H
 | 
				
			||||
@ -0,0 +1,23 @@ | 
				
			||||
//
 | 
				
			||||
// Created by lensferno on 2022/3/30.
 | 
				
			||||
//
 | 
				
			||||
 | 
				
			||||
#include <sstream> | 
				
			||||
#include "Staff.h" | 
				
			||||
 | 
				
			||||
Staff::Staff(const std::string &name, char sex, const std::string &phone, const Date &birthday) : | 
				
			||||
        name(name), sex(sex), phone(phone), | 
				
			||||
        birthday(birthday) {} | 
				
			||||
 | 
				
			||||
Staff::Staff(const Staff &staff) : name(staff.name), sex(staff.sex), phone(staff.phone), birthday(staff.birthday) {} | 
				
			||||
 | 
				
			||||
std::string Staff::toString() { | 
				
			||||
    std::stringstream output; | 
				
			||||
    output | 
				
			||||
            << "name: " << name << '\n' | 
				
			||||
            << "sex: " << sex << '\n' | 
				
			||||
            << "phone: " << phone << '\n' | 
				
			||||
            << "birthday: " << birthday.toString(); | 
				
			||||
    return output.str(); | 
				
			||||
} | 
				
			||||
 | 
				
			||||
@ -0,0 +1,28 @@ | 
				
			||||
//
 | 
				
			||||
// Created by lensferno on 2022/3/30.
 | 
				
			||||
//
 | 
				
			||||
 | 
				
			||||
#ifndef WORK20220330_STAFF_H | 
				
			||||
#define WORK20220330_STAFF_H | 
				
			||||
 | 
				
			||||
#include <string> | 
				
			||||
#include "date/Date.h" | 
				
			||||
 | 
				
			||||
class Staff { | 
				
			||||
protected: | 
				
			||||
    std::string name; | 
				
			||||
    char sex; | 
				
			||||
    std::string phone; | 
				
			||||
    Date birthday; | 
				
			||||
public: | 
				
			||||
    Staff(const std::string &name, char sex, const std::string &phone, const Date &birthday); | 
				
			||||
 | 
				
			||||
    Staff(const Staff &staff); | 
				
			||||
 | 
				
			||||
    Staff() = delete; | 
				
			||||
 | 
				
			||||
    std::string toString(); | 
				
			||||
}; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
#endif //WORK20220330_STAFF_H
 | 
				
			||||
@ -0,0 +1,19 @@ | 
				
			||||
//
 | 
				
			||||
// Created by lensferno on 2022/3/30.
 | 
				
			||||
//
 | 
				
			||||
 | 
				
			||||
#include <sstream> | 
				
			||||
#include "Teacher.h" | 
				
			||||
 | 
				
			||||
Teacher::Teacher(const Staff &staff, const std::string &title) : Staff(staff), title(title) {} | 
				
			||||
 | 
				
			||||
std::string Teacher::toString() { | 
				
			||||
    std::stringstream out; | 
				
			||||
    out | 
				
			||||
            << Staff::toString() << '\n' | 
				
			||||
            << "title: " << title << '\n'; | 
				
			||||
 | 
				
			||||
    return out.str(); | 
				
			||||
} | 
				
			||||
 | 
				
			||||
Teacher::Teacher(const Teacher &teacher) : Staff(teacher), title(teacher.title) {} | 
				
			||||
@ -0,0 +1,23 @@ | 
				
			||||
//
 | 
				
			||||
// Created by lensferno on 2022/3/30.
 | 
				
			||||
//
 | 
				
			||||
 | 
				
			||||
#ifndef WORK20220330_TEACHER_H | 
				
			||||
#define WORK20220330_TEACHER_H | 
				
			||||
 | 
				
			||||
 | 
				
			||||
#include "Staff.h" | 
				
			||||
 | 
				
			||||
class Teacher : public virtual Staff { | 
				
			||||
protected: | 
				
			||||
    std::string title; | 
				
			||||
public: | 
				
			||||
    Teacher(const Staff &staff, const std::string &title); | 
				
			||||
 | 
				
			||||
    Teacher(const Teacher &teacher); | 
				
			||||
 | 
				
			||||
    std::string toString(); | 
				
			||||
}; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
#endif //WORK20220330_TEACHER_H
 | 
				
			||||
@ -0,0 +1,30 @@ | 
				
			||||
#include <sstream> | 
				
			||||
#include "Date.h" | 
				
			||||
 | 
				
			||||
Date::Date(int year, int month, int day) : year(year), month(month), day(day) {} | 
				
			||||
 | 
				
			||||
Date::Date(const Date &date) : year(date.year),month(date.month), day(date.day) {} | 
				
			||||
 | 
				
			||||
int Date::getYear() const { | 
				
			||||
    return year; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
int Date::getMonth() const { | 
				
			||||
    return month; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
int Date::getDay() const { | 
				
			||||
    return day; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
void Date::setDate(int year, int month, int day) { | 
				
			||||
    Date::year = year; | 
				
			||||
    Date::month = month; | 
				
			||||
    Date::day = day; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
std::string Date::toString() const { | 
				
			||||
    std::stringstream output; | 
				
			||||
    output << year << '-' << month << '-' << day; | 
				
			||||
    return output.str(); | 
				
			||||
} | 
				
			||||
@ -0,0 +1,30 @@ | 
				
			||||
#ifndef WORK20220325_DATE_H | 
				
			||||
#define WORK20220325_DATE_H | 
				
			||||
 | 
				
			||||
#include <string> | 
				
			||||
 | 
				
			||||
class Date { | 
				
			||||
private: | 
				
			||||
    int year; | 
				
			||||
    int month; | 
				
			||||
    int day; | 
				
			||||
public: | 
				
			||||
    Date(int year, int month, int day); | 
				
			||||
 | 
				
			||||
    Date() = delete; | 
				
			||||
 | 
				
			||||
    Date(const Date &date); | 
				
			||||
 | 
				
			||||
    int getYear() const; | 
				
			||||
 | 
				
			||||
    int getMonth() const; | 
				
			||||
 | 
				
			||||
    int getDay() const; | 
				
			||||
 | 
				
			||||
    void setDate(int year, int month, int day); | 
				
			||||
 | 
				
			||||
    std::string toString() const; | 
				
			||||
}; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
#endif //WORK20220325_DATE_H
 | 
				
			||||
@ -0,0 +1,9 @@ | 
				
			||||
#include <iostream> | 
				
			||||
#include "DbTeacher.h" | 
				
			||||
 | 
				
			||||
int main() { | 
				
			||||
    Staff basicInformation("dbt", 'M', "17388293849", Date(2002, 6, 9)); | 
				
			||||
    DbTeacher dbTeacher(basicInformation, "unknown title", "unknown job", 11234); | 
				
			||||
    std::cout << dbTeacher.toString(); | 
				
			||||
    return 0; | 
				
			||||
} | 
				
			||||
					Loading…
					
					
				
		Reference in new issue