.


:




:

































 

 

 

 





. 7 ( ) :

struct zap {

int key; //

int info; //

} data;

{59,1}, {70,3}, {96,5}, {81,7}, {13,8}, {41,2}, {79,9}; - m = 10. - i = h (data) = data. key %10; .. 10 i Î[0,9].

-.

(-):

i = 59 % 10 = 9; i = 70 % 10 = 0;

i = 96 % 10 = 6; i = 81 % 10 = 1;

i = 13 % 10 = 3.

81 41 1 . - , i = 2.

79 : 9 . , .. 6 (), i = 4. 19 .

 

. :

struct zap {

int key; //

int info; //

zap *Next; //

} data;

-, , .

, , (-): 9, 0, 6, 1, 3.

. 41 81, 79 59.

 

 

8.

1.

, , ( / ).

 

1. ,
50 +50 . , . .

2. .

3. ( 10 10) .

4. .

5. , 5.

6. , .

7. . , .

8. . , .

9. , , , .

10. , , , .

11. , .

12. , : , .

13. 1 10, .

14. .

15. .

 

2.

, , .

 

1. . .

2. . .

3. . , .

4. .

5. . , .

6. . , .

7. . , , , .

8. . , , .

9. . , .

10. . , , .

11. . .

12. , 5.

13. . , .

14. . . .

15. . , .

9.

 

1.

, , , , ( ). :

;

;

;

;

;

;

.

1. , .

2. .

3. , .

4. .

5. .

6. .

7. .

8. .

9. , .

10. .

11. , .

12. , .

13. .

14. , .

15. , .

 

 

2.

. , % . (. 15.1).

, (a + b)*(c d)/ e = 3, b = 5, c = 6, d = 9, = 7, :

ab + cd * e /

3.42857

15.1

a b c d e
1 a /(b c)*(d + e) 8.6 2.4 5.1 0.3 7.9 26.12
2 (a + b)*(c d)/ e 7.4 3.6 2.8 9.5 0.9 81.89
3 a (b + c * d)/ e 3.1 5.4 0.2 9.6 7.8 2.16
4 a / b ((c + d)* e) 1.2 0.7 9.3 6.5 8.4 131.006
5 a *(b c + d)/ e 9.7 8.2 3.6 4.1 0.5 168.78
6 (a + b)*(c d)/ e 0.8 4.1 7.9 6.2 3.5 2.38
7 a *(b c)/(d + e) 1.6 4.9 5.7 0.8 2.3 0.413
8 a /(b *(c + d)) e 8.5 0.3 2.4 7.9 1.6 1.151
9 (a +(b / c d))* e 5.6 7.4 8.9 3.1 0.2 0.666
10 a *(b + c)/(d e) 0.4 2.3 6.7 5.8 9.1 1.091
11 a (b / c *(d + e)) 5.6 3.2 0.9 1.7 4.8 17.51
12 (a b)/(c + d)* e 0.3 6.7 8.4 9.5 1.2 0.429
13 a /(b + c d * e) 7.6 4.8 3.5 9.1 0.2 1.173
14 a *(b c)/(d + e) 0.5 6.1 8.9 2.4 7.3 0.144
15 (a + b * c)/(d e) 9.1 0.6 2.4 3.7 8.5 2.196


16.

 

++ ANSI , - .

.

 

-

, . ++ (stdin, stdout), . , .

- ++ iostream: cin ( istream), cout ( ostream) . iostream.h.

<< ( ) >> ( ) :

cout << ID ;

cin >> ID ;

cout stdout ( ), cin stdin, .. . :

#include<iostream.h>

void main (void)

{

int i, j, k;

cout << Hello! << endl; // end line

cout << Input i, j ;

cin >> i >> j;

k = i + j;

cout << Sum i, j = << k << endl;

}

ANSI - . .

, , , .

 

, . , , .

iostream. h iomanip. h ( ).

.

#include<iomanip.h>

main()

