A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B_Tutorial%2FClass%2Fclass_combination</id>
		<title>C++ Tutorial/Class/class combination - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B_Tutorial%2FClass%2Fclass_combination"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B_Tutorial/Class/class_combination&amp;action=history"/>
		<updated>2026-04-17T23:55:53Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B_Tutorial/Class/class_combination&amp;diff=2333&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B_Tutorial/Class/class_combination&amp;diff=2333&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:17Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B_Tutorial/Class/class_combination&amp;diff=2334&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B_Tutorial/Class/class_combination&amp;diff=2334&amp;oldid=prev"/>
				<updated>2010-05-25T10:29:29Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Demonstrating composition--an object with member objects==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
#include &amp;lt;cstring&amp;gt; &lt;br /&gt;
using std::strlen;&lt;br /&gt;
using std::strncpy;&lt;br /&gt;
&lt;br /&gt;
class Date &lt;br /&gt;
{&lt;br /&gt;
public:&lt;br /&gt;
   Date( int = 1, int = 1, int = 1900 );&lt;br /&gt;
   void print() const; &lt;br /&gt;
   ~Date(); &lt;br /&gt;
private:&lt;br /&gt;
   int month; &lt;br /&gt;
   int day; &lt;br /&gt;
   int year;&lt;br /&gt;
};&lt;br /&gt;
Date::Date( int mn, int dy, int yr )&lt;br /&gt;
{&lt;br /&gt;
   month = mn;&lt;br /&gt;
   year = yr;&lt;br /&gt;
   day = dy );&lt;br /&gt;
}&lt;br /&gt;
void Date::print() const&lt;br /&gt;
{&lt;br /&gt;
   cout &amp;lt;&amp;lt; month &amp;lt;&amp;lt; &amp;quot;/&amp;quot; &amp;lt;&amp;lt; day &amp;lt;&amp;lt; &amp;quot;/&amp;quot; &amp;lt;&amp;lt; year; &lt;br /&gt;
}&lt;br /&gt;
Date::~Date()&lt;br /&gt;
{ &lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Date object destructor for date &amp;quot;;&lt;br /&gt;
   cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
class Employee&lt;br /&gt;
{&lt;br /&gt;
public:&lt;br /&gt;
   Employee( const char * const, const char * const, &lt;br /&gt;
      const Date &amp;amp;, const Date &amp;amp; );&lt;br /&gt;
   void print() const;&lt;br /&gt;
   ~Employee();&lt;br /&gt;
private:&lt;br /&gt;
   char firstName[ 25 ];&lt;br /&gt;
   char lastName[ 25 ];&lt;br /&gt;
   const Date birthDate; &lt;br /&gt;
   const Date hireDate; &lt;br /&gt;
};&lt;br /&gt;
Employee::Employee( const char * const first, const char * const last,const Date &amp;amp;dateOfBirth, const Date &amp;amp;dateOfHire )&lt;br /&gt;
   : birthDate( dateOfBirth ), hireDate( dateOfHire ) &lt;br /&gt;
{&lt;br /&gt;
   strcpy( firstName, first);&lt;br /&gt;
   strcpy( lastName, last);&lt;br /&gt;
}&lt;br /&gt;
void Employee::print() const&lt;br /&gt;
{&lt;br /&gt;
   cout &amp;lt;&amp;lt; lastName &amp;lt;&amp;lt; &amp;quot;, &amp;quot; &amp;lt;&amp;lt; firstName &amp;lt;&amp;lt; &amp;quot;  Hired: &amp;quot;;&lt;br /&gt;
   hireDate.print();&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;  Birthday: &amp;quot;;&lt;br /&gt;
   birthDate.print();&lt;br /&gt;
   cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
Employee::~Employee()&lt;br /&gt;
{ &lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Employee destructor: &amp;quot; &amp;lt;&amp;lt; lastName &amp;lt;&amp;lt; &amp;quot;, &amp;quot; &amp;lt;&amp;lt; firstName &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   Date birth( 7, 24, 1949 );&lt;br /&gt;
   Date hire( 3, 12, 1989 );&lt;br /&gt;
   Employee manager( &amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, birth, hire );&lt;br /&gt;
   cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
   manager.print();&lt;br /&gt;
   return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;B, A  Hired: 3/12/1989  Birthday: 7/24/1949&lt;br /&gt;
Employee destructor: B, A&lt;br /&gt;
Date object destructor for date&lt;br /&gt;
Date object destructor for date&lt;br /&gt;
Date object destructor for date&lt;br /&gt;
Date object destructor for date&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Initialize inner object using initialization syntax==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;  &lt;br /&gt;
using namespace std;  &lt;br /&gt;
  &lt;br /&gt;
class IntPair {  &lt;br /&gt;
public:  &lt;br /&gt;
  int a;  &lt;br /&gt;
  int b;  &lt;br /&gt;
  &lt;br /&gt;
  IntPair(int i, int j) : a(i), b(j) { }  &lt;br /&gt;
};  &lt;br /&gt;
  &lt;br /&gt;
class MyClass {  &lt;br /&gt;
  IntPair nums;&lt;br /&gt;
public:  &lt;br /&gt;
   &lt;br /&gt;
  MyClass(int x, int y) : nums(x,y) { }  &lt;br /&gt;
  &lt;br /&gt;
  int getNumA() { return nums.a; }  &lt;br /&gt;
  int getNumB() { return nums.b; }  &lt;br /&gt;
};  &lt;br /&gt;
  &lt;br /&gt;
int main()  &lt;br /&gt;
{  &lt;br /&gt;
  MyClass ob1(7, 9), ob2(5, 2);  &lt;br /&gt;
  &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Values in ob1 are &amp;quot; &amp;lt;&amp;lt; ob1.getNumB() &amp;lt;&amp;lt; &lt;br /&gt;
          &amp;quot; and &amp;quot; &amp;lt;&amp;lt; ob1.getNumA() &amp;lt;&amp;lt; endl;  &lt;br /&gt;
  &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Values in ob2 are &amp;quot; &amp;lt;&amp;lt; ob2.getNumB() &amp;lt;&amp;lt; &lt;br /&gt;
          &amp;quot; and &amp;quot; &amp;lt;&amp;lt; ob2.getNumA() &amp;lt;&amp;lt; endl; &lt;br /&gt;
   &lt;br /&gt;
  return 0;  &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Values in ob1 are 9 and 7&lt;br /&gt;
Values in ob2 are 2 and 5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use class as a member field==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
class Point     // holds x,y coordinates&lt;br /&gt;
{&lt;br /&gt;
    // no constructor, use default&lt;br /&gt;
public:&lt;br /&gt;
    void SetX(int x) { itsX = x; }&lt;br /&gt;
    void SetY(int y) { itsY = y; }&lt;br /&gt;
    int GetX()const { return itsX;}&lt;br /&gt;
    int GetY()const { return itsY;}&lt;br /&gt;
private:&lt;br /&gt;
    int itsX;&lt;br /&gt;
    int itsY;&lt;br /&gt;
};// end of Point class declaration&lt;br /&gt;
&lt;br /&gt;
class  Rectangle&lt;br /&gt;
{&lt;br /&gt;
public:&lt;br /&gt;
    Rectangle (int top, int left, int bottom, int right);&lt;br /&gt;
    ~Rectangle () {}&lt;br /&gt;
    int GetTop() const { return itsTop; }&lt;br /&gt;
    int GetLeft() const { return itsLeft; }&lt;br /&gt;
    int GetBottom() const { return itsBottom; }&lt;br /&gt;
    int GetRight() const { return itsRight; }&lt;br /&gt;
    Point  GetUpperLeft() const { return itsUpperLeft; }&lt;br /&gt;
    Point  GetLowerLeft() const { return itsLowerLeft; }&lt;br /&gt;
    Point  GetUpperRight() const { return itsUpperRight; }&lt;br /&gt;
    Point  GetLowerRight() const { return itsLowerRight; }&lt;br /&gt;
    void SetUpperLeft(Point Location);&lt;br /&gt;
    void SetLowerLeft(Point Location);&lt;br /&gt;
    void SetUpperRight(Point Location);&lt;br /&gt;
    void SetLowerRight(Point Location);&lt;br /&gt;
    void SetTop(int top);&lt;br /&gt;
    void SetLeft (int left);&lt;br /&gt;
    void SetBottom (int bottom);&lt;br /&gt;
    void SetRight (int right);&lt;br /&gt;
    int GetArea() const;&lt;br /&gt;
private:&lt;br /&gt;
    Point  itsUpperLeft;&lt;br /&gt;
    Point  itsUpperRight;&lt;br /&gt;
    Point  itsLowerLeft;&lt;br /&gt;
    Point  itsLowerRight;&lt;br /&gt;
    int    itsTop;&lt;br /&gt;
    int    itsLeft;&lt;br /&gt;
    int    itsBottom;&lt;br /&gt;
    int    itsRight;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
Rectangle::Rectangle(int top, int left, int bottom, int right)&lt;br /&gt;
{&lt;br /&gt;
    itsTop = top;&lt;br /&gt;
    itsLeft = left;&lt;br /&gt;
    itsBottom = bottom;&lt;br /&gt;
    itsRight = right;&lt;br /&gt;
    itsUpperLeft.SetX(left);&lt;br /&gt;
    itsUpperLeft.SetY(top);&lt;br /&gt;
    itsUpperRight.SetX(right);&lt;br /&gt;
    itsUpperRight.SetY(top);&lt;br /&gt;
    itsLowerLeft.SetX(left);&lt;br /&gt;
    itsLowerLeft.SetY(bottom);&lt;br /&gt;
    itsLowerRight.SetX(right);&lt;br /&gt;
    itsLowerRight.SetY(bottom);&lt;br /&gt;
}&lt;br /&gt;
void Rectangle::SetUpperLeft(Point Location)&lt;br /&gt;
{&lt;br /&gt;
    itsUpperLeft = Location; &lt;br /&gt;
    itsUpperRight.SetY(Location.GetY());&lt;br /&gt;
    itsLowerLeft.SetX(Location.GetX());&lt;br /&gt;
    itsTop = Location.GetY();&lt;br /&gt;
    itsLeft = Location.GetX();&lt;br /&gt;
}&lt;br /&gt;
void Rectangle::SetLowerLeft(Point Location)&lt;br /&gt;
{&lt;br /&gt;
    itsLowerLeft = Location; &lt;br /&gt;
    itsLowerRight.SetY(Location.GetY());&lt;br /&gt;
    itsUpperLeft.SetX(Location.GetX());&lt;br /&gt;
    itsBottom = Location.GetY();&lt;br /&gt;
    itsLeft = Location.GetX();&lt;br /&gt;
}&lt;br /&gt;
void Rectangle::SetLowerRight(Point Location)&lt;br /&gt;
{&lt;br /&gt;
    itsLowerRight = Location; &lt;br /&gt;
    itsLowerLeft.SetY(Location.GetY());&lt;br /&gt;
    itsUpperRight.SetX(Location.GetX());&lt;br /&gt;
    itsBottom = Location.GetY();&lt;br /&gt;
    itsRight = Location.GetX();&lt;br /&gt;
}&lt;br /&gt;
void Rectangle::SetUpperRight(Point Location)&lt;br /&gt;
{&lt;br /&gt;
    itsUpperRight = Location; &lt;br /&gt;
    itsUpperLeft.SetY(Location.GetY());&lt;br /&gt;
    itsLowerRight.SetX(Location.GetX());&lt;br /&gt;
    itsTop = Location.GetY();&lt;br /&gt;
    itsRight = Location.GetX();&lt;br /&gt;
}&lt;br /&gt;
void Rectangle::SetTop(int top)&lt;br /&gt;
{&lt;br /&gt;
    itsTop = top;&lt;br /&gt;
    itsUpperLeft.SetY(top);&lt;br /&gt;
    itsUpperRight.SetY(top);&lt;br /&gt;
}&lt;br /&gt;
void Rectangle::SetLeft(int left)&lt;br /&gt;
{&lt;br /&gt;
    itsLeft = left;&lt;br /&gt;
    itsUpperLeft.SetX(left);&lt;br /&gt;
    itsLowerLeft.SetX(left);&lt;br /&gt;
}&lt;br /&gt;
void Rectangle::SetBottom(int bottom)&lt;br /&gt;
{&lt;br /&gt;
    itsBottom = bottom;&lt;br /&gt;
    itsLowerLeft.SetY(bottom);&lt;br /&gt;
    itsLowerRight.SetY(bottom);&lt;br /&gt;
}&lt;br /&gt;
void Rectangle::SetRight(int right)&lt;br /&gt;
{&lt;br /&gt;
    itsRight = right;&lt;br /&gt;
    itsUpperRight.SetX(right);&lt;br /&gt;
    itsLowerRight.SetX(right);&lt;br /&gt;
}&lt;br /&gt;
int Rectangle::GetArea() const&lt;br /&gt;
{&lt;br /&gt;
    int Width = itsRight-itsLeft;&lt;br /&gt;
    int Height = itsTop - itsBottom;&lt;br /&gt;
    return (Width * Height);&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    Rectangle MyRectangle (100, 20, 50, 80 );&lt;br /&gt;
    int Area = MyRectangle.GetArea();&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Area: &amp;quot; &amp;lt;&amp;lt; Area &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; MyRectangle.GetUpperLeft().GetX();&lt;br /&gt;
    return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Area: 3000&lt;br /&gt;
20&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>