,,,
̲Ͳ ²
ֲ Ͳ Ͳ
"ʲ ˲Ͳ "
__________ /xxxxxxxxx./
"___" __________ 2007.
Xxxxxxxx
__________ /. xxxxxxx./ "___" __________ 2007 . __________ /. xxxxxxx./ "___" __________ 2007 . |
2007
xxxxxxxxxxxxxx
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.
Xxxxxxxxxxx-01 81 01-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.
Xxxxxxxxxxx-01 81 01-1-
__________ /. Xxxxxxxxxxx./ "___" __________ 2007 . __________ /. Xxxxxxxxxxx./ "___" __________ 2007 . |
2007
- ᒺ, , ᒺ C++.
ᒺ.
- , , C++.
.
In the given settlement-graphic task in details is described algorithms of polymorphic lists of the objects, the developed program which realizes algorithm of polymorphic lists of objects and the interface part of the program language C++.
The explain annotation contains enough examples and a theoretical part for independent consideration and mastering of a theme polymorphic lists of objects.
1.
2.
3.
4.
5.
++ - ¢- (Object Oriented Programming, OOP). , ++ , , , . ++ . ++ . ++ .
.
1.
: , , , .
:
- ᒺ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
-
- .
.
:
- ;
- ;
- ;
- ;
- .
2.
IBM . IBM/PC AT CPU k286 , ' 4 HARD 200 .
, int char. . .
void main().( 1.1)
3. -
ᒺ . . , ᒺ . .
4.
, , . , (). . ᒺ.
- .
album
Nazv God |
г |
virtual void input() virtual void output() |
lbum1
Trek | ʳ |
--//-- int getTrek() void setTrek() |
--//-- trek |
lbum
Time |
--//-- int getTime() void setTime() |
--//-- time |
album3
Bonus | ʳ |
--//-- Int getBonus(), void setBonus() |
--//-- bonus |
Tool
T *d *right *left |
. ᒺ. ᒺ->. ᒺ<- |
Trst
*head *tail *current |
... |
Void add(int type, int vvod) |
lbum () , : ( ) ( ). ³ (/), .
lbum1 - lbum, , . ³ (/) , trek, .
lbum2 - lbum1, , . ³ (/) , time, .
lbum3 - lbum2, , . ³ (/) , bonus, .
Tool ᒺ lbum . ᒺ ' .
Trist Tool.³ ᒺ . ᒺ () lbum, lbum1, lbum2 lbum3.
int get.() ᒺ.
int set.() ' ( ) .
virtual void output() virtual void input() . ᒺ .
6.
. ++. -, 2007.
"ϲ".
̲Ͳ ²
ֲ Ͳ Ͳ
"ʲ ˲Ͳ
__________ /Xxxxxxxxxxx./
"___" __________ 2007.
Xxxxxxxxxxx-01 51 01-1-
__________ /. Xxxxxxxxxxx./ "___" __________ 2007 . __________ /. Xxxxxxxxxxx./ "___" __________ 2007 . |
2007
Xxxxxxxxxxx-01 51 01-1-
Xxxxxxxxxxx-01 51 01-1
2007
1. ᒺ
, :
- RGZ.cpp ( , main( ) );
- RGZ_DSC.cpp (, ) ;
- RGZ. (, )
ᒺ .
2.
.
, .
3.
IBM .
, , .
4.
, . , .
:
' : "Vvedite nomer operatsii".
"1", 䳿:
Sozdanie tablizi dannih
Vvedite N: 3
Vvedite tip zapisi [0..2]: 2
Vvedite nazvanie alboma: qqq
Vvedite god vipuska: 1889
Vvedite kl-vo trekov v albome: 11
Vvedite prodolzitelnost alboma po vremeni: 60
Vvedite kolichestvo bonus trekov: 2
Vvedite tip zapisi [0..2]: 0
Vvedite nazvanie alboma: www
Vvedite god vipuska: 1990
Vvedite kl-vo trekov v albome: 12
Vvedite tip zapisi [0..2]: 1
Vvedite nazvanie alboma: eee
Vvedite god vipuska: 1991
Vvedite kl-vo trekov v albome: 13
Vvedite prodolzitelnost alboma po vremeni: 58
"2" ' :
Vivod na ekran
|Nazv |God |Treki |Vremya |Bonus+
-------------------------------------------------------
qqq 1889 11 60 2
www 1990 12
eee 1991 13 58
Vivod na ekran zavershen.
"3", ' :
Vvedite nomer operatsii:3
Vivod v fail a.dat
Vivod v fail uspeshno zavershen.
"4", ' :
Vvedite nomer operatsii:4
Chtenie iz faila a.dat
Chtenie iz faila uspeshno zavershena.
"5" ' 䳿:
Vvedite nomer operatsii:5
Poisk obyekta
Vvedite kluch dlya poiska(nazvanie alboma): www
Zapis bila naidena.
|Nazv |God |Treki |Vremya |Bonus+
-------------------------------------------------------
www 1990 12
"6", ' 䳿:
Vvedite nomer operatsii:6
Redaktirovanie zapisi
Vvedite nomer zapisi: 2
vedite nazvanie alboma: rrr
vedite god vipuska: 1234
vedite kl-vo trekov v albome: 13
vedite prodolzitelnost alboma po vremeni: 56
Redaktirovanie uspeshno zaversheno.
, :
Vivod na ekran
|Nazv |God |Treki |Vremya |Bonus+
-------------------------------------------------------
qqq 1889 11 60 2
www 1990 12
rrr 1234 13 56
Vivod na ekran zavershen.
"7" ' 䳿:
Vvedite nomer operatsii:7
Vstavka novoi zapisi
Vvedite tip novoy zapisi [0..2]: 2
vedite nazvanie alboma: zzz
vedite god vipuska: 1534
Vvedite kl-vo trekov v albome: 13
Vvedite prodolzitelnost alboma po vremeni: 222
Vvedite kolichestvo bonus trekov: 1
Vstavka zapisi uspeshno zaversena.
:
Vivod na ekran
|Nazv |God |Treki |Vremya |Bonus+
-------------------------------------------------------
qqq 1889 11 60 2
www 1990 12
rrr 1234 13 56
zzz 1534 11 222 1
Vivod na ekran zavershen.
"8" ' 䳿:
Vvedite nomer operatsii:8
Udalenie zapisi
Vvedite nomer zapisi dlya udalenia:1
Zapis bila udalena.
, :
Vivod na ekran
|Nazv |God |Treki |Vremya |Bonus+
-------------------------------------------------------
qqq 1889 11 60 2
rrr 1234 13 56
zzz 1534 11 222 1
Vivod na ekran zavershen.
"9" ' 䳿:
Vvedite nomer operatsii:9
Poisk obyekta s minimalnim kl-vom trekov v zadannom diapazone let
Vvedite leviy predel poiska(god): 1
Vvedite praviy predel poiska(god): 1600
Zapis bila naidena.
|Nazv |God |Treki |Vremya |Bonus+
-------------------------------------------------------
zzz 1534 11 222 1
"10" .
.
, , .
̲Ͳ ²
ֲ Ͳ Ͳ
"ʲ ˲Ͳ
__________ /Xxxxxxxxxxx./
"___" __________ 2007.
Xxxxxxxxxxx-01 12 01-1-
__________ /. Xxxxxxxxxxx./ "___" __________ 2007 . __________ /. Xxxxxxxxxxx./ "___" __________ 2007 . |
2007
Xxxxxxxxxxx-01 81 01-1-
Xxxxxxxxxxx-01 12 01-1
2007
//
#include <string.h>
class album
{
public:
album() {}
virtual void input();
virtual void output();
char nazv[4];//
int god;//г
~album() {}
};
class album1: public album
{ protected:
int trek;//ʳ
public:
album1();
virtual void input();
virtual void output();
int getTrek()
{
return trek;
}
void setTrek(int c)//-
{
trek=c;
}
~album1();
};
class album2: public album1
{
protected:
int time;//
public:
album2();
virtual void input();
virtual void output();
int getTime()
{
return time;
}
void setTime(int c)
{
time=c;
}
~album2();
};
class album3: public album2
{
protected:
int bonus;//ʳ
public:
album3();
virtual void input();
virtual void output();
int getBonus()
{
return bonus;
}
void setBonus(int c)
bonus=c;
}
~album3();
};
class Tool
{
public:
album *d;
int t;
friend class Trist;//'
Tool *right,*left;
};
class Trist
{
public:
Tool *head,*tail;
Tool *current;
Trist(int type,int vvod);//
void add(int type, int vvod);//_ ᒺ
~Trist();//
};
//
#include "RGZ.h"
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <iomanip.h>
void album::input()//-
{
cout << "Vvedite nazvanie alboma: ";
cin >> nazv;
nazv[3]=NULL;
cout << "Vvedite god vipuska: ";
cin >> god;
}
void album::output()//-
{
cout << endl<< setw(10) << setiosflags(ios::left) << nazv
<< setw(10) << setiosflags(ios::left) << god;
}
album1::album1():album() {}//
album1::~album1(){ album::~album(); }//
void album1::input()
{
album::input();
cout << "Vvedite kl-vo trekov v albome: ";
cin >> trek;
}
void album1::output()
{
album::output();
cout<< setw(10) << setiosflags(ios::left) << trek;
}
album2::album2():album1() {}
album2::~album2() { album1::~album1(); }
void album2::input()
{
album1::input();
cout << "Vvedite prodolzitelnost alboma po vremeni: ";
cin >> time;
}
void album2::output()
{
album1::output();
cout << setw(12) << setiosflags(ios::left) << time;
}
album3::album3():album2() {}
album3::~album3() { album2::~album2(); }
void album3::input()
{
album2::input();
cout << "Vvedite kolichestvo bonus trekov: ";
cin >> bonus;
}
void album3::output()
{
album2::output();
cout << setw(10) << setiosflags(ios::left) << bonus;
}
void caption()// -
{
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(int type, int vvod)// '
{
album1 *pr;
album2 *sp;
album3 *fl;
head = new Tool;
head->t = type;
if (head->t == 0)
{
pr = new album1;
if (vvod)
pr->input();
head->d=pr;
} else
if (head->t == 1)
{
sp = new album2;
if (vvod)
sp->input();
head->d=sp;
} else
if (head->t == 2)
{
fl = new album3;
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;
}
}
void Trist::add(int type, int vvod)// ᒺ
{
Tool *q = new Tool;
album1 *pr;
album2 *sp;
album3 *fl;
q->t = type;
switch (q->t)
{
case 0:
pr = new album1;
if (vvod)
pr->input();
q->d=pr;
break;
case 1:
sp=new album2;
if (vvod)
sp->input();
q->d=sp;
break;
case 2:
fl=new album3;
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>
void sozdan(Trist *&a, int n);//
void output(Trist *&a);//
void output_file(Trist *&a, int n);//
void input_file(Trist *&a);//
Tool* pois(Trist *&a, char* nazv);//-
Tool* zadacha(Trist *&a,int godL,int godR);//
void main()//
{
int i,N=5,k;
Trist *a = NULL;
clrscr();
randomize();
while (1)
{
cout << "\n\n############################";
cout << "\n# 1 - Sozdanie bazi dannih #";
cout << "\n# 2 - Vivod na ekran #";
cout << "\n# 3 - Vivod v fail #";
cout << "\n# 4 - Chtenie iz faila #";
cout << "\n# 5 - Poisk #";
cout << "\n# 6 - Redaktirovanie zapisi #";
cout << "\n# 7 - Vstavka novoi zapisi #";
cout << "\n# 8 - Udalenie zapisi #";
cout << "\n# 9 - Vipolnrnie zadachi #";
cout << "\n# 10 - Vihod #";
cout << "\n\n############################";
cout << "\n Vvedite nomer operatsii:";
cin >> k;
switch (k)
{
case 1:
cout << "\n Sozdanie tablizi dannih";
cout << "\n Vvedite N: ";
cin >> N;
sozdan(a,N);
cout << "\n Tabliza dannih sozdana.";
getch();
break;
case 2:
cout << "\n Vivod na ekran ";
output(a);
cout << "\n Vivod na ekran zavershen.";
getch();
break;
case 3:
cout << "\n Vivod v fail a.dat ";
output_file(a,N);
cout << "\n Vivod v fail uspeshno zavershen.";
getch();
break;
case 4:
cout << "\n Chtenie iz faila a.dat ";
input_file(a);
cout << "\n Chtenie iz faila uspeshno zavershena.";
getch();
break;
case 5:
cout << "\n Poisk obyekta ";
cout << "\n Vvedite kluch dlya poiska(nazvanie alboma): ";
char *nazv;
cin >> nazv;
Tool *n;
// n=NULL;
n = pois(a,nazv);
if (n==NULL) cout << "\n Zapis ne naidena.";
else
{
cout << "\n Zapis bila naidena.";
caption();
n->d->output();
}
delete nazv;
getch();
break;
case 6:
cout << "\n Redaktirovanie zapisi ";
cout << "\n Vvedite nomer zapisi: ";
int c;
cin >> c;
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 << "\n Redaktirovanie uspeshno zaversheno.";
getch();
break;
case 7:
cout << "\n Vstavka novoi zapisi ";
cout << "\n Vvedite tip novoy zapisi [0..2]: ";
int p = 0;
cin >> p;
a->current=a->tail;
a->add(p,1);
cout << "\n Vstavka zapisi uspeshno zaversena.";
getch();
break;
case 8:
cout << "\n Udalenie zapisi ";
cout << "\n Vvedite nomer zapisi dlya udalenia: ";
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;
delete q;
a->current = a->tail;
break;
}
a->current=a->current->right;
}
cout << "\n Zapis bila udalena.";
getch();
break;
case 9:
cout << "\n Poisk obyekta s minimalnim kl-vom trekov v zadannom diapazone let";
cout << "\n Vvedite leviy predel poiska(god): ";
int godL,godR;
cin >> godL;
cout << "\n Vvedite praviy predel poiska(god): ";
cin >> godR;
Tool *k;
k = zadacha(a,godL,godR);
if (n==NULL) cout << "\n Zapis ne naidena.";
else
{
cout << "\n Zapis bila naidena.";
caption();
k->d->output();
}
getch();
break;
case 10:
delete a;
exit(0);
break;
}
}
}
void sozdan(Trist *&a, int n)
{
if (a!=NULL)
delete a;
cout << "\nVvedite tip zapisi [0..2]: ";
int k;
cin >> k;
a = new Trist(k,1);
for (int i=1;i<n;i++)
{
cout << "\nVvedite tip zapisi [0..2]: ";
cin >> k;
a->add(k,1);
}
}
void output(Trist *&a)
{
caption();
a->current=a->head;
while (a->current!=NULL)
{
a->current->d->output();
a->current=a->current->right;
}
}
void output_file(Trist *&a, int n)
{
ofstream file("a.dat",ios::out|ios::binary);
if (!file)
{
cerr << "\nOshibka vivoda v fail!\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;
int trek = obj1->getTrek();
file.write((char*)&(trek),sizeof(trek));
break;
case 1:
album2 *obj2;
obj2=(album2*)a->current->d;
trek = obj2->getTrek();
int time = 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();
int bonus = 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();
}
void input_file(Trist *&a)
{
ifstream file("a.dat",ios::in);
if (!file)
{
cerr << "\nOshibka chtenia faila!\n";
getch();
exit(1);
}
int n;
file.read((char*)&(n),sizeof(n));
int i;
delete a;
for (i=0;i<n;i++)
{
int t;
file.read((char*)&(t),sizeof(t));
if (i==0) a=new Trist(t,0); else a->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;
int trek = 0;
file.read((char*)&(trek),sizeof(trek));
obj1->setTrek(trek);
break;
case 1:
album2 *obj2;
obj2=(album2*)a->current->d;
trek = 0;
int time = 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;
int bonus = 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;
else n=NULL;
a->current=a->current->right;
}
return n;
}
Tool* zadacha(Trist *&a,int godL,int godR)
{
Tool *k = NULL;
a->current=a->head;
int max=1000;
while (a->current!=NULL)
{
k = a->current;
if(k->d->god>godL)
if(k->d->god<godR)
if(k->d->trek<min) break;
else k=NULL;
a->current=a->current->right;
}
return k;
̲Ͳ ² ֲ Ͳ Ͳ "ʲ ˲Ͳ " __________ /xxxxxxxxx./ &qu
Copyright (c) 2024 Stud-Baza.ru , , , .