Skip to content

Instantly share code, notes, and snippets.

@NoharaMasato
Created March 5, 2020 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NoharaMasato/e2c4651af921efbc27a087ba0fab2a92 to your computer and use it in GitHub Desktop.
Save NoharaMasato/e2c4651af921efbc27a087ba0fab2a92 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
enum Gender{male,female};
string gender_to_string(Gender gen){
switch(gen){
case male:
return "男";
case female:
return "女";
}
return "その他";
}
class Human {
protected:
string name;
int age;
Gender gender;
public:
Human(string n, int a, Gender gen);
void show();
};
class Student : public Human {
private:
int score;
string major;
public:
Student(string n, Gender gen, int a, string m);
string ret_name();
void show();
void get_score(int s);
};
class Lab {
private:
string name,place;
vector<Student> students;
public:
Lab(string name,string place);
void change_place(string new_place);
void join(Student new_student);
void leave(Student leave_student);
void show();
};
Student::Student(string n, Gender gen, int a, string m) : Human(n, a, gen){
major = m;
}
void Student::get_score(int s){
score = s;
}
Human::Human(string n, int a, Gender gen){
name = n;
gender = gen;
age = a;
}
void Student::show(){
cout << "【生徒】名前:" << ret_name() << ",性別:" << gender_to_string(gender) << endl;
}
string Student::ret_name(){
return name;
}
void Human::show(){
cout << "【人間】名前:" << name << ",性別:" << gender_to_string(gender) << endl;
}
Lab::Lab(string n,string p){
name = n;
place = p;
}
void Lab::show(){
cout << "=======" << name << "[" << place << "]=======\n" << "【メンバー】" << endl;
if (int(students.size() == 0)){
cout << "まだ誰もいません" << endl;
return;
}
for (auto student : students){
student.show();
}
}
void Lab::change_place(string new_place){
cout << place <<"から" << new_place << "に移動します" << endl;
place = new_place;
}
void Lab::join(Student new_student){
cout << new_student.ret_name() << "という名前の人が入ってきました" << endl;
students.push_back(new_student);
}
void Lab::leave(Student leave_student){
for (auto it = students.begin(); it != students.end();it++) {
if ((*it).ret_name() == leave_student.ret_name()){
students.erase(it);
break;
}
}
}
int main(){
Lab westlab("westlab","25-425");
westlab.show();
Student nohara("nohara",male,22,"science");
Student korosue("korosue",female,22,"science");
Student saiton("saiton",female,22,"science");
westlab.join(nohara);
westlab.join(korosue);
westlab.join(saiton);
westlab.leave(nohara);
westlab.change_place("25-513");
westlab.show();
westlab.leave(saiton);
westlab.show();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment