» , » -


-

>̲Ͳ²

>ֲͲͲ

">ʲ˲Ͳɲ"


>

>

__________ />xxxxxxxxx./

"___" __________2007.

>- 1, 2

>ֲ-²

>

>Xxxxxxxx

>

>

__________ />.xxxxxxx./

"___" __________ 2007 .

>

__________ />.xxxxxxx./

"___" __________ 2007 .

2007
>

>xxxxxxxxxxxxxx

 

>- 1, 2

>ֲ-²

>

>xxxxxxxxxxxxx

2007

> > >
4 >Xxxxxxxxxxx-01 81 > 2
4 >Xxxxxxxxxxx-01 81 > 6
4 >Xxxxxxxxxxx-01 81 2
4 >Xxxxxxxxxxx-01 81 4-6

>̲Ͳ²

>ֲͲͲ

">ʲ˲Ͳɲ"

>

>

__________ />xxxxxxxxx./

"___" __________2007.

>- 1, 2

>ֲ-²

>

>Xxxxxxxxxxx-01 8101-1-

>

>

__________ />.xxxxxxx./

"___" __________ 2007 .

>

__________ />.xxxxxxxx./

"___" __________ 2007 .

2007
1.

 

'..

2.ϳ

>ϳ >- .

3.

' , . .

4.

> :

- ᒺ;

- ;

- ;

- ;

-;

-;

- ;

-;

-;

-.

5.䳿

1.;

2.;

3. ;

4. , .4;

5. .

6. .

6.

> :

- ;

- ;

- .

>³ .

> MS-DOS Windows C++/.

7.

:

-;

- ;

- ;

- ;

- .

>̲Ͳ²

>ֲͲͲ

">ʲ˲Ͳɲ

>

>

__________ />Xxxxxxxxxxx./

"___" __________2007.

>- 1, 2

>ֲ-²

>

>Xxxxxxxxxxx-01 8101-1-

>

>

__________ />.Xxxxxxxxxxx./

"___" __________ 2007 .

>

__________ />.Xxxxxxxxxxx./

"___" __________ 2007 .

2007
>

-ᒺ,, ᒺ ++.

> > ᒺ.


- ', , ' ++.

> > '.


>Annotation

>In thegivensettlement-graphictask indetailsisdescribedalgorithms ofpolymorphiclists of theobjects, thedevelopedprogramwhichrealizesalgorithm ofpolymorphiclists ofobjects and theinterfacepart of theprogramlanguage ++.

Theexplainannotationcontainsenoughexamples and atheoreticalpartforindependentconsideration andmastering of atheme polymorphiclists ofobjects.

>

1.

2.

3.

4.

5.

++ - - (>ObjectOrientedProgramming,OOP). , ++ , , , . ++ . ++ . ++ .

.

1.         >

> :,,, .

> :

- ᒺ;

- ;

- ;

- ;

-;

-;

- ;

-;

-

-.

> .

:

- ;

- ;

- ;

- ;

- .

2.         >

> IBM. IBM/PC AT CPU k286 ,' 4 HARD 200.

, 躳 int char. . .

> >voidmain().(> 1.1)


3.         >-

ᒺ.. , ᒺ . .

4.         >

, , . ,(). . ᒺ.

> >- .

>

>album

> > > >

>Nazv

>God

>

>virtualvoidinput()

>virtualvoidoutput()

>lbum1

> > > >
>Trek

--//--

>intgetTrek()

>voidsetTrek()

--//--

>trek

>lbum

> > > >
Time >

--//--

>intgetTime()

>voidsetTime()

--//--

>time

>album3

> > > >
>Bonus

--//--

>IntgetBonus(),voidsetBonus()

--//--

>bonus

>Tool

> > > >

T

*>d

*>right

*>left

>

. ᒺ

. ᒺ->

. ᒺ<-

>Trst

> > > >

*>head

*>tail

*>current

.

.

.

>Voidadd(inttype,intvvod) >

lbum (>), : (> ) (> ).³ (>/), .

lbum1 - lbum, , .³ (>/) , trek, .

lbum2 - lbum1, , .³ (>/) , time, .

lbum3 - lbum2, , .³ (>/) , bonus, .

Tool ᒺ lbum . ᒺ ' .

Trist Tool.³ ᒺ .ᒺ () lbum,lbum1,lbum2 lbum3.

>intget.() ᒺ.

>intset.() ' ( 볳) .

>virtualvoidoutput() virtualvoidinput() . ᒺ .

6.        

. ++. -, 2007.

">ϲ".

>̲Ͳ²

>ֲͲͲ

">ʲ˲Ͳɲ

>

>

__________ />Xxxxxxxxxxx./

"___" __________2007.

>- 1, 2

>ֲ-²

>Xxxxxxxxxxx-01 5101-1-

>

>

__________ />.Xxxxxxxxxxx./

"___" __________ 2007 .

>

__________ />.Xxxxxxxxxxx./

"___" __________ 2007 .

2007
>

>Xxxxxxxxxxx-01 5101-1-


>- 1, 2

>ֲ-²

>Xxxxxxxxxxx-01 51 01-1

2007


1.         >ᒺ

, :

-RGZ.cpp (> , >main( ) );

-RGZ_DSC.cpp (>, ) ;

-RGZ. (>, )

>ᒺ .

2.        

迿.

, > .

3.         >

> IBM.

> , ,.

4.         >

> , . , .

> :

': ">Vveditenomeroperatsii".

"1", 䳿:

>Sozdanietablizidannih

>Vvedite N: 3

>Vveditetipzapisi [0..2]: 2

>Vveditenazvaniealboma:qqq

>Vveditegodvipuska: 1889

>Vveditekl-votrekov valbome: 11

>Vvediteprodolzitelnostalbomapovremeni: 60

>Vveditekolichestvobonustrekov: 2

>Vveditetipzapisi [0..2]: 0

>Vveditenazvaniealboma: www

>Vveditegodvipuska: 1990

>Vveditekl-votrekov valbome: 12

>Vveditetipzapisi [0..2]: 1

>Vveditenazvaniealboma:eee

>Vveditegodvipuska: 1991

>Vveditekl-votrekov valbome: 13

>Vvediteprodolzitelnostalbomapovremeni: 58

"2" ' :

>Vivodnaekran

|>Nazv |>God |>Treki |>Vremya |>Bonus+

-------------------------------------------------------

>qqq 1889 11 60 2

www 1990 12

>eee 1991 13 58

>Vivodnaekranzavershen.

"3", , ':

>Vveditenomeroperatsii:3

>Vivod vfaila.dat

>Vivod vfailuspeshnozavershen.

"4", , ':

>Vveditenomeroperatsii:4

>Chtenieizfailaa.dat

>Chtenieizfailauspeshnozavershena.

"5" ' 䳿:

>Vveditenomeroperatsii:5

>Poiskobyekta

>Vveditekluchdlyapoiska(nazvaniealboma): www

>Zapisbilanaidena.

|>Nazv |>God |>Treki |>Vremya |>Bonus+

-------------------------------------------------------

www 1990 12

"6", , ' 䳿:

>Vveditenomeroperatsii:6

>Redaktirovaniezapisi

>Vveditenomerzapisi: 2

>veditenazvaniealboma:rrr

>veditegodvipuska: 1234

>veditekl-votrekov valbome: 13

>vediteprodolzitelnostalbomapovremeni: 56

>Redaktirovanieuspeshnozaversheno.

, :

>Vivodnaekran

|>Nazv |>God |>Treki |>Vremya |>Bonus+

-------------------------------------------------------

>qqq 1889 11 60 2

www 1990 12

>rrr 1234 13 56

>Vivodnaekranzavershen.

"7" ' 䳿:

>Vveditenomeroperatsii:7

>Vstavkanovoizapisi

>Vveditetipnovoyzapisi [0..2]: 2

>veditenazvaniealboma:zzz

>veditegodvipuska: 1534

>Vveditekl-votrekov valbome: 13

>Vvediteprodolzitelnostalbomapovremeni: 222

>Vveditekolichestvobonustrekov: 1

>Vstavkazapisiuspeshnozaversena.

:

>Vivodnaekran

|>Nazv |>God |>Treki |>Vremya |>Bonus+

-------------------------------------------------------

>qqq 1889 11 60 2

www 1990 12

>rrr 1234 13 56

>zzz 1534 11 222 1

>Vivodnaekranzavershen.

"8" , ' 䳿:

>Vveditenomeroperatsii:8

>Udaleniezapisi

>Vveditenomerzapisidlyaudalenia:1

>Zapisbilaudalena.

, :

>Vivodnaekran

|>Nazv |>God |>Treki |>Vremya |>Bonus+

-------------------------------------------------------

>qqq 1889 11 60 2

>rrr 1234 13 56

>zzz 1534 11 222 1

>Vivodnaekranzavershen.

"9" ' 䳿:

>Vveditenomeroperatsii:9

>Poiskobyektasminimalnimkl-vomtrekov vzadannomdiapazonelet

>Vvediteleviypredelpoiska(god): 1

>Vveditepraviypredelpoiska(god): 1600

>Zapisbilanaidena.

|>Nazv |>God |>Treki |>Vremya |>Bonus+

-------------------------------------------------------

>zzz 1534 11 222 1

"10" .

> .

> , , .

>̲Ͳ²

>ֲͲͲ

">ʲ˲Ͳɲ

 

>

>

__________ />Xxxxxxxxxxx./

"___" __________2007.

>- 1, 2

>ֲ-²

>Xxxxxxxxxxx-01 1201-1-

>

>

__________ />.Xxxxxxxxxxx./

"___" __________ 2007 .

>

__________ />.Xxxxxxxxxxx./

"___" __________ 2007 .

2007
>

>Xxxxxxxxxxx-01 8101-1-

 

>- 1, 2

>ֲ-²

>Xxxxxxxxxxx-01 12 01-1

2007

//>

#>include <>string.h>

>classalbum

{

public:

album() {}

virtualvoidinput();

virtualvoidoutput();

charnazv[4];//

intgod;//г

~>album() {}

};

>classalbum1: publicalbum

{protected:

inttrek;//ʳ

public:

album1();

virtualvoidinput();

virtualvoidoutput();

intgetTrek()

{

returntrek;

}

voidsetTrek(intc)//-

{

trek=c;

}

~>album1();

};

>classalbum2: publicalbum1

{

protected:

inttime;//

public:

album2();

virtualvoidinput();

virtualvoidoutput();

intgetTime()

{

returntime;

}

voidsetTime(int )

{

time=c;

}

~>album2();

};

>classalbum3: publicalbum2

{

protected:

intbonus;//ʳ

public:

album3();

virtualvoidinput();

virtualvoidoutput();

intgetBonus()

{

returnbonus;

}

voidsetBonus(int )

{

bonus=c;

}

~>album3();

};

>classTool

{

public:

album *>d;

intt;

friendclassTrist;//'

Tool *>right,*left;

};

>classTrist

{

public:

Tool *>head,*tail;

Tool *>current;

Trist(inttype,intvvod);//

voidadd(inttype,intvvod);//_ᒺ

~>Trist();//

};

//>

#>include ">RGZ.h"

#>include <>iostream.h>

#>include <>string.h>

#>include <>stdlib.h>

#>include <>iomanip.h>

>voidalbum::input()//-

{

cout << ">Vveditenazvaniealboma: ";

cin >>nazv;

nazv[3]=NULL;

cout << ">Vveditegodvipuska: ";

cin >>god;

}

>voidalbum::output()//-

