diff --git a/readme.md b/readme.md index a15e280..81f803a 100644 --- a/readme.md +++ b/readme.md @@ -4,4 +4,4 @@ 所以这里并没有什么好康的东西。 - +里边的变量命名都是作业的设定,别在意 :) diff --git a/20200311.cpp b/test1/20200311-2.cpp similarity index 100% rename from 20200311.cpp rename to test1/20200311-2.cpp diff --git a/test1/20220313-3.cpp b/test1/20220313-3.cpp new file mode 100644 index 0000000..3677d40 --- /dev/null +++ b/test1/20220313-3.cpp @@ -0,0 +1,97 @@ +#include +#include + +using namespace std; + +class CStudent { +public: + int getId() const; + + void setId(int id); + + int getScore() const; + + void setScore(int score); + + CStudent(int id, string name, int score); + + void setName(const string &name); + + const string &getName() const; + + CStudent(const CStudent &source); + + CStudent(); + +private: + int id = 0; + string name; + int score = 0; +}; + +int CStudent::getId() const { + return id; +} + +void CStudent::setId(int id) { + CStudent::id = id; +} + +void CStudent::setName(const string &name) { + CStudent::name = name; +} + +const string &CStudent::getName() const { + return name; +} + +int CStudent::getScore() const { + return score; +} + +void CStudent::setScore(int score) { + CStudent::score = score; +} + +CStudent::CStudent(int id, string name, int score) : id(id), name(name), score(score) {} + +CStudent::CStudent() : id(0), name("name"), score(0) {} + +CStudent::CStudent(const CStudent &source) { + id = source.id; + name = source.name; + score = source.score; +} + +#include + +int main() { + vector students; + + int studentAmount = 0; + cout << "Enter the amount of students: "; + cin >> studentAmount; + + int maxScore = 0; + for (int i = 0; i < studentAmount; ++i) { + int id = 0; + int score = 0; + string name = ""; + + cin >> id >> name >> score; + CStudent student(id, name, score); + students.push_back(student); + + if (maxScore < score) { + maxScore = score; + } + } + + for (const CStudent &student: students) { + if (student.getScore() == maxScore) { + cout << "id: " << student.getId() + << ", name: " << student.getName() + << ", score: " << student.getScore() << endl; + } + } +} diff --git a/test1/20220317-4.cpp b/test1/20220317-4.cpp new file mode 100644 index 0000000..01f6f1b --- /dev/null +++ b/test1/20220317-4.cpp @@ -0,0 +1,38 @@ +#include +#include + +using namespace std; + +class date { +public: + date(const char *NewD); + + date(int NewY, int NewM, int NewD); + + date(); + + void show(); + +private: + int y, m, d; +}; + +date::date(int NewY, int NewM, int NewD) : y(NewY), m(NewM), d(NewD) {} + +date::date(const char *NewD) { + sscanf(NewD, "%d-%d-%d", &y, &m, &d); +} + +void date::show() { + cout << y << '-' << m << '-' << d << endl; +} + +date::date() : y(1970), m(1), d(1){} + +int main() { + date d1, d2(2011, 3, 8), d3("2011-03-19"); + + d1.show(); + d2.show(); + d3.show(); +}