0% found this document useful (0 votes)
31 views2 pages

Functions in Your Editor and Add Following Code

The document provides a series of coding exercises related to access specifiers (private, protected, public) and abstract classes in C++. It instructs the reader to: 1) Write and run code demonstrating private, protected, and public access specifiers. 2) Write and run code for private functions. 3) Create an object and pass a value to its setter function to display via its getter. 4) Write code for an abstract base class "person" and derived classes "student" and "professor", and run/modify the code, noting any errors.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

Functions in Your Editor and Add Following Code

The document provides a series of coding exercises related to access specifiers (private, protected, public) and abstract classes in C++. It instructs the reader to: 1) Write and run code demonstrating private, protected, and public access specifiers. 2) Write and run code for private functions. 3) Create an object and pass a value to its setter function to display via its getter. 4) Write code for an abstract base class "person" and derived classes "student" and "professor", and run/modify the code, noting any errors.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

 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)

/////////////////////////////////////////////////////////////////////////////////////////////////////////

You might also like