{

>cout <<endl<<setw(10) <<setiosflags(ios::left) <<nazv

<<setw(10) <<setiosflags(ios::left) <<god;

}

>album1::album1():album() {}//

>album1::~album1(){album::~album(); }//>

>voidalbum1::input()

{

album::input();

cout << ">Vveditekl-votrekov valbome: ";

cin >>trek;

}

>voidalbum1::output()

{

album::output();

cout<<setw(10) <<setiosflags(ios::left) <<trek;

}

>album2::album2():album1() {}

>album2::~album2() {album1::~album1(); }

>voidalbum2::input()

{

album1::input();

cout << ">Vvediteprodolzitelnostalbomapovremeni: ";

cin >>time;

}

>voidalbum2::output()

{

album1::output();

cout <<setw(12) <<setiosflags(ios::left) <<time;

}

>album3::album3():album2() {}

>album3::~album3() {album2::~album2(); }

>voidalbum3::input()

{

album2::input();

cout << ">Vveditekolichestvobonustrekov: ";

cin >>bonus;

}

>voidalbum3::output()

{

album2::output();

cout <<setw(10) <<setiosflags(ios::left) <<bonus;

}

>voidcaption()//-

{

>cout <<endl <<setw(10) <<setiosflags(ios::left) << "|>Nazv"

<<setw(10) <<setiosflags(ios::left) << "|>God"

<<setw(10) <<setiosflags(ios::left) << "|>Treki"

<<setw(10) <<setiosflags(ios::left) << "|>Vremya"

<<setw(10) <<setiosflags(ios::left) << "|>Bonus+"<<endl;

>cout << "-------------------------------------------------------";

}

>Trist::Trist(inttype,intvvod)// '

{

album1 *>pr;

album2 *>sp;

album3 *>fl;

head = newTool;

head->t =type;

if (>head->t == 0)

{

pr = newalbum1;

if (>vvod)

pr->input();

head->d=pr;

}else

if (>head->t == 1)

{

sp = newalbum2;

if (>vvod)

sp->input();

head->d=sp;

}else

if (>head->t == 2)

{

fl = newalbum3;

if (>vvod)

fl->input();

head->d=fl;

}

head->right=NULL;

head->left=NULL;

tail=head;

current=head;

}

>Trist::~Trist()//

{

Tool *h;

h=head;

while (>h!=0)

{head=head->right;

head->left=NULL;

delete h;

h=head;

}

}

>voidTrist::add(inttype,intvvod)// ᒺ

{

Tool *>q = newTool;

album1 *>pr;

album2 *>sp;

album3 *>fl;

q->t =type;

switch (>q->t)

{

case 0:

pr = newalbum1;

if (>vvod)

pr->input();

q->d=pr;

break;

case 1:

sp=newalbum2;

if (>vvod)

sp->input();

q->d=sp;

break;

case 2:

fl=newalbum3;

if (>vvod)

fl->input();

q->d=fl;

break;

}

if (>current==tail)

{

q->right=NULL;

q->left=current;

current->right=q;

tail=q;

current=q;

}else

{q->right=current->right;

current->right->left=q;

current->right=q;

q->left=current;

current=q;

}

}

//>

#>include ">RGZ_dsc.cpp"

#>include <>iostream.h>

#>include <>conio.h>

#>include <>stdlib.h>

#>include <>fstream.h>

>voidsozdan(Trist *&a,intn);//

>voidoutput(Trist *&>a);//

>voidoutput_file(Trist *&a,intn);//

>voidinput_file(Trist *&>a);//

>Tool*pois(Trist *&a,char*nazv);//-

>Tool*zadacha(Trist *&>a,intgodL,intgodR);//

>voidmain()//