{

int a = 157;

double b = 1.55555;

cout << setw(10) << a << endl;

/* setw (n) , .. n , . 8- , 7 : 157 ( ). . */

cout << setw(10) << setfill(z) << a << endl;

/* setwfill (kod) , ( 122 ' z '). : zzzzzzz157. setwfill (0).*/

cout << oct << a << endl;

/* oct 8- . : 235 */

cout << hex << a << endl;

// hex 16- . : 9d

cout << dec << a << endl;

// dec 10-. : 157

cout << b << endl; // : 1.55555

cout << setprecision(3) << b << endl;

/* setprecision (n) n , . :

1.56 1.556 */

return 0;

}

 

, ios, .

setiosflags (ios:: flag);

resetiosflags (ios:: flag);

, | ( ) .

.

#include<iostream.h>

#include<iomanip.h>

#include<conio.h>

void main(void) {

int a = 157;

cout<<setiosflags(ios:: showbase)<<a<< <<oct<<a<<

<<hex<<a<< endl;

/* showbase , . : 157 0235 09d */

double a1 = 12.99, a2 = 15;

cout << setiosflags(ios:: showpoint | ios:: fixed)

/* showpoint , fixed */

<< setprecision(2) << setfill(*) << setiosflags(ios:: right)

// right ( left)

<< a1 << setw(10) << a1

<< a2 << setw(10) << a2 << endl;

// : a1 *****12.99 a2 *****15.00

double pi = 3.14159;

cout << Pi << setw(15) << setfill(_)

// _

<< setiosflags(ios:: showpos | ios:: scientific)

<< setprecision(5) << pi << endl;

/* showpos +, scientific . : Pi _ _ _ +3.14159e+00 */

}

 

, , .

 

16.3. - Visual C++

Visual C++ 6.0 ( ) . , , , - , . Visual C++ 6.0 :

#include <iostream.h>

int main()

{

cout << "Welcome to C++!" << endl;

cout << " C++!" << endl;

return 0;

}

:

Welcome to C++!

─ C++!

Press any key to continue

. MS DOS Windows.

- ASCII. , .. 0 127, 128 255 . , , (Alt), (Mai), (MIC), -8 (KOI), . ASCII.

, Visual C++, ANSI. ASCII, , Visual , MS DOS ASCII.

, , CharToOem, ANSI ASCII. , () ANSI, OemToChar. windows. h.

:

#include <iostream.h>

#include <windows.h>

char* Rus(const char* text);

char bufRus[255];

int main()

{

char s[] = "!", ss[100];

cout << Rus(" ") << Rus(s) <<endl;

cout << Rus(" :");

cin >> ss;

cout << Rus(" : ") << ss << endl;

return 0;

}

char* Rus (const char* text)

{

CharToOem(text, bufRus);

return bufRus;

}

 

:

!

: !

: !

, Visual C++ 6.0 Rus, CharToOem, . bufRus. : ( ) Rus ( ).

CharToOem, , , BOOL, . , : Rus << , .

new delete

++ new delete. :

1) type * p = new type (); sizeof (type), , ;

...

delete p; .

2) type * p = new type [ n ]; n , n * sizeof (type); ;

...

delete [] p; .

, delete , , .

delete [ ] , , . .

 

new delete.

, new , . NULL.

¼

double *x;

int i, n;

puts(" : ");

scanf(%d, &n);

x = new double [n];

if (x = = NULL) {

puts(" ! ");

return;

}

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

scanf(%lf, &x[i]);

¼ //

delete [ ]x; //

¼

, , , .

...

int **m, n1, n2, i, j;

puts(" (, ): ");

scanf(%d%d, &n1, &n2);

m = new int*[n1]; // (n1=3)

for (i=0; i<n1; i++) //

*(m+i) = new int[n2];

for (i=0; i<n1; i++)

for (j=0; j<n2; j++)

m[i] [j] = i+j; // *(*(m+i)+j) = i+j;

...

for (i=0; i<n1; i++) //

delete []m[i];

delete []m;

...

 

 





:


: 2018-10-14; !; : 873 |


:

:

- - , .
==> ...

1479 - | 1472 -


© 2015-2024 lektsii.org - -

: 0.113 .