+ n;,
n , .
', n - ', , n , '. , int 4 , .
, .
, 1< p2, 2 - 1+1 1 2 .
, :
;
(+5);
, ;
.
.
:
1 = mas; ++,
, mas .
.
2.4 .
.
// P2_7.CPP
//
//
#include < iostream>
Using namespace std;
Main()
{
const int n = 5;
float mas[n], s = 0;
int kol = 0;
for(int i = 0; i < n; i++)
{
cout << "" << << " mas" << endl;
cin >> mas[ i ];
if (mas[ i ] > 0)
{
s += mas[ i ];
kol ++;
}
}
s / = kol;
cout << "s=" << s << endl;
Return 0;
}
' ( ), :
// P2_8.CPP
//
//
#include < iostream>
Using namespace std;
Main ()
{
const int n = 5;
float mas[n], s = 0;
int kol = 0;
for (int i=0; i < n; i++)
{
cout << "" << << " mas" << endl;
cin >> *(mas+i);
if(* (mas+i) > 0)
{
s+= *(mas+i);
kol++;
}
}
s/=kol;
cout << "s=" << s << endl;
Return 0;
}
, ' ( ), , :
// P2_9. CPP
//
//
#include < iostream>
Using namespace std;
Main ()
{
int kol = 0;
const int n = 5;
float mas[n], s = 0;
float *pm = mas; // pm=&mas[0]
for (int = 0; < n; ++)
{
cout <<""<< <<" mas" << endl;
cin >> *pm++;
cout << mas[i] << endl;
|
|
if (mas[i] > 0)
{
s+=mas[i];
kol++;
}
}
s/= kol;
cout << "s=" << s << endl;
Return 0;
}
*pm, ' . *pm, . , *pm (pm++) .
.
// P2_10.
//
//
#include < iostream>
Using namespace std;
Main ()
{
const int n = 5;
float mas[n], s = 0;
float *pm = mas; // *pm=&mas[0]
int kol = 0;
for (int i = 0; i < n; i++)
{
cin >> *pm;
cout << "" << << " mas" << endl;
if (*pm > 0)
{
s += *pm;
kol ++;
}
pm ++;
}
s/= kol;
cout << "s=" << s << endl;
Return 0;
}
2.5.
.
// P2_11.CPP ( )
//
#include < iostream.h >
#include < conio.h >
Main ()
{
int stc, mas [6], i, j;
int *pmas;
pmas = mas;
cout << " 6 " << endl;
for (i = 0; i < 6; i++) cin >>*pmas++;
//
// ( )
pmas = mas;
for (i =1; i < 6; i++)
{
stc = *(pmas + i);
j = i - 1;
while (j >= 0 && stc > *(pmas+j))
{
*(pmas+j+1) = *(pmas+j);
J - -;
}
*(pmas+j+1) = stc;
}
cout << "" << endl;
for (i = 0; i < 6; i++)
cout << i << " " << *(pmas + i) << endl;
//
// cout << i << " " << * pmas++ << endl;
getch (); //
Return 0;
}
2.5
, , '. "" . : . ', , , , .
Fio
(0) | -> | \0 | |||||||
(1) | -> | \0 | |||||||
(2) | -> | \0 | |||||||
(3) | -> | \0 | |||||||
(4) | -> | \0 | |||||||
(5) | -> | \0 |
.
// P2_11.CPP
#include < iostream>
Using namespace std;
Main ()
{
char *fio [ ] = { "",
"",
|
|
"",
"",
"",
" " };
Int str;
for (str = 0; str <= 5; str++)
cout << " stroka " <<(str +1) << = << *(fio+str) << endl;
Return 0;
}
, . , , : int matr[5][7]; int *pmt [5];.
, , , mas [i][j]. , mas [i][j] :
* (pm[i]+j) *(*(pm+i)+j).
2.6 , , .
.
// P2_12.CPP .
#include < iostream>
Using namespace std;
Void main()
{
int mat [2][3];
int , j;
cout << " "<< endl;
for (i = 0; i < 2; i++)
for (j = 0; j < 3; j++)
cin >> mat [i] [j];
//
cout << " mat " << endl;
for (i = 0; i < 2; i++)
{
for (j = 0; j< 3; j++)
{
if ((mat [i][j] %2 == 0)
mat[i][j] = mat[i][j] + 5;
cout << mat [i][j] << " ";
}
cout << endl; //
}
}
.
//P2_13.CPP :
#include < iostream>
Using namespace std;
Main ()
{
int , j, *pm[2];
cout << " "<< endl;
for (i = 0; i < 2; i++)
for (j = 0; j < 3; j++)
cin >> *(pm[i] + j);
cout << " R "<< endl;
for (i = 0; i < 2; i++)
{
for (j = 0; j < 3; j++)
{
if (*(pm[i] + j) %2 == 0)
*(pm [i] + j) += 10;
cout << *(pm [i] + j) << " ";
}
cout << endl;
}
Return 0;
}
:
out << ((j == 0)? '\t':' ') << *(pm[i]+j) << ((j == 2)? '\n':' ');
' - -, , mat [2] [2] :
mat [0] - ;
mat [1] - ;
mat [2] - ;
: mat[0] == &mat[0][0];
mat[1] == &mat[1][0];
mat[2] == &mat[2][0];
:
cout << mat [i] [j];
cout << *(mat [i] +j);
cout << *(* (mat +i)+j);
++ , " ". "*" , int ** pmt; ' . . , :
int x = 20;
int *px1 = &x;
int** px2 = &px1;
int ***px3 = &px2;
x : *px1; **px2; ***px3;.
' "*", , x:
Px1 [0] *px1;
Px2 [0][0] **px2;
Px3 [0][0][0] ***px3;
2.6
|
|
1. ?
2. ?
3. '?
4. C++ ' '?
5. , ?
6. ?
7. C++ ?
8. ?
2.7.
.
1. (15).
2. (12) .
3. 䒺 (15) , . .
4. (17) .
5. 20 . , 5 4.
6. (15).
7. ³ (17) .
8. H(15) .
9. (15), , 1, 2.
10. ³ Y(20) .
11. (15), , 1, 2.
12. , a = 10,5; i , 10 .
13. K(3,5) .
14. (4,5) 1, 0.
15. 䒺 (3,4) , .
16. Matr(3,5), , 1, 2.
17. X(10) Y(10), Z(i,j) = Xi+Yj, j,j=10..1.
18. (5,5).
19. 䒺 , (5,5).
20. (5,5) .
21. Q(3,5).
22. , (5,5).
23. (5,4).
24. (4,4) .
25. (5,5) , .
3 в
3.1 ֳ
.
3.2
, , .
. ++ . ++ , 䳿 . : , , , ..
|
|
++ .
, . , : , , \ .
char . ' char ', . char ( -128 127). unsigned char ' 0 255.
, ("), : " ". ³ ', (\0), \0 . char [ ]. 1, . . ENTER. , .
3.2.1 -
- ++ , - .
++ - . : , , .. , ++ - , , , . . <string.h>. - ++ , stdin, ( ), ( ) ' stdout. ֳ ' stdprn, ' stdaux, ' stderr. cout , ' stdout , cin , (stdin).
:
¾ ofstream;
¾
ofstream prn ("PRN");
prn << " "<< endl;
prn << name1 << name2... <<endl;
DOS .
3.1 ( ') .
// P3_1.PP
#include < fstream>
#include < iostream>
Using namespace std;
Main ()
{
char fio [15];
char name [10];
cout << " ";
cin >> fio;
cout << " ' ";
cin >> name;
// fio name
ofstream prn ("PRN");
prn << " " << endl;
prn << name << fio << endl;
Return 0;
}
- (get () put ()) (getch () (putch ()) , :
Device. get (char_var);
device. put (char_var);,
device - .
. get() , , ENTER . getch() , , . getche (). get() put () - . - ifstream.
3.2 , ' .
|
|
// P3_2.CPP
// getch() put ()
#include < fstream>
#include < iostream>
Using namespace std;
#include < conio.h >
Main ()
{
Int str;
char slovo [5];
cout << " 5 " << endl;
for (str = 0; str < 5; str++)
{
slovo [str] = getch ()
}
//
ofstream prn ("PRN");
prn << " << endl;
for(str = 0; str < 5; str++)
{
prn.put (slovo [str]);
}
Return 0;
}
< conio.h >, getch () put() DOS.
3.2.2