{

inti,N=5,k;

Trist *a =NULL;

clrscr();

randomize();

while (1)

{

cout << ">nn############################";

cout << "n# 1 -Sozdaniebazidannih #";

cout << "n# 2 -Vivodnaekran #";

cout << "n# 3 -Vivod vfail #";

cout << "n# 4 -Chtenieizfaila #";

cout << "n# 5 -Poisk #";

cout << "n# 6 -Redaktirovaniezapisi #";

cout << "n# 7 -Vstavkanovoizapisi #";

cout << "n# 8 -Udaleniezapisi #";

cout << "n# 9 -Vipolnrniezadachi #";

cout << "n# 10 -Vihod #";

cout << ">nn############################";

cout << "nVveditenomeroperatsii:";

cin >>k;

switch (>k)

{

case 1:

cout << "nSozdanietablizidannih";

cout << "nVvedite N: ";

cin >> N;

sozdan(a,N);

cout << "nTablizadannihsozdana.";

getch();

break;

case 2:

cout << "nVivodnaekran ";

output(a);

cout << "nVivodnaekranzavershen.";

getch();

break;

case 3:

cout << "nVivod vfaila.dat ";

output_file(a,N);

cout << "nVivod vfailuspeshnozavershen.";

getch();

break;

case 4:

cout << "nChtenieizfailaa.dat ";

input_file(a);

cout << "nChtenieizfailauspeshnozavershena.";

getch();

break;

case 5:

cout << "nPoiskobyekta ";

cout << "nVveditekluchdlyapoiska(nazvaniealboma): ";

char *>nazv;

cin >>nazv;

Tool *n;

//n=NULL;

n =pois(a,nazv);

if (>n==NULL)cout << "nZapisnenaidena.";

else

{

cout << "nZapisbilanaidena.";

caption();

n->d->output();

}

deletenazv;

getch();

break;

case 6:

cout << "nRedaktirovaniezapisi ";

cout << "nVveditenomerzapisi: ";

int ;

cin >> ;

a->current=a->head;

for (>i=0;a->current!=NULL;i++)

{

if (>i==c)

{

a->current->d->input();

break;

}

a->current=a->current->right;

}

cout << "nRedaktirovanieuspeshnozaversheno.";

getch();

break;

case 7:

cout << "nVstavkanovoizapisi ";

cout << "nVveditetipnovoyzapisi [0..2]: ";

intp = 0;

cin >>p;

a->current=a->tail;

a->add(p,1);

cout << "nVstavkazapisiuspeshnozaversena.";

getch();

break;

case 8:

cout << "nUdaleniezapisi ";

cout << "nVveditenomerzapisidlyaudalenia: ";

int j = 0;

cin >> j;

a->current=a->head;

for (>i=0;a->current!=NULL;i++)

{

if (>i==j)

{

Tool *>q =a->current;

if (>q->left!=NULL)q->left->right =q->right;

if (>q->right!=NULL)q->right->left =q->left;

if (>q==a->head)a->head=q->right;

if (>q==a->tail)a->tail=q->left;

deleteq;

a->current =a->tail;

break;

}

a->current=a->current->right;

}

cout << "nZapisbilaudalena.";

getch();

break;

case 9:

cout << "nPoiskobyektasminimalnimkl-vomtrekov vzadannomdiapazonelet";

cout << "nVvediteleviypredelpoiska(god): ";

intgodL,godR;

cin >>godL;

cout << "nVveditepraviypredelpoiska(god): ";

cin >>godR;

Tool *>k;

k =zadacha(a,godL,godR);

if (>n==NULL)cout << "nZapisnenaidena.";

else

{

cout << "nZapisbilanaidena.";

caption();

k->d->output();

}

getch();

break;

case 10:

delete a;

exit(0);

break;

}

}

}

>voidsozdan(Trist *&a,int n)

{

if (>a!=NULL)

delete a;

cout << ">nVveditetipzapisi [0..2]: ";

intk;

cin >>k;

a = newTrist(k,1);

for (>inti=1;i<n;i++)

{

cout << ">nVveditetipzapisi [0..2]: ";

cin >>k;

a->add(k,1);

}

}

>voidoutput(Trist *&a)

