반응형
https://www.hackerrank.com/challenges/virtual-functions/problem
class Person
{
public:
virtual void getdata()=0;
virtual void putdata() const=0;
protected:
int age;
std::string name;
};
class Professor : public Person
{
public:
void getdata()
{
cin>>name>>age>>publications;
cur_id=++id;
}
void putdata() const
{
cout<<name<<' '<<age<<' '<<publications<<' '<<cur_id<<endl;
}
private:
int publications;
int cur_id;
static int id;
};
int Professor::id=0;
class Student : public Person
{
public:
void getdata()
{
cin>>name>>age;
cur_id=++id;
for(int i=0;i<6;i++)
{
cin>>mark[i];
sum+=mark[i];
}
}
void putdata() const
{
cout<<name<<' '<<age<<' '<<sum<<' '<<cur_id<<endl;
}
private:
int mark[6];
int cur_id;
static int id;
int sum=0;
};
int Student::id=0;
반응형
'C++' 카테고리의 다른 글
[HackerRank]Vector-Erase-Easy (0) | 2019.10.29 |
---|---|
[HackerRank]Vector-Sort - Easy (0) | 2019.10.29 |
[HackerRank] Exceptional Server - Easy (0) | 2019.10.25 |
[HackerRank] Inherited Code - Easy (0) | 2019.10.25 |
[HackerRank] Box it! - easy (0) | 2019.10.23 |
댓글