📖 Samacheer Kalvi · 11th TN - English Medium · Computer Science · Page 239question

Unit IV · Part 2

Chapter 3: 4 · Computer Science

}; class item int prd; }; item int prdno; . . Definition of class members Class comprises of members. Members are classified as Data Members and Member functions.

Data members are the data variables that represent the features or properties of a class. Member functions are the functions that perform specific tasks in a class. Member functions are called as methods, and data members are also called as attributes. Example Class result Private; char name [ ]; int rollno,mark1, mark2, total; Public: void accept(); void display(); }; Member functions Data members Note Classes also contain some special member functions called as constructors and destructors.

. . Defining methods of a class Without defining the methods (functions), class definition will become incomplete. The member functions of a class can be defined in two ways.

( ) Inside the class definition ( ) Outside the class definition ( ) Inside the class definition When a member function is defined inside a class, it behaves like inline functions. These are called Inline member functions. Note If a function is inline, the compiler places a copy of the code at each point where the function is called at compile time. ( ) Outside the class definition When Member function defined outside the class just like normal function definition (Function definitions you are familiar with ) then it is be called as outline member function or non-inline member function.

Scope resolution operator (::) is used for this purpose. The syntax for defining the outline member function is Chapter Page - - Syntax :: (parameter list) function definition For example: Member function Scope resolution operator Data type of the member function Class name / tag void add :: display() # include <iostream> using namespace std; class Box double width; // no access specifier mentioned public: double length; void printWidth( ) //inline member function definition cout<<”\n The width of the box is...”<<width; void setWidth( double w ); //prototype of the function }; void Box :: setWidth(double w) // outline member function definition width=w; int main( ) Box b; // object for class Box b.setWidth( . ); // Use member

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →