From 73498b9b57df952ef1a9118518e4852cf3bce8e0 Mon Sep 17 00:00:00 2001 From: lensferno Date: Wed, 30 Mar 2022 20:30:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E4=BD=9C=E4=B8=9A=EF=BC=9A20220330?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- work20220330/.idea/.gitignore | 8 ++++++++ work20220330/.idea/deployment.xml | 14 ++++++++++++++ work20220330/.idea/encodings.xml | 6 ++++++ work20220330/.idea/misc.xml | 4 ++++ work20220330/.idea/modules.xml | 8 ++++++++ work20220330/.idea/vcs.xml | 6 ++++++ work20220330/.idea/work20220330.iml | 2 ++ work20220330/CMakeLists.txt | 6 ++++++ work20220330/DbTeacher.cpp | 24 +++++++++++++++++++++++ work20220330/DbTeacher.h | 24 +++++++++++++++++++++++ work20220330/Leader.cpp | 21 ++++++++++++++++++++ work20220330/Leader.h | 27 ++++++++++++++++++++++++++ work20220330/Staff.cpp | 23 ++++++++++++++++++++++ work20220330/Staff.h | 28 +++++++++++++++++++++++++++ work20220330/Teacher.cpp | 19 ++++++++++++++++++ work20220330/Teacher.h | 23 ++++++++++++++++++++++ work20220330/date/Date.cpp | 30 +++++++++++++++++++++++++++++ work20220330/date/Date.h | 30 +++++++++++++++++++++++++++++ work20220330/main.cpp | 9 +++++++++ 19 files changed, 312 insertions(+) create mode 100644 work20220330/.idea/.gitignore create mode 100644 work20220330/.idea/deployment.xml create mode 100644 work20220330/.idea/encodings.xml create mode 100644 work20220330/.idea/misc.xml create mode 100644 work20220330/.idea/modules.xml create mode 100644 work20220330/.idea/vcs.xml create mode 100644 work20220330/.idea/work20220330.iml create mode 100644 work20220330/CMakeLists.txt create mode 100644 work20220330/DbTeacher.cpp create mode 100644 work20220330/DbTeacher.h create mode 100644 work20220330/Leader.cpp create mode 100644 work20220330/Leader.h create mode 100644 work20220330/Staff.cpp create mode 100644 work20220330/Staff.h create mode 100644 work20220330/Teacher.cpp create mode 100644 work20220330/Teacher.h create mode 100644 work20220330/date/Date.cpp create mode 100644 work20220330/date/Date.h create mode 100644 work20220330/main.cpp diff --git a/work20220330/.idea/.gitignore b/work20220330/.idea/.gitignore new file mode 100644 index 0000000..1c2fda5 --- /dev/null +++ b/work20220330/.idea/.gitignore @@ -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 diff --git a/work20220330/.idea/deployment.xml b/work20220330/.idea/deployment.xml new file mode 100644 index 0000000..771f492 --- /dev/null +++ b/work20220330/.idea/deployment.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/work20220330/.idea/encodings.xml b/work20220330/.idea/encodings.xml new file mode 100644 index 0000000..4fff3db --- /dev/null +++ b/work20220330/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/work20220330/.idea/misc.xml b/work20220330/.idea/misc.xml new file mode 100644 index 0000000..f1c67df --- /dev/null +++ b/work20220330/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/work20220330/.idea/modules.xml b/work20220330/.idea/modules.xml new file mode 100644 index 0000000..e1b9eca --- /dev/null +++ b/work20220330/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/work20220330/.idea/vcs.xml b/work20220330/.idea/vcs.xml new file mode 100644 index 0000000..2e3f692 --- /dev/null +++ b/work20220330/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/work20220330/.idea/work20220330.iml b/work20220330/.idea/work20220330.iml new file mode 100644 index 0000000..6d70257 --- /dev/null +++ b/work20220330/.idea/work20220330.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/work20220330/CMakeLists.txt b/work20220330/CMakeLists.txt new file mode 100644 index 0000000..cff4015 --- /dev/null +++ b/work20220330/CMakeLists.txt @@ -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) diff --git a/work20220330/DbTeacher.cpp b/work20220330/DbTeacher.cpp new file mode 100644 index 0000000..cf5f6e9 --- /dev/null +++ b/work20220330/DbTeacher.cpp @@ -0,0 +1,24 @@ +// +// Created by lensferno on 2022/3/30. +// + +#include +#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(); +}; diff --git a/work20220330/DbTeacher.h b/work20220330/DbTeacher.h new file mode 100644 index 0000000..3fae44f --- /dev/null +++ b/work20220330/DbTeacher.h @@ -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 diff --git a/work20220330/Leader.cpp b/work20220330/Leader.cpp new file mode 100644 index 0000000..eb10a77 --- /dev/null +++ b/work20220330/Leader.cpp @@ -0,0 +1,21 @@ +// +// Created by lensferno on 2022/3/30. +// + +#include +#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) {} diff --git a/work20220330/Leader.h b/work20220330/Leader.h new file mode 100644 index 0000000..38e08ee --- /dev/null +++ b/work20220330/Leader.h @@ -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 diff --git a/work20220330/Staff.cpp b/work20220330/Staff.cpp new file mode 100644 index 0000000..1fc14a5 --- /dev/null +++ b/work20220330/Staff.cpp @@ -0,0 +1,23 @@ +// +// Created by lensferno on 2022/3/30. +// + +#include +#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(); +} + diff --git a/work20220330/Staff.h b/work20220330/Staff.h new file mode 100644 index 0000000..73eb41b --- /dev/null +++ b/work20220330/Staff.h @@ -0,0 +1,28 @@ +// +// Created by lensferno on 2022/3/30. +// + +#ifndef WORK20220330_STAFF_H +#define WORK20220330_STAFF_H + +#include +#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 diff --git a/work20220330/Teacher.cpp b/work20220330/Teacher.cpp new file mode 100644 index 0000000..962c292 --- /dev/null +++ b/work20220330/Teacher.cpp @@ -0,0 +1,19 @@ +// +// Created by lensferno on 2022/3/30. +// + +#include +#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) {} diff --git a/work20220330/Teacher.h b/work20220330/Teacher.h new file mode 100644 index 0000000..3999359 --- /dev/null +++ b/work20220330/Teacher.h @@ -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 diff --git a/work20220330/date/Date.cpp b/work20220330/date/Date.cpp new file mode 100644 index 0000000..36c5d5e --- /dev/null +++ b/work20220330/date/Date.cpp @@ -0,0 +1,30 @@ +#include +#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(); +} \ No newline at end of file diff --git a/work20220330/date/Date.h b/work20220330/date/Date.h new file mode 100644 index 0000000..9393301 --- /dev/null +++ b/work20220330/date/Date.h @@ -0,0 +1,30 @@ +#ifndef WORK20220325_DATE_H +#define WORK20220325_DATE_H + +#include + +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 diff --git a/work20220330/main.cpp b/work20220330/main.cpp new file mode 100644 index 0000000..0f53e8f --- /dev/null +++ b/work20220330/main.cpp @@ -0,0 +1,9 @@ +#include +#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; +}