第二次作业。
This commit is contained in:
40
OOP/02/Exercise01.cpp
Normal file
40
OOP/02/Exercise01.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <iostream>
|
||||
|
||||
class Student {
|
||||
private:
|
||||
int ID, grade;
|
||||
|
||||
public:
|
||||
Student() {
|
||||
this->ID = 0;
|
||||
this->grade = 0;
|
||||
};
|
||||
|
||||
Student(int newID, int newGrade) : ID(newID), grade(newGrade){};
|
||||
|
||||
void display();
|
||||
|
||||
void set(int, int);
|
||||
};
|
||||
|
||||
void Student::display() {
|
||||
std::cout << "ID: " << this->ID << ", Grade: " << this->grade << std::endl;
|
||||
}
|
||||
|
||||
void Student::set(int newID, int newGrade) {
|
||||
this->ID = newID;
|
||||
this->grade = newGrade;
|
||||
}
|
||||
|
||||
int main() {
|
||||
Student stu[5];
|
||||
stu[0].set(21394,89);
|
||||
stu[1].set(2394888, 100);
|
||||
stu[2].set(299, 70);
|
||||
stu[3].set(3999, 10);
|
||||
stu[4].set(4999, 60);
|
||||
stu[0].display();
|
||||
stu[2].display();
|
||||
stu[4].display();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user