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

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B_Tutorial/Structure/structure&amp;diff=2243&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B_Tutorial/Structure/structure&amp;diff=2243&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://cppe.ru/index.php?title=C%2B%2B_Tutorial/Structure/structure&amp;diff=2244&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B_Tutorial/Structure/structure&amp;diff=2244&amp;oldid=prev"/>
				<updated>2010-05-25T10:29:14Z</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;==Assign one structure to another structure==&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;
struct Box {&lt;br /&gt;
  double length;&lt;br /&gt;
  double width;&lt;br /&gt;
  double height;&lt;br /&gt;
};&lt;br /&gt;
int main() {&lt;br /&gt;
  Box firstBox = { 80.0, 50.0, 40.0 };&lt;br /&gt;
  cout &amp;lt;&amp;lt; firstBox.length&lt;br /&gt;
       &amp;lt;&amp;lt; firstBox.width&lt;br /&gt;
       &amp;lt;&amp;lt; firstBox.height&lt;br /&gt;
       &amp;lt;&amp;lt; endl;&lt;br /&gt;
       &lt;br /&gt;
  Box secondBox = firstBox;   &lt;br /&gt;
  secondBox.length *= 1.1;&lt;br /&gt;
  secondBox.width *= 1.1;&lt;br /&gt;
  secondBox.height *= 1.1;&lt;br /&gt;
  cout &amp;lt;&amp;lt; secondBox.length &lt;br /&gt;
       &amp;lt;&amp;lt; secondBox.width&lt;br /&gt;
       &amp;lt;&amp;lt; secondBox.height&lt;br /&gt;
       &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;805040&lt;br /&gt;
885544&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==const structure parameter==&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.h&amp;gt;&lt;br /&gt;
struct Time&lt;br /&gt;
{&lt;br /&gt;
       int hh,mm,ss;&lt;br /&gt;
};&lt;br /&gt;
void Disp1(struct Time t);&lt;br /&gt;
void Disp2(const Time &amp;amp; t);&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
       Time t1,t2,*p;&lt;br /&gt;
       &lt;br /&gt;
       t1.hh=10;&lt;br /&gt;
       t1.mm=30;&lt;br /&gt;
       t1.ss=0;&lt;br /&gt;
       t2=t1;  &lt;br /&gt;
       t2.hh++;                        &lt;br /&gt;
       p = &amp;amp;t2;&lt;br /&gt;
    &lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;The t2 time is &amp;quot; &amp;lt;&amp;lt; p-&amp;gt;hh  &amp;lt;&amp;lt; &amp;quot;:&amp;quot; &amp;lt;&amp;lt; t2.mm &amp;lt;&amp;lt; &amp;quot;:&amp;quot;&amp;lt;&amp;lt; t1.ss &amp;lt;&amp;lt; endl;&lt;br /&gt;
       Disp1(t2);&lt;br /&gt;
       Disp2(t2);&lt;br /&gt;
       &lt;br /&gt;
       return 0;&lt;br /&gt;
}&lt;br /&gt;
void Disp1(struct Time t)&lt;br /&gt;
{&lt;br /&gt;
       cout &amp;lt;&amp;lt; &amp;quot;The time is &amp;quot; &amp;lt;&amp;lt; t.hh &amp;lt;&amp;lt;&amp;quot;:&amp;quot; &amp;lt;&amp;lt; t.mm &amp;lt;&amp;lt; &amp;quot;:&amp;quot;&amp;lt;&amp;lt; t.ss &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
void Disp2(const Time &amp;amp; t)&lt;br /&gt;
{&lt;br /&gt;
       cout &amp;lt;&amp;lt; &amp;quot;The time is &amp;quot; &amp;lt;&amp;lt; t.hh &amp;lt;&amp;lt;&amp;quot;:&amp;quot; &amp;lt;&amp;lt; t.mm &amp;lt;&amp;lt; &amp;quot;:&amp;quot;&amp;lt;&amp;lt; t.ss &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;The t2 time is 11:30:0&lt;br /&gt;
The time is 11:30:0&lt;br /&gt;
The time is 11:30:0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Define structure to record time==&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.h&amp;gt;&lt;br /&gt;
struct Time&lt;br /&gt;
{&lt;br /&gt;
               int hh,mm,ss;&lt;br /&gt;
};&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   Time t1,t2,*p;&lt;br /&gt;
   t1.hh=10;&lt;br /&gt;
   t1.mm=30;&lt;br /&gt;
   t1.ss=0;  //10:30:0&lt;br /&gt;
   t2=t1;&lt;br /&gt;
   t2.hh++;                             //11:30:0&lt;br /&gt;
   p = &amp;amp;t2;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;The t2 time is &amp;quot; &amp;lt;&amp;lt; p-&amp;gt;hh  &amp;lt;&amp;lt; &amp;quot;:&amp;quot; &amp;lt;&amp;lt; t2.mm &amp;lt;&amp;lt; &amp;quot;:&amp;quot;&amp;lt;&amp;lt; t1.ss &amp;lt;&amp;lt; endl;&lt;br /&gt;
   return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;The t2 time is 11:30:0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==structure composition==&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;iostream&amp;gt;&lt;br /&gt;
struct Name {&lt;br /&gt;
  char firstname[80];&lt;br /&gt;
  char surname[80];&lt;br /&gt;
  &lt;br /&gt;
  void show();        &lt;br /&gt;
};&lt;br /&gt;
struct Date {&lt;br /&gt;
  int day;&lt;br /&gt;
  int month;&lt;br /&gt;
  int year;&lt;br /&gt;
  void show();        &lt;br /&gt;
};&lt;br /&gt;
struct Phone {&lt;br /&gt;
  int areacode;&lt;br /&gt;
  int number;&lt;br /&gt;
  void show();        &lt;br /&gt;
};&lt;br /&gt;
struct Person {&lt;br /&gt;
  Name name;&lt;br /&gt;
  Date birthdate;&lt;br /&gt;
  Phone number;&lt;br /&gt;
  void show();&lt;br /&gt;
  int age(Date&amp;amp; date);&lt;br /&gt;
};&lt;br /&gt;
void Name::show() {&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; firstname &amp;lt;&amp;lt; &amp;quot; &amp;quot; &amp;lt;&amp;lt; surname &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
}&lt;br /&gt;
void Date::show() {&lt;br /&gt;
    std::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 &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
}&lt;br /&gt;
void Phone::show() {&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; areacode &amp;lt;&amp;lt; &amp;quot; &amp;quot; &amp;lt;&amp;lt; number &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
}&lt;br /&gt;
void Person::show() {&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    name.show();&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Brithday: &amp;quot;;&lt;br /&gt;
    birthdate.show();&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;phone: &amp;quot;;&lt;br /&gt;
    number.show(); &lt;br /&gt;
}&lt;br /&gt;
int Person::age(Date&amp;amp; date) {&lt;br /&gt;
    if(date.year &amp;lt;= birthdate.year)&lt;br /&gt;
      return 0;&lt;br /&gt;
    int years = date.year - birthdate.year;&lt;br /&gt;
    &lt;br /&gt;
    if((date.month&amp;gt;birthdate.month) || (date.month == birthdate.month &amp;amp;&amp;amp; date.day&amp;gt;= birthdate.day))&lt;br /&gt;
       return years;&lt;br /&gt;
    else&lt;br /&gt;
       return --years;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
  Person her = {{ &amp;quot;L&amp;quot;, &amp;quot;G&amp;quot; },      // Initializes Name member&lt;br /&gt;
                {1, 4, 1976 },     // Initializes Date member&lt;br /&gt;
                {999,5551234}     // Initializes Phone member&lt;br /&gt;
               };&lt;br /&gt;
  Person actress;&lt;br /&gt;
  actress = her;&lt;br /&gt;
  her.show();&lt;br /&gt;
  Date today = { 4, 4, 2007 };&lt;br /&gt;
  cout &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; &amp;quot;Today is &amp;quot;;&lt;br /&gt;
  today.show();&lt;br /&gt;
  cout &amp;lt;&amp;lt;  endl; &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Today &amp;quot; &amp;lt;&amp;lt; actress.name.firstname &amp;lt;&amp;lt; &amp;quot; is &amp;quot; &lt;br /&gt;
       &amp;lt;&amp;lt; actress.age(today) &amp;lt;&amp;lt; &amp;quot; years old.&amp;quot;&lt;br /&gt;
       &amp;lt;&amp;lt; endl;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;L G&lt;br /&gt;
Brithday: 4/1/1976&lt;br /&gt;
phone: 999 5551234&lt;br /&gt;
Today is 4/4/2007&lt;br /&gt;
Today L is 31 years old.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use cin to read data for a structure==&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.h&amp;gt;&lt;br /&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include&amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include&amp;lt;string.h&amp;gt;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
       struct student&lt;br /&gt;
       {&lt;br /&gt;
               int num;&lt;br /&gt;
           char name[20];&lt;br /&gt;
           float score;&lt;br /&gt;
       };&lt;br /&gt;
       struct student stu[4];&lt;br /&gt;
       struct student *p;&lt;br /&gt;
       int i,temp;&lt;br /&gt;
       float max;&lt;br /&gt;
       for(i=0;i&amp;lt;=4;i++)&lt;br /&gt;
               cin&amp;gt;&amp;gt;stu[i].num&amp;gt;&amp;gt;stu[i].name&amp;gt;&amp;gt;stu[i].score;&lt;br /&gt;
       for(max=stu[0].score,i=1;i&amp;lt;4;i++){&lt;br /&gt;
               if(stu[i].score&amp;gt;max);&lt;br /&gt;
               {&lt;br /&gt;
                       max=stu[i].score;temp=i;&lt;br /&gt;
               }&lt;br /&gt;
    }&lt;br /&gt;
       p=stu+temp;&lt;br /&gt;
       cout&amp;lt;&amp;lt;&amp;quot;maxmum score:&amp;quot;;&lt;br /&gt;
       cout&amp;lt;&amp;lt;&amp;quot;NO.:&amp;quot;&amp;lt;&amp;lt;p-&amp;gt;num&amp;lt;&amp;lt;&amp;quot;NAME:&amp;quot;&amp;lt;&amp;lt;p-&amp;gt;name&amp;lt;&amp;lt;&amp;quot;SCORE:&amp;quot;&amp;lt;&amp;lt;p-&amp;gt;score&amp;lt;&amp;lt;&amp;quot;\n&amp;quot;;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;maxmum score:NO.:^CTerminate batch job (Y/N)? n&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use memcpy to duplicate structures==&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;memory&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
struct mystruct&lt;br /&gt;
{&lt;br /&gt;
       int i;&lt;br /&gt;
       int x;&lt;br /&gt;
       int y;&lt;br /&gt;
};&lt;br /&gt;
 &lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  mystruct source,destination;&lt;br /&gt;
  source.i = 1;&lt;br /&gt;
  source.x = 2;&lt;br /&gt;
  source.y = 3;&lt;br /&gt;
  memcpy(&amp;amp;destination,&amp;amp;source,sizeof(source));&lt;br /&gt;
  cout &amp;lt;&amp;lt; destination.i &amp;lt;&amp;lt; endl;&lt;br /&gt;
  cout &amp;lt;&amp;lt; destination.x &amp;lt;&amp;lt; endl;&lt;br /&gt;
  cout &amp;lt;&amp;lt; destination.y &amp;lt;&amp;lt; endl;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;1&lt;br /&gt;
2&lt;br /&gt;
3&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use the keyword struct to illustrate a primitive form of class==&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;
#include &amp;lt;math.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
struct math_operations {&lt;br /&gt;
 double data_value;&lt;br /&gt;
  &lt;br /&gt;
 void set_value(double ang) {&lt;br /&gt;
     data_value=ang;&lt;br /&gt;
 }&lt;br /&gt;
 double get_square(void) {&lt;br /&gt;
     double answer;&lt;br /&gt;
     answer=data_value*data_value;                          &lt;br /&gt;
     return (answer);&lt;br /&gt;
 }&lt;br /&gt;
 double get_square_root(void) {&lt;br /&gt;
     double answer;&lt;br /&gt;
     answer=sqrt(data_value);&lt;br /&gt;
     return (answer);&lt;br /&gt;
 }&lt;br /&gt;
} math;&lt;br /&gt;
int main( )&lt;br /&gt;
{&lt;br /&gt;
 math.set_value(35.63);&lt;br /&gt;
 cout &amp;lt;&amp;lt; &amp;quot;The square of the number is: &amp;quot;&lt;br /&gt;
      &amp;lt;&amp;lt; math.get_square( ) &amp;lt;&amp;lt; endl;&lt;br /&gt;
 cout &amp;lt;&amp;lt; &amp;quot;The square root of the number is: &amp;quot;&lt;br /&gt;
      &amp;lt;&amp;lt; math.get_square_root( ) &amp;lt;&amp;lt; endl;&lt;br /&gt;
 return (0);&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using pointers to structure objects: delete the point==&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;
struct Box {&lt;br /&gt;
  double length;&lt;br /&gt;
  double width;&lt;br /&gt;
  double height;&lt;br /&gt;
  double volume();&lt;br /&gt;
};&lt;br /&gt;
double Box::volume() {&lt;br /&gt;
  return length * width * height;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
  Box aBox = { 1, 2, 3 };&lt;br /&gt;
  Box* pBox = &amp;amp;aBox;&lt;br /&gt;
 &lt;br /&gt;
  Box* pBox2 = new Box;&lt;br /&gt;
  pBox2-&amp;gt;height = pBox-&amp;gt;height+5.0;&lt;br /&gt;
  pBox2-&amp;gt;length = pBox-&amp;gt;length+3.0;&lt;br /&gt;
  pBox2-&amp;gt;width = pBox-&amp;gt;width+2.0;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Volume of Box in the free store is &amp;quot; &amp;lt;&amp;lt; pBox2-&amp;gt;volume() &amp;lt;&amp;lt; endl;&lt;br /&gt;
  delete pBox;&lt;br /&gt;
  delete pBox2;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Volume of Box in the free store is 128&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>