Classes and Objects
Classes and Objects
Lecture 03
Member Functions
Member functions are functions that are included within a class
There are two member functions in smallobj: setdata() and showdata().
Defining Objects
smallobj s1, s2; //defines two objects, s1 and s2, of class smallobj
This strange syntax is used to call a member function that is associated with a specific
object
setdata(1066); // error
Using the Objects and Calling the
Member functions
class smallobj //define a class
{
private:
int somedata; //data member
public:
void setdata(int d) //member function to set data
{ somedata = d; }
void showdata() //member function to display data
{ cout << “Data is “ << somedata << endl; }
};
Defining Objects
smallobj s1, s2;
//defines two objects, s1
and s2, of class smallobj
int main()
{
smallobj s1, s2; //define two objects of class smallobj
s1.setdata(1066); //call member function to set data
s2.setdata(1776);
s1.showdata(); //call member function to display data
s2.showdata();
return 0;
}
The Unified Modeling Language
(UML)
• The UML is a graphical “language” for
modeling computer programs