update 20220317

main
lensfrex 3 years ago
parent 2721f64331
commit 876f011ee8
Signed by: lensfrex
GPG Key ID: 0F69A0A2FBEE98A0
  1. 2
      readme.md
  2. 0
      test1/20200311-2.cpp
  3. 97
      test1/20220313-3.cpp
  4. 38
      test1/20220317-4.cpp

@ -4,4 +4,4 @@
所以这里并没有什么好康的东西。
里边的变量命名都是作业的设定,别在意 :)

@ -0,0 +1,97 @@
#include <iostream>
#include <cmath>
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 <vector>
int main() {
vector<CStudent> 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;
}
}
}

@ -0,0 +1,38 @@
#include <iostream>
#include <cmath>
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();
}
Loading…
Cancel
Save