C++/c++

Advertisement


Question
sir last time you gave clarification for abstraction.thank you.
now my question is again abstraction.i do not know whether this doubt is correct or not.but i am asking you.
suppose i write the code like this
class student
{
private:
int rollno;
int age;
public:
void get()
{
cout<<"enter roll no"<<endl;
cin<<rollno;
cout<<enter age";
cin>>age;
}
void show()
{
cout<<"roll no="<<rollno<<"age="<<age<<endl;
}
};
void main()
{
student s;
clrscr();
s.read();
s.show();
getch();
}
in this programme how can i expect abstraction.which details are hidden?which are essential features?how many of them are shown?please tell.

Answer
Hello

I would say that the student class is an abstraction of a real living student because it reduces the details of the real student down to only the details important to the computer program. That is one way of looking at it.

The age and rollnumber are hidden and and accessed only by the member functions read and show. That is called data hiding, but also helps in abstraction because it hides implementation.

Note that storing age is not such a good idea because age is always changing. It is better to store birthdate and calculate age when needed.

Best regards
Zlatko

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Zlatko

Expertise

No longer taking questions.

Experience

No longer taking questions.

Education/Credentials
No longer taking questions.

©2016 About.com. All rights reserved.