6.2
. , . , , , . - . .
( ) :
namespace [ _ ]{ /* */ }
, . , .
, , . static. , . .
.
namespace demo{
int i = 1; int k = 0;
void fund (int);
void func2(int) { /*... */ }
}
namespace demo{ //
// int i = 2; -
void funcl(double); //
void func2(int); // ( )
}
, . , ::, :
void demo::fund(int) { /*... */ }
. .
, , . ::, :
demo::i = 100; demo::func2(10);
, using:
using demo::i: .
- , using namespace:
using namespace demo:
using using namespace , :
namespace Department_of_Applied_Mathematics{ using demo::i; //... }
, using, , usi ng namespace ( , ).
|
|
, , :
namespace DAM = Department_of_Applied_Mathematics;
. std. , / <stdio.h> :
// stdio.h namespace std{
int feof(FILE *f);
}
using namespace std;
. , , <cstdio>:
// cstdio
namespace std{
int feof(FILE *f);
}
<cstdio>, :
std::feof(f);
finclude .
, (, , ), , , , , . , , . , .
// .
#include <iostream>
#include <conio.h>
#include <stdlib.h>
using namespace std;
struct Tadres
{
char strace[80];
int numDom;
int numKv;
};
struct TStudent
{
char fio[80];
Tadres adres;
int pos;//
};
void SetAdres(Tadres& adres)
{
cout<<"Vvedite name ulici"<<endl;
cin.getline(adres.strace,80);
cout<<"Vvedite nomer doma"<<endl;
char str[1000];
cin.getline(str,1000);
adres.numDom=atoi(str);
cout<<"Vvedite nomer kvartiri"<<endl;
cin.getline(str,1000);
adres.numKv=atoi(str);
};
void SetGrup(TStudent *Grup,int n)
{
for (int i(0);i<n;i++)
{
cout<<"Vvedite FIO "<<i<<" student:"<<endl;
cin.getline(Grup[i].fio,80);
SetAdres(Grup[i].adres);
Grup[i].pos=i;
}
};
void OutputStudent(TStudent *Grup,int n,int kol)
{
if(n>=kol)
{
cout<<"Student not found"<<endl;
return;
}
cout<<"FIO: "<<Grup[n].fio<<endl;
cout<<"Adres: "<<Grup[n].adres.strace<<" "<<Grup[n].adres.numDom<<" "<<Grup[n].adres.numKv<<endl;
};
int main()
{
int kolS;//
char ch;
int num;
char str[1000];
cout<<"Vvedite kolichestvo studenta"<<endl;
|
|
cin.getline(str,1000);
kolS=atoi(str);
if (kolS<=0)return 1;
TStudent *BIKS = new TStudent [kolS];
SetGrup(BIKS,kolS);
do //
{
cout<<"Vvedite num studenta"<<endl;
char str[1000];
cin.getline(str,1000);
num=atoi(str);
OutputStudent(BIKS,num,kolS); //
cout<<"Zakonchit' Y/N"<<endl;
ch=getch();
}while((ch!='y')&&(ch!='Y')&&(ch!='')&&(ch!=''));
getch();
delete [] BIKS;
return 0;
}
6.4
6.6
.
1. . . .
2. (*.h).
1
STUDENT, : - ;
- ;
- ( ). , :
- , STUDENT; ;
- , , 4.0;
- , .
2
STUDENT, ; - ;
- ;
- ( ). , :
- , STUDENT; ;
- , 4 5;
- , .
3
STUDENT, :
- ; - ;
- ( ). , :
- , STUDENT; ;
- , 2;
- , .
4
AEROFLOT, :
- ;
- ;
- .
, :
- , AEROFLOT; ;
- , , , ;
- ,
5
AEROFLOT, :
- ;- ;
- .
, :
- , AEROFLOT; ;
- , , ;
- , .
6
WORKER, :
|
|
- ;
- ;
- .
, :
- , WORKER; ;
- , , ;
- , .
7
TRAIN, :
- ;
- ;
- .
, :
- , TRAIN; ;
- , ;
- , .
8
TRAIN, :
- ;
- ;- .
, :
- , TRAIN; ;
- , , ;
- , .
9
TRAIN, :
- ;
- ;
- .
, :
- , TRAIN; ;
- , ;
- , .
10
MARSH, :
- ;
- ;
- .
, :
- , MARSH; ;
- , ;
- , .
11
MARSH, :
- ;
- ;
- .
, :
- , MARSH; ;- , , ;
- , .
12
NOTE, :
- , ;
- ;
- ( ).
, :
- , NOTE; ;
- , ;
- , .
|
|
13
NOTE, :
- , ;
- ;
- ( ).
, :
- , NOTE; ;
- , , ;
- , .
14
NOTE, :
- , ; - ;
- ( ).
, :
- , NOTE; ;
- , ;
- , .
15
ZNAK, :
- , ;
- ;
- ( ).
, :
- , ZNAK; ;
- , ;
- , .
16
ZNAK, :
- , ;
- ;
- ( ).
, :
- , ZNAK; ;
- , , !
- , .
17
ZNAK, : - , ;
- ;
- ( ).
, :
- , ZNAK; ;
- , , ;
- , .
18
PRICE, :
- ;- , ;
- .
, :
- , PRICE; ;
- , ;
- ,
19
PRICE, :
- ;
- , ;
- .
, :
- , PRICE; ;
- , , ;
- , .
20
ORDER, :
- ; - ;
- .
, :
- , ORDER; ;
- , , ;
- , .
21
STUDENT, ; - ;
- ;
- ( ). , :
- , STUDENT; ;
|
|
- , ;
22
STUDENT, ; - ;
- ;
- ( ). , :
- , STUDENT; ;
- , 2.0 4.5.
23
PRICE, :
- ;
- , ;
- .
, :
- , PRICE;
- , , ;
- ,
24
PRICE, :
- ;
- , ;
- .
, :
- , PRICE;
- , ;
- ,
25
COMP, :
- ;
- ;
- .
, :
- , COMP;
- ;
25
COMP, :
- ;
- ;
- .
, :
- , COMP;
- 64 1024.
26
COMP, :
- ;
- ;
- .
, :
- , COMP;
- 128 1000.
STUDENT, :
- ;
- ;
, :
- ;
- ;
- .
:
main.cpp
#include"student.h"
using namespace grup;
int main()
{
int n;
cout<<"Vvedite kolichestvo studentov=";
char kolTMP[10]; //
cin.getline(kolTMP,10); //
n=atoi(kolTMP); //
if(!n) return 1;
Stud *PMM=new Stud[n];
input(PMM,n);
output(PMM,n);
Stud *StudMin=serchMin(PMM,n);
cout<<"Student s minim balom:"<<endl;
cout<<StudMin->FIO<<'\t'<<StudMin->bal<<endl;
cin.get();
delete []PMM;
return 0;
}
student.h
#include<iostream>
using namespace std;
namespace grup
{
struct Stud
{
char FIO[80];
float bal;
};
void input(Stud *IB,int n);
//
void output(Stud *IB,int n);
//
Stud *serchMin(Stud *IB,int n);
// a
}// namespace grup
void grup::input(Stud *IB,int n)
//
{
for(int i=0;i<n;i++)
{
cout<<"Vvedite imja Studenta "<<endl;
cin.getline(IB[i].FIO,80);
char strTMP[10];
cout<<"Vvedite bal Studenta "<<endl;
cin.getline(strTMP,80);
IB[i].bal=atoi(strTMP);
}
};
void grup::output(Stud *IB,int n)
//
{
for(int i=0;i<n;i++)
{
cout<<IB[i].FIO<<'\t'<<IB[i].bal<<endl;
}
};
grup::Stud *grup::serchMin(Stud *IB,int n)
// a
{
Stud *Min;
Min=&IB[0];
for(int i=1;i<n;i++)
if(Min->bal>IB[i].bal)
Min=&IB[i];
return Min;
};
7
++ , .
7.2
, . . , , , .
' (-) (-) . , , .
7.2.1 ˳
, , . : .
7.2.2 ( )
, . m . , , , , m, ; , , m.
: , , . , , .
. , xi > xi+1 (i=1n-1), . i- ( ) , , () . .., . , n-1 .
X(n) , , . C(n). i+1 xi R(n).
. , . :
(x) ( ). , i>x, , j<x. , ( i j ). , , x, x, x ;
1 ( ) , , . .
' . X(n) Y(m). ' Z(n+m), . : X Y ( x1 y1) Z, , , , . , . X, Y Z, Y, Z X.
7
#include<iostream.h>
#include<stdio.h>
#define b=16
int n=6;
int a[6];
int i,j,l,r=6;
void swap(int*,int*);
Void quicksort(int,int);
void part(int,int,int&,int&);
Int main()
{ for(int k=1;k<=n; k++)
{cout << "input ["<<k<<"] of massive \n";
cin >> a[k]; }
quicksort(1,n); //
for(k=1; k<=n; k++)
{printf("a[ %d ]= %d \n",k,a[k]);}
cin>>k;
Return 0;
}
void swap(int* p,int* q)
{ int prom;
prom=*p;
*p=*q;
*q=prom; }
void quicksort(int l,int r) //
{ int i,j; i=l; j=r;
{ part(l,r, i, j);
if(i<r) quicksort(i,r); //
if(j>l) quicksort(l,j); } //
}
void part(int l,int r,int &i,int &j)
{ int x; i=l; j=r; x=(l+r)/2;
do { while (a[i]<a[x]) i++; // : a[j]> a[x]
while(a[j]>a[x]) j--; // : a[j]< a[x],
if(i<=j)
{ swap(&a[i],&a[j]); //
i++;j--; }
} while(i<j); }
7.3
1. , ?
2. , .
3. , , ?
4. , , .
5. a b d.
6. . ?
7. , , ?
2 2 . .
1. ., . : . . .: , 1992. 272 .
2. . ++. 1. : "", 1993. 264 .
3. . ++. 2. : "", 1993. 296 .
4. .. +: . . .: , 1995. 400 .
5. .. . ++. : , 2002. 500 .
6. .., .. ++.- .: ̻, 2000 . 1024 .
7. . , , .-M.:,1985.
8. .. . . . .:, 1993. 224.
9. . : .-: , 1994. 221.
10. . : . . .: , 1994. 160 .