,   CyberForum.ru

- C++

 
artemi
0 / 0 / 0
: 03.02.2010
: 21
19.04.2010, 14:26     #1
.: , : , , ; ( ); .
*30, .
( *25).
.
, ,
.
.

:
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#include <iostream.h>
#include <conio.h>
#include <fstream.h>
#include <string.h>
#include <iomanip.h>
#include <math.h>
#include <stdlib.h>
 
struct Student   //îñ*îâ**ÿ ñòðóêòóð*
 
{
char fam[20];   //ô*ìèëèÿ
char name[20];    //èìÿ
char otc[20];  //îò÷åñòâî
char nomer[6];   //*îìåð  ãðóïïû
int srb;   //ñðåä*èé á*ë
int zar;  //ç*ðïë*ò*
};
 
 
 
class Studenti     //êë*ññ äè**ìè÷åñêèé ì*ññèâ ñòðóêòóð
{
 private:
  Student *st;    //óê*ç*òåëü ** ì*ññèâ ç*ïèñåé
   int n;         //÷èñëî ñòðîê â ì*ññèâå
  int f;      //÷èñëî **éäå**ûõ ñòðîê
 public:
  Studenti(){n=0;st=NULL;} //êî*ñòðóêòîð
  Studenti(int);//êî*ñòðóêòîð ñ ï*ð*ìåòð*ìè
  Studenti(const Studenti&);//êî*ñòðóêòîð êîïèðîâ**èÿ
  ~Studenti(){n=0;if(st!=NULL)delete[]st;} //äåñòðóêòîð
   void newBD(); //ñîçä**èå *îâîé ÁÄ
  void PRINT(); //âûâîä ÁÄ ** ýêð**
  void redaktor(); //ðåä*êòèðîâ**èå ÁÄ
  int vuibor(); //âûáîð *óæ*îé ñòðîêè
  void add(); //äîá*âëå*èå *îâîé ç*ïèñè
  void delt(); //óä*ëå*èå ç*ïèñè
   void sortBD(); //ñîðòèðîâê* ïî *îìåðó
   void Obchejitie();//îáùåæèòèå
  };
 Studenti::Studenti(int newSize)//êî*ñòðóêòîð ñ ï*ð*ìåòð*ìè
 {
  n=0;
  if(0<=newSize)
  n=newSize;
  else cout<<"Size error"<<newSize<<endl;
  st=new Student[n];
  }
 
 Studenti::Studenti(const Studenti& newStudenti)//êî*ñòðóêòîð êîïèðîâ**èÿ
 {
  n=newStudenti.n;
  st=new Student[n];
  memcpy(st,newStudenti.st,sizeof(int)*n);
  }
void Studenti::newBD() //ñîçä**èå *îâîé ÁÄ
{int i;   //ð*áî÷*ÿ ïåðåìå***ÿ äëÿ ïîäñ÷¸ò*
      do
    {
cout<<"Kolichestvo zapisey=";cin>>n;
    }
    while (n<1 || n>30);//êîëè÷åñòâî ç*ïèñåé *å áîëèå 30
   if(st!=NULL)delete[] st; //î÷èñòê* ð*áî÷åé îáë*ñòè(ì*ññèâ*)
 st=new Student[n];     //âûäåëå*èå äè**ìè÷åñêîé ï*ìÿòè
 if(st==NULL){cout<<"Net pamyati\n";getch();n=0;return;}
  //ñîçä**èå á*çû ä***ûõ
 for(i=0;i<n;i++)
 {
  cout<<"Familiy:      ";cin>>st[i].fam;
  cout<<"Name:         ";cin>>st[i].name;
  cout<<"Otchestvo:    ";cin>>st[i].otc;
  cout<<"Nomer gruppi:";cin>>st[i].nomer;
  cout<<"Sredniy bal: ";cin>>st[i].srb;
  cout<<"Dahod na 1 chlena semyi: ";cin>>st[i].zar;
  cout<<endl;
 }cout<<"Massiv dannuih sozdan";getch();
}
 
void Studenti::PRINT() //âûâîä ÁÄ ** ýêð**
{int i; //ïåðåìå***ÿ äëÿ ïîäñ÷¸ò*
 if(st==NULL){cout<<"Massiv pust\n";getch();return;}
 clrscr(); //î÷èñòê* ýêð***
 cout.setf(ios::left); //âûð*â*èâ**èå ñëåâ*
 cout<<endl<<"Spisok studentov gruppi\n"<<endl;
 cout<<"N"<<" "<<setw(12)<<"Familiy"<<setw(12)<<"Name"<<setw(12)<<"Otchestvo"<<setw(12)<<"Nomer gruppi"
 <<setw(12)<<"Srrdniy bal"<<setw(12)<<"Dahod"<<endl;
  //âûâîä ÁÄ ** ýêð**
for(i=0;i<n;i++)
  {cout.setf(ios::left);  i++;
 cout<<setw(3)<<i<<setw(12)<<st[i-1].fam<<setw(12)<<st[i-1].name<<setw(12)<<st[i-1].otc
 <<setw(12)<<st[i-1].nomer<<setw(12)<<st[i-1].srb<<setw(12)<<st[i-1].zar<<endl;
 i--;} ;
    getch();
}
 
int Studenti::vuibor()  //âûáîð *óæ*îé ñòðîêè
{int k; //ð*áî÷*ÿ ïåðåìå***ÿ äëÿ âûáîð* ñòðîêè
 cout.setf(ios::left); //âûð*â*èâ**èå ñëåâ*
 PRINT(); //âûçûâ*åòñÿ ôó*êöèÿ âûâîä* ÁÄ ** ýêð**
 cout<<"Vuiberite stroku: ";cin>>k;
if(k<0|| k>n+1){cout<<"Net takoi stroki\n";getch();}
 k--;
 return k;
}
 
void Studenti::redaktor()  //ðåä*êòèðîâ**èå ÁÄ
{int j, //ð*áî÷*ÿ ïåðåìå***ÿ äëÿ âûáîð* ïó*êò*
 N;  //ð*áî÷*ÿ ïåðåìå***ÿ äëÿ âûçîâ* ôó*êöèè
 if(st==NULL){cout<<"Massiv pust\n";getch();return;}
 N=vuibor(); //âûçûâ*åòñÿ ôó*êöèÿ âûáîð* ñòðîêè
 while(1)
 {clrscr(); //î÷èñòê* ýêð***
{cout.setf(ios::left);
 cout<<setw(12)<<st[N].fam<<setw(12)<<st[N].name<<setw(12)<<st[N].otc<<setw(12)<<st[N].nomer
 <<setw(12)<<st[N].srb<<setw(12)<<st[N].zar<<endl;
 }
 
 cout.setf(ios::left); //âûð*â*èâ**èå ñëåâ*
  cout<<"1.Familiy\n"<<"2.Name\n"<<"3.Otvhestvo\n"<<"4.Nomer gruppi\n"<<"5.Sredniy bal\n"<<"6.Dohod na 1 chlena semiy\n"
  <<"7.menu\n"
  <<"Vash vuibor ";cin>>j;
  if(cin.good())
  //âûáîð ðåä*êòèðóåìîãî ïîëÿ
  switch(j)
  {case 1:cout<<"Familiy: ";cin>>st[N].fam;break;
   case 2:cout<<"Name:    ";cin>>st[N].name;break;
   case 3:cout<<"Otchestvo: ";cin>>st[N].otc;break;
   case 4:cout<<"Nomer gruppi: ";cin>>st[N].nomer;break;
   case 5:cout<<"Sredniy bal: ";cin>>st[N].srb;break;
   case 6:cout<<"Dohod: ";cin>>st[N].zar;break;
   case 7:return;
   default :cout<<"Neverniy vuibor\n povtorite\n";getch();
  }
  else
  {cout<<"Oshibka vvoda\n";getch();
  cin.clear();  //î÷èñòê* ïîòîê* ââîä*
    while(cin.get()!='\n')
         return;
   }
 }
}
 
void Studenti::add()
{int i;
 Student t,
 *p;
  if(st==NULL){cout<<"massiv pyst\n";getch();return;}
 cout<<"Familiy: ";cin>>t.fam;
 cout<<"Name: ";cin>>t.name;
 cout<<"Otchedtvo: ";cin>>t.otc;
 cout<<"Nomer gruppi: ";cin>>t.nomer;
 cout<<"Sredniy bal: ";cin>>t.srb;
 cout<<"Dohod: ";cin>>t.zar;
 p=st;
 st=new Student[n+1];
 if(st==NULL){cout<<"Net pamyati.\n";getch();return;}
 for(i=0;i<n;i++)
 st[i]=p[i];
 st[n]=t;
 n++;
 delete[]p;
 cout<<"Zapis dobavlena\n";getch();
}
 
