+ 1
How to define class in cpp??
5 Answers
+ 2
Take this example:
#include<iostream>
using namespace std;
class rectangle
{
private:
int len,br;
public:
void set(int l,int b)
{
len=l;
br=b;
}
void disp()
{
cout<<endl<<len<<endl<<br;
}
};
int main()
{
rectangle r1, r2 ;
r1.set(20,15); //sets the value of r1
r2.set(25,20);
r1.disp();// displayes the len and br of r1
r1 .disp();
return 0;
}
+ 7
It is covered in the lesson:
https://www.sololearn.com/learn/CPlusPlus/1711/
P.S. Specify the language in "Relevant Tags" please ...
+ 1
You should go through the lessons of class and constructer and destructers
0
What is set and disp???
0
set and disp are the function that can only read or write the private variables(len & br).
You can define as many functions as you want or as program requires in the public segment
As for some knowledge The private segment cannot be accessed outside the class,it is called data hiding.