Professional Documents
Culture Documents
C++ Presentatn
C++ Presentatn
SPECIFIERS
A class is an expanded concept of a data
structure: instead of holding only data, it can
hold both data and functions.
class class_name {
access_specifier_1:
member1;
access_specifier_2:
member2; ...
} object_names;
private members of a class are
accessible only from within other members
of the same class or from their friends.
protected members are accessible from
members of their same class and from
their friends, but also from members of
their derived classes.
Finally, public members are accessible
from anywhere where the object is visible.
PRIVATE
Enter colour:
RED
Inside shape class::
RED
Enter the lenth of cube:
25.0
Volume of cube : 15625
#include<iostream.h>
#include<conio.h>
class shape
{
protected:
char colour[30];
public:
void get_colour()
{
cout<<"Enter colour:\n";
cin>>colour;
cout<<"Inside shape class::\n"<<colour<<endl;
}
};
class two_d : protected
public shape
{
protected:
float s_len;
public:
void get_slen()
{
cout<<"Enter length for square:"<<endl;
cin>>s_len;
}
class three_d:public shape
{
protected: int main()
int c_len; {
public:
void get_clen()
square s;
{ cube c;
cout<<"Enter the lenth of cube:"<<endl; clrscr();
cin>>c_len; s.get_colour();
}
s.get_slen();
};
class cube:public three_d s.get_area();
{ c.get_colour();
protected: c.get_clen();
int c_vol; c.get_volume();
public:
void get_volume()
getch();
{ return 0;
c_vol=(c_len*c_len*c_len); }
cout<<"Volume of cube:"<<c_vol<<endl;
}
};
ERROR IS SHOWN AS: