diff --git a/.gitignore b/.gitignore index aebedde..c26ed17 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,6 @@ .idea/**/dbnavigator.xml # CMake -cmake-build-*/ \ No newline at end of file +cmake-build-*/ + +out/ \ No newline at end of file diff --git a/work20220325/.idea/encodings.xml b/work20220325/.idea/encodings.xml new file mode 100644 index 0000000..214ac02 --- /dev/null +++ b/work20220325/.idea/encodings.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/work20220325/CMakeLists.txt b/work20220325/CMakeLists.txt index 6937c04..a8b7a4e 100644 --- a/work20220325/CMakeLists.txt +++ b/work20220325/CMakeLists.txt @@ -2,5 +2,5 @@ cmake_minimum_required(VERSION 3.21) project(work20220325) set(CMAKE_CXX_STANDARD 14) - +add_compile_options(-finput-charset=GBK -fexec-charset=GBK) add_executable(work20220325 main.cpp person/Person.cpp person/Person.h date/Date.cpp date/Date.h person/students/Student.cpp person/students/Student.h person/teachers/Teacher.cpp person/teachers/Teacher.h person/students/Graduate.cpp person/students/Graduate.h date/Date.cpp date/Date.h person/students/Student.cpp person/students/Student.h person/teachers/Teacher.cpp person/teachers/Teacher.h person/students/Graduate.cpp person/students/Graduate.h person/students/TeachAssistant.cpp person/students/TeachAssistant.h) diff --git a/work20220325/main.cpp b/work20220325/main.cpp new file mode 100644 index 0000000..4ac5782 --- /dev/null +++ b/work20220325/main.cpp @@ -0,0 +1,29 @@ +#include +#include "person/Person.h" +#include "person/students/Graduate.h" +#include "person/students/TeachAssistant.h" + +int main() { + /* + * 因为这里的代码用到了中文,所以代码文件编码设置成了GBK,而不是UTF8(呜呜呜) + * 所以请设置好编译器及控制台相关选项,以免运行时输出乱码 + * 该项目为CMake项目,为运行方便建议使用VStudio或者clion等支持cmake的IDE打开本项目(已测试过) + */ + + // to avoid garbled when output Chinese character + // 防止中文乱码 + setlocale(LC_ALL, "zh-CN"); + + Person baseInformation("id233333", "Lag Seeing", Person::SEX_MALE, "ident23333", Date(2002, 9, 6)); + + Person adviserBaseInformation("id0000000", "Goos Suede", Person::SEX_MALE, "ident000000", Date(1992, 1, 1)); + Teacher adviser(adviserBaseInformation, "导师", "BEE-HIVE"); + + TeachAssistant teachAssistant(121, baseInformation, "不知道什么专业", adviser, "助教", "BEE-HIVE"); + + std::cout << teachAssistant.toString() << '\n'; + + std::cout << "\nover. If Chinese character can't be display correctly, please check the file encoding. (GBK)\n"; + + return 0; +} diff --git a/work20220325/person/Person.cpp b/work20220325/person/Person.cpp index 20c446e..9304d43 100644 --- a/work20220325/person/Person.cpp +++ b/work20220325/person/Person.cpp @@ -1,22 +1,22 @@ -#include -#include -#include "Person.h" - -Person::Person(const std::string& id, const std::string &name, char sex, const std::string &identNumber, - const Date &birthday) : id(id), name(name), sex(sex), identNumber(identNumber), birthday(birthday) {} - -Person::Person(const Person &person) : id(person.id), name(person.name), sex(person.sex), - identNumber(person.identNumber), - birthday(person.birthday) {} - -std::string Person::toString() { - std::stringstream output; - output - << "缂栧彿锛" << id << '\n' - << "濮撳悕锛" << name << '\n' - << "鎬у埆锛" << sex << '\n' - << "韬唤璇佸彿锛" << identNumber << '\n' - << "鍑虹敓鏃ユ湡锛" << birthday.toString() << '\n'; - - return output.str(); -} +#include +#include +#include "Person.h" + +Person::Person(const std::string& id, const std::string &name, char sex, const std::string &identNumber, + const Date &birthday) : id(id), name(name), sex(sex), identNumber(identNumber), birthday(birthday) {} + +Person::Person(const Person &person) : id(person.id), name(person.name), sex(person.sex), + identNumber(person.identNumber), + birthday(person.birthday) {} + +std::string Person::toString() { + std::stringstream output; + output + << "编号:" << id << '\n' + << "姓名:" << name << '\n' + << "性别:" << sex << '\n' + << "身份证号:" << identNumber << '\n' + << "出生日期:" << birthday.toString(); + + return output.str(); +} diff --git a/work20220325/person/students/Graduate.cpp b/work20220325/person/students/Graduate.cpp index cc8255e..10b002c 100644 --- a/work20220325/person/students/Graduate.cpp +++ b/work20220325/person/students/Graduate.cpp @@ -15,8 +15,8 @@ Graduate::Graduate(const Graduate &graduate) : subject(graduate.subject), advise std::string Graduate::toString() { std::stringstream output; output << Student::toString() << '\n' - << "涓撲笟锛" << subject << '\n' - << "瀵煎笀锛歿 \n" << adviser.toString() << " \n}" << '\n'; + << "专业:" << subject << '\n' + << "导师:{ \n" << adviser.toString() << " \n}" << '\n'; return output.str(); } diff --git a/work20220325/person/students/Student.cpp b/work20220325/person/students/Student.cpp index 0cff4c1..bfc26f6 100644 --- a/work20220325/person/students/Student.cpp +++ b/work20220325/person/students/Student.cpp @@ -18,7 +18,7 @@ std::string Student::toString() { std::stringstream output; output << Person::toString() << '\n' - << "鐝骇锛" << classId; + << "班级:" << classId; return output.str(); } diff --git a/work20220325/person/students/TeachAssistant.cpp b/work20220325/person/students/TeachAssistant.cpp index bd5f7a7..7174e4a 100644 --- a/work20220325/person/students/TeachAssistant.cpp +++ b/work20220325/person/students/TeachAssistant.cpp @@ -7,9 +7,9 @@ TeachAssistant::TeachAssistant(int classId, const Person &person, const std::str std::string TeachAssistant::toString() { std::stringstream output; - output << "[鐮旂┒鐢熻韩浠戒俊鎭痌" << '\n' + output << "[研究生身份信息]" << '\n' << Graduate::toString() << '\n' - << "[鏁欏笀韬唤淇℃伅]" << '\n' + << "[教师身份信息]" << '\n' << Teacher::toString(); return output.str(); } \ No newline at end of file diff --git a/work20220325/person/teachers/Teacher.cpp b/work20220325/person/teachers/Teacher.cpp index dc98778..aa80323 100644 --- a/work20220325/person/teachers/Teacher.cpp +++ b/work20220325/person/teachers/Teacher.cpp @@ -9,8 +9,8 @@ Teacher::Teacher(const Teacher &teacher) : department(teacher.department), job(t std::string Teacher::toString() { std::stringstream output; output << Person::toString() + '\n' - << "閮ㄩ棬锛" << department << '\n' - << "鑱屽姟" << job << '\n'; + << "部门:" << department << '\n' + << "职务:" << job; return output.str(); } \ No newline at end of file