728x90
특별히 어려운 것 없이 통과,
class Person{
private :
string _name;
int _age;
public :
string getName(){return _name;}
int getAge(){return _age;}
void setName(string name){_name = name;}
void setAge(int age) { _age = age;}
virtual void getdata(){};
virtual void putdata(){};
};
static int professor_cur_id = 1;
class Professor : public Person
{
private :
int publications;
int cur_id;
public :
Professor(){
cur_id = professor_cur_id;
professor_cur_id++;
}
void getdata(){
string nameBuf;
int ageBuf;
cin >> nameBuf >> ageBuf >> publications;
setName(nameBuf);
setAge(ageBuf);
};
void putdata(){
cout << getName() << " " << getAge() << " " << publications << " " << cur_id << endl;
};
};
static int student_cur_id = 1;
class Student : public Person
{
private:
int marks[6] = {0,} ;
int cur_id;
public:
Student(){
cur_id = student_cur_id;
student_cur_id++;
}
void getdata(){
string nameBuf;
int ageBuf;
cin >> nameBuf >> ageBuf;
for(int i = 0 ; i < 6; i++)
{
cin >> marks[i];
}
setName(nameBuf);
setAge(ageBuf);
}
void putdata(){
int sum = 0;
for(int element : marks)
{
sum += element;
}
cout << getName() << " " << getAge() << " " << sum << " " << cur_id << endl;
}
};
728x90
'개발 공부 > 알고리즘' 카테고리의 다른 글
HackerRank, c++, Preprocessor Solution (0) | 2022.11.03 |
---|---|
HackerRank, c++, Cpp exception handling (0) | 2022.11.03 |
HackerRank , C++, Hotel Prices (0) | 2022.11.03 |
HackerRank C++, STL, Deque-STL (0) | 2022.11.02 |
hackerrank, c++, Abstract Classes - Polymorphism (2) | 2022.10.25 |