Docsity

C++ Access Specifiers & Abstract Classes: Members, Functions & Inheritance, Exercises of Computer Science

Toggle sidebar
bg1
• From the access specifiers lecture write the code that we saw for private, protected and public
members and run it.
• Write the code given for private functions and run it.
• Create an object myobject and pass value 500 to its setter function and use its getter function to
show data.
/////////////////////////////////////////////////////////////////////////////////////
• From the abstract classess lecture, write the person program to demonstrate pure virtual
functions in your editor and add following code
int main()
{
person p1;
p1.getname();
}
• Run to see the output
/////////////////////////////////////////////////////////////////////////
Add following code in main and run it
int main()
{
student stu; //object of student class
professor prof; //object of professor class
stu.getdata();
stu.putname();
}
pf2

Partial preview of the text

Download C++ Access Specifiers & Abstract Classes: Members, Functions & Inheritance and more Exercises Computer Science in PDF only on Docsity!

  • From the access specifiers lecture write the code that we saw for private, protected and public members and run it.
  • Write the code given for private functions and run it.
  • Create an object myobject and pass value 500 to its setter function and use its getter function to show data.
  • From the abstract classess lecture, write the person program to demonstrate pure virtual functions in your editor and add following code int main() { person p1; p1.getname();

}

  • Run to see the output ///////////////////////////////////////////////////////////////////////// Add following code in main and run it int main() { student stu; //object of student class professor prof; //object of professor class

stu.getdata(); stu.putname(); }

In the line class student : public person change public to private and run the program. In the line class student : public person change public to protected and run the program. If it shows an error note what the error says.

In function getdata of class student, change person::getname() to person.getname(). Run to see output ( REMINDER :: is the scope resolution operator which is used when function is defined in one class and we want to use it in another class. (. operator) is used to access method or variables of an object ) /////////////////////////////////////////////////////////////////////////////////////////////////////////