.


:




:

































 

 

 

 


. 3 4




 

3 4 . .

. , .

, .

, , . , , .

, , . ++ , , . ++, . new, delete, , new.

 

, , . .

, , . , .


, , new. , , , , , .

new delete

, double. double . , new :

double* pvalue = NULL; // , null

pvalue = new double; // double

 

, , . "" , , . , , 0.

new , double, pvalue. , , .

*pvalue = 5555.0;

 

new . double, new pvalue, 999.0 :

// double

pvalue = new double(555.0);

 

, , , , delete:

delete pvalue; // , pvalue

. delete pvalue , , , . , (memory leak) - .


. char, , pString - char, :

pString = new char [20]; // 20

20 pString.

, delete. :

delete []pString; // , pstr

 

, , , - . , , , . - [ ].

, pString , - , , , . delete , , , 0, :

pString = 0; // null

 

 

, .

. , . :

 

int n;

..

cin>>n; //

int *mas=new int[n]; //

.

delete mas; //

mas n .

int *mas=new int[n];

: , . .


int n;

int* mas;

cin>>n; // n-

mas=new int[n]; //

delete mas;

, n , . , , .

// 24

 

//

#include <iostream.h>

void main ()

{

int i,n; //

float *a; // float

float s; //

cout<<"n=";

cin>>n; //

//

a=new float[n];

cout << "vvedite massiv A\n";

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

//cin>>a[i]; //

cin>>*(a+i);

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

//s+=a[i];

s+=*(a+i);

cout << "S= "<<s<<'\n'; //

//

delete [] a;

}

, - , , , , .

.


. , , , . a=new float[n];

n .

, , .

. . . , . , . - .

- , .

. .

 

new , .

, .

n k:

...

int n, k, i;

int**mas;

cin>>n; //n-

cin>>k; // k

mas = new int*[n]; // n

// k

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

mas[i] = new int[k];

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

delete mas[i];

delete [] mas;


new n . , . . , .

 

 

, .

, . , . .

, 0.


 

// 25

//

#include < iostream.h >

void main()

{

int **array;

int n, m;

int i, j, sum;

//

cout<<"Enter number of rows and number of columns\n";

cin>> n>> m; //

array = new int*[n]; //

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

{

array[i] = new int[m];

cout<<"Now enter all numbers\n";

for (j = 0; j < m; j++) //

cin>> array[i][j];

}

//

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

{

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

{

cout<<array[i][j]<<'\t';

}

cout<<endl;

}

cout<<endl;

//

sum = 0;

for (i = 0; (i < n) && (i < m); i++)

sum += array[i][i];

cout<<"Sum of diagonal:"<< sum <<"\n";

//

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

delete[] array[i];

delete[] array;

}

.

int **array;

, , array - .

, , . . . , , , , . , , , , . .

. , . .

, .

, , , , , .

 

 

 

// 26

// m n. , //

#include <iostream.h>

#include <stdlib.h>

#include <time.h>

#include <iomanip.h>

int main()

{

//

//

srand(time(NULL));

int m, n, i, j;

int **matr;

int *b;

//cout << "Enter number of rows and number of columns\n";

//cin >> m >> n;

n = rand() % 10 + 1; // -

m = rand() % 10 + 1;

matr = new int*[m]; //

cout << "m: " << m << ", n: " << n << '\n';

cout << "matrix:\n";

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

{

matr[i] = new int[n]; //

//

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

{

matr[i][j] = rand() % 100;

cout <<setw(5) << matr[i][j];

}

cout << endl;

}

cout << endl;

b = new int[m]; //

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

{

b[i] = matr[i][0];

for (j = 1; j < n; j++)

{

if (matr[i][j] > b[i])

{

b[i] = matr[i][j];

}

}

}

cout << "Maximums of rows:\n";

for (i = 0; i < m; i++) {

cout << b[i] << endl;

}

//

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

delete[] matr[i];

delete[] matr;

delete[] b;

return 0;

}

.


 

, , . , , , .

,

#include <stdlib.h>

rand() .

, , . , .

#include <time.h>

srand(time(NULL));

m = rand() % 10 + 1;

, , . , , .

, , 0 9. 1 10, , . , .

,

matr[i][j] = rand() % 100;

.

b = new int[m];

.

, .

, , , . .


 

 

 

  m×n -25 75. . . . . . . .  
  D m×m -10 15. . . . . .
  m×n 0 90. . , . . , 5, .  
  Q m×n -20 65. . . . . , k- .  
  Q m×m -30 65. . . . , . .
  m×n -20 90. . . . k- . . , . .  
  R n×n. -50 +50. . , . . . . , . .
  P n×n. -50 +80. . . . . . .
  Q m×n -20 80. . , , . . , . .
  Q m×n -60 65. . , , . . . .
  m×n 25 75. . 5. 5 0 . . .    
  n ×n -20 25. . . . .  
  n ×n -50 50. . , . . . .  
  V m ×n -90 65. . . . k . .  
  F m ×n -20 20. . . . . .  
  R n×n. -50 +50. . , . . . . , . .  

 


 

1) ? ?

2) . . ?

3) , , ?

4) .


6

 

: .

 

:

1) ++.

2) ++.

3) .

 





:


: 2016-11-18; !; : 501 |


:

:

,
==> ...

1542 - | 1518 -


© 2015-2024 lektsii.org - -

: 0.127 .