void Studenti::delt()
{int i,N;
Student *t;
if(st==NULL){cout<<"Massiv pust\n";getch();return;}
t=new Student[n-1];
if(t==NULL){cout<<"Net pamyati\n";getch();n=0;return;}
if(n==1){delete[] st;st=NULL;}
else {N=vuibor();
for(i=0;i<N;i++)
t[i]=st[i];
for(i=N+1;i<n;i++)
t[i-1]=st[i];
delete[] st;
st=t;
}
n--;cout<<"zapis udalena\n";getch();
}
 
        void Studenti::sortBD()
{
   int fl,i,l;
   Student t;
   if(st==NULL){cout<<"Massiv pust\n";getch();return;}
  l=n-1;
  do
  {
   fl=0;
   for(i=0;i<l;i++)
    if(st[i].srb>st[i+1].srb)
    {
      t=st[i];
      st[i]=st[i+1];
      st[i+1]=t;
      fl=1;
    }
    else if(st[i].srb==st[i+1].srb)
     {
      if(strcmp(st[i].fam, st[i+1].fam )>0)
    {
      t=st[i];
      st[i]=st[i+1];
      st[i+1]=t;
      fl=1;
    }
    }
l--;
}
  while(fl==1);
 PRINT();
  return;
 
}
void Studenti::Obchejitie()
{
  Student t,*px;
 cout<<"Kolichestvo zapisey=";cin>>n;
  int i;   //ð*áî÷*ÿ ïåðåìå***ÿ äëÿ ïîäñ÷¸ò*
  px=new Student[n];     //âûäåëå*èå äè**ìè÷åñêîé ï*ìÿòè
 clrscr(); //î÷èñòê* ýêð***
 if(st==NULL){cout<<"Massiv pust\n";getch();return;}
 int z,sum;
  cout<<"Vvedite razmer bazovoy velecheni=";cin>>z;
 sum=3*z;
 cout.setf(ios::left); //âûð*â*èâ**èå ñëåâ*
 cout<<endl<<"Spisok studentov gruppi\n"<<endl;
 cout<<"N"<<" "<<setw(12)<<"Familiy"<<setw(12)<<"Name"<<setw(12)<<"Otchestvo"<<setw(12)<<"Nomer gruppi"
 <<setw(12)<<"Sredniy bal"<<setw(12)<<"Dahod"<<endl;
  //âûâîä ÁÄ ** ýêð**
 for(i=0;i<n;i++)
  if(st[i].zar<sum){
 t=st[i];
 st[i]=px[i];
 px[i]=t;
   cout.setf(ios::left);  i++;
 cout<<setw(3)<<i<<setw(12)<<px[i-1].fam<<setw(12)<<px[i-1].name<<setw(12)<<px[i-1].otc
 <<setw(12)<<px[i-1].nomer<<setw(12)<<px[i-1].srb<<setw(12)<<px[i-1].zar<<endl;
 i--;
 }
     getch();
 
              }
 
void main ()
{Studenti a[25];
 
 
 int j, fl;
 while (1)
 {clrscr();
  cout<<"                         "<<"1.Novaya baza dannuih\n"
      <<"                         "<<"2.Redaktirovanie bazui dannuih\n"
      <<"                         "<<"3.Dobavlenie novoi zapisi\n"
      <<"                         "<<"4.Udalenie zapisi\n"
      <<"                         "<<"5.Prosmotr bazui dannuih\n"
      <<"                         "<<"6.Sortirovka\n"
      <<"                         "<<"7.Obchejitie\n"
      <<"                         "<<"0.Vuihod\n"
      <<"Vash vuibor:";cin>>j;
  if(cin.good())
   switch(j)
   {case 1:a[25].newBD();break;
    case 2:a[25].redaktor();break;
    case 3:a[25].add();break;
    case 4:a[25].delt();break;
    case 5:a[25].PRINT();break;
    case 6:a[25].sortBD();break;
    case 7:a[25].Obchejitie(); break;
    case 0:cout<<endl<<"Poka"<<endl;getch ();return;
    default :cout<<"Neverniy vuibor\n povtorite\n";getch();
   }
   else
   {cout<<"Oshibka vvoda\n";getch();
    cin.clear();
    while(cin.get()!='\n')
     continue;
   }
 }
 
         }
Similar
41792 / 34177 / 6122
: 12.04.2006
: 57,940
19.04.2010, 14:26    
:

C++
C++
C++
C++ ++
++ C++
C++ c++
C++
C++



:
.

: 11:13. GMT +3.
- , ,
-
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
@Mail.ru