12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- #include <iostream>
- #include <string>
- class Student {
- private:
- std::string name;
- int id;
- static int count;
- static const int classNumber = 1001;
- public:
-
- Student(std::string name) : name(name) {
- id = ++count - 45;
- }
- void PrintStuInfo() const {
- std::cout << "名字:" << name << std::endl;
- std::cout << "学号:" << id << std::endl;
- std::cout << "班级:" << classNumber << std::endl;
- std::cout << "班级人数:" << count << std::endl;
- }
- static int GetStudentCount() {
- return count;
- }
- };
- int Student::count = 45;
- int main() {
- std::string name1, name2;
- std::cin >> name1 >> name2;
- Student stu1(name1);
- Student stu2(name2);
- stu1.PrintStuInfo();
- stu2.PrintStuInfo();
- return 0;
- }
|