Professional Documents
Culture Documents
Faculty of Engineering
Computer Programming
Lab 10
Dec. 2013
Classes in C++
-
Within the body, the keywords private: and public: specify the access level of the
members of the class << the default is private >>
public
can be accessed outside the class directly.
private
Accessible only to member functions of class.
Circle c;
}
2. Member functions defined inside class
Memberwise Copy
In C++, you can also use the assignment operator = to copy the contents from one object
to the other. By default, each data field of one object is copied to its counterpart in the
other object. For example,
circle2 = circle1; copies the radius in circle1 to circle2. After the copy, circle1 and circle2
are still two different objects, but with the same radius.
Accessor and Mutator
-
A get function is referred to as a getter (or accessor), and a set function is referred
to as a setter (or mutator). A get function has the following signature:
returnType getPropertyName()
Lab work #1
Build a class that handles time parts
1.
2.
3.
4.
5.
Timer.h
6.
Write the code at the main which represent accessing Class Members
int main()
{
Time t1(3,55,54), t2;
t1.printTime();
cout<<"please enter time in hours, minutes and seconds: ";
int x,y,z;
cin>> x >> y >> z;
t2.setHour(x);
t2.setMinute(y);
t2.setSecond(z);
t2.printTime();
system("PAUSE");
return EXIT_SUCCESS;
}
Output
Goood Luck
9