{

caption();

a->current=a->head;

while (>a->current!=NULL)

{

a->current->d->output();

a->current=a->current->right;

}

}

>voidoutput_file(Trist *&a,int n)

{

>ofstreamfile("a.dat",ios::out|ios::binary);

>if (!>file)

{

cerr << ">nOshibkavivoda vfail!n";

getch();

exit(1);

}

>file.seekp(0);

>file.write((char*)&(n),sizeof(n));

>a->current=a->head;

>while (>a->current!=NULL)

{

file.write((char*)&(a->current->t),sizeof(a->current->t));

file.write(a->current->d->nazv,sizeof(a->current->d->nazv));

switch (>a->current->t)

{

case 0:

album1 *>obj1;

obj1=(album1*)a->current->d;

inttrek =obj1->getTrek();

file.write((char*)&(trek),sizeof(trek));

break;

case 1:

album2 *>obj2;

obj2=(album2*)a->current->d;

trek =obj2->getTrek();

inttime =obj2->getTime();

file.write((char*)&(trek),sizeof(trek));

file.write((char*)&(time),sizeof(time));

break;

case 2:

album3 *>obj3;

obj3=(album3*)a->current->d;

trek =obj3->getTrek();

time =obj3->getTime();

intbonus =obj3->getBonus();

file.write((char*)&(trek),sizeof(trek));

file.write((char*)&(time),sizeof(time));

file.write((char*)&(bonus),sizeof(bonus));

break;

}

a->current=a->current->right;

}

>file.close();

}

>voidinput_file(Trist *&a)

{

>ifstreamfile("a.dat",ios::in);

>if (!>file)

{

cerr << ">nOshibkachteniafaila!n";

getch();

exit(1);

}

>int n;

>file.read((char*)&(n),sizeof(n));

>int ;

>delete a;

>for (>i=0;i<n;i++)

{

intt;

file.read((char*)&(t),sizeof(t));

if (>i==0)a=newTrist(t,0);elsea->add(t,0);

file.read((char*)&(a->current->d->nazv),sizeof(a->current->d->nazv));

switch (>t)

{

case 0:

album1 *>obj1;

obj1=(album1*)a->current->d;

inttrek = 0;

file.read((char*)&(trek),sizeof(trek));

obj1->setTrek(trek);

break;

case 1:

album2 *>obj2;

obj2=(album2*)a->current->d;

trek = 0;

inttime = 0;

file.read((char*)&(trek),sizeof(trek));

file.read((char*)&(time),sizeof(time));

obj2->setTrek(trek);

obj2->setTime(time);

break;

case 2:

album3 *>obj3;

obj3=(album3*)a->current->d;

trek = 0;

time = 0;

intbonus = 0;

file.read((char*)&(trek),sizeof(trek));

file.read((char*)&(time),sizeof(time));

file.read((char*)&(bonus),sizeof(bonus));

obj3->setTrek(trek);

obj3->setTime(time);

obj3->setBonus(bonus);

break;

}

}

>file.close();

}

>Tool*pois(Trist *&a,char*nazv)

{

Tool *n =NULL;

a->current=a->head;

while (>a->current!=NULL)

{

n =a->current;

if (>strcmp(n->d->nazv,nazv)==0)break;

elsen=NULL;

a->current=a->current->right;

}

return n;

}

>Tool*zadacha(Trist *&>a,intgodL,intgodR)

{

Tool *>k =NULL;

a->current=a->head;

intmax=1000;

while (>a->current!=NULL)

{

k =a->current;

if(k->d->god>godL)

>if(k->d->god<godR)

>if(k->d->trek<min)break;

>elsek=NULL;

a->current=a->current->right;

}

returnk;


:

  • : -
    >̲Ͳ >² >ֲ >Ͳ >² >˲Ͳ
  • : ֲ
    : >. > > >   : >. >
  • :
    > > . > > > 1.1 > > >
  • :
    > : > > > > >
  • :
    . 㳿.