May 2012
Intermediate to advanced
679 pages
16h 56m
English
Just like data members class also has member functions. We need member functions to access private data members. Let us add two member functions3 (or methods) to the class Date which was declared earlier.
Problem: Write a program to demonstrate the use of public method in accessing private data members.
Solution: See Program 5.2.
// date1.cpp#include<iostream.h>//Class declaration begins hereclass Date{ private : int day, month, year; // data members public : void setDate(int d1,int m1,int y1);// member function or method void showDate(); //member function or method};//Class declaration ends here.//Method definitions are given after function mainint main(){ Date d1; cout<< “<---date1.cpp--->”<<endl; ...
Read now
Unlock full access