.


:




:

































 

 

 

 





˲

""

 

 

2007


̲Ͳ ²

ʲ ֲ
Ͳ IJͲ

 

Ͳ Dz

 

˲

""

_______________________

 

 

³ ..

 

 

.

 

2007


c ___________ /.: .. , .. , .. - i: , 2007. - ___ .

 

 

: ..

..

..

 

 

.. , . .


̲

.. 5

1 . . 6

2 ++. 17

3 .. 41

4 . 55

5 ++. 60

6 , , . 79

˲.. 105

 


p . .

++, VISUAL C ++.

. , , .

: , , , , (), .

: , , , ( ), - , .

, - , , .

 


.

 

 

, , , .

 

1.2

 

# 1- . , stdout .

#include

.

 

#include <_>

#include "_".

 

_ , . .

#define

#define . :

- :

#define __

( );

- , , :

#define ( _;

- , . #i fdef #i fndef. :

#define :

#define VERSION I

#define VASIA " "

#define MAX(,) ((x)>(y)? (x): (y))

, . , , y = MAX(suml,. sum2);

= ((suml)>(sum2)? (suml):(sum2));

, . , #deflne sqr(x) (*) sqr(y+l), (+1*+1).

#undef

 

. :

 

#if _1

// , _1

#elif _2

// , _1 ,

// _2

...

#else

// ,

#endif

 

#elif #else .

 

. .

#if 0

//

#endif

 

#if #elif . sizeof.

#if #elif defined. , .

. .

 

#if defined(DEBUGGING)

space = 1000;

#else

space = 10;

#endif

 

 

#ifdef #ifndef

#if defined #if!defined .

 

. sample.h.

 

#ifndef __SAMPLE_H__

#define __SAMPLE_H__

//

#endif

 

 

sample.h , .

 

. Visual C++

#pragma once.

#error

#error .

 

#error __

. .

 

#if!defined(__cplusplus)

#error ++

#endif

 

, . , .

#line

#line .

#line _ ["_"]

#pragma

#pragma . Visual C++.

#pragma hdrstop ;

#pragma once ;

#pragma warning .

 

 

. -. . .

 

1.4

 

 

- .

 

1.6

 

1

, , :

1) ;

2) , .

.

2

, , :

1) ;

2) , .

.

3

, , :

1) ;

2) , .

, , (, 0, ).

4

, , :

1) ;

2) , .

, , 1. .

5

, , :

1) ;

2) , .

, , [ , ]. .

6

, , :

1) ;

2) , .

, , , .

7

, , :

1) ;

2) , .

, , , , .

8

, , :

1) ;

2) , .

, , 1, .

9

, , :

1) ;

2) , .

, , , .

10

, , :

1) ;

2) , , .

, , , , .

11

, , :

1) ;

2) , .

, , [ , ]. .

12

, , :

1) ;

2) , .

, , [ , ], .

13

, , :

1) , ;

2) , . .

14

, , :

1) , 0;

2) , .

.

15

, , :

1) , ;

2) , .

, , (, 0, ).

16

, , :

1) ;

2) , .

.

17

, , :

1) ;

2) , , .

, , 1, .

18

, , :

1) , ;

2) , .

, , 20%, .

19

, , :

1) ;

2) , .

.

20

, , :

1) ;

2) , .

, , , .

21

, , :

1) ;

2) ;

.

22

, , :

1) ;

2) ;

.

23

, , :

1) ;

2) , .

.

24

, , :

1) ;

2) , .

, , 5, .

25

, , :

1) ;

2) , .

.

26

, , :

1) ;

2) , .

.

27

, , :

1) ;

2) , .

, , (, 0, ).

28

, , :

1) ;

2) , .

.

29

, , :

1) ;

2) , .

.

30

, , :

1) , 0;

2) , .

.

 

 

, , . .

( main)

#include <iostream>

using namespace std;

#include "myHeader.h"

#define N 3

#define M 5

int main()

{

int mas[N][M]={9,3,6,23,21,

4,5,6,4,51,

4,6,24,23,24};

cout<<"Nachalnije dannie\n";

outmatr(mas,N,M);

#define cmp >

# if defined (cmp)

sortmas(mas[1],M);

#else

cout<<"error";

#endif

#define MES "sort \">\" 2-ja stroka"

cout<<endl;

outmas(mas[1],5);

#define cmp <

#define MES "sort \"<\" 3-ja stroka"

# if defined (cmp)

sortmas(mas[2],M);

#else

cout<<"error";

#endif

cout<<endl;

outmas(mas[2],5);

cout<<endl;

int sum;

SUM(mas[0],5,sum);

cout<<"Summa 1-oj stroki = "<<sum<<endl;

cout<<"Rezultat:"<<endl;

outmatr(mas,N,M);

cin.get();

return 0;

}

 

myHeader.h

//---------------------------------------------------------------------------

#ifndef _MY_HEADER_

#define _MY_HEADER_

#define MES "ne sort"

#define cmp ==

#define sortmas(mas,n) { for (int i=0;i<n;i++) \

for (int j=0;j<n-i-1;j++) \

if(mas[j] cmp mas[j+1]) \

{ mas[j]=mas[j]+mas[j+1]; \

mas[j+1]=mas[j]-mas[j+1]; \

mas[j]=mas[j]-mas[j+1];}; \

}

#define outmas(mas,n) { for (int i=0;i<n;i++) cout<<mas[i]<<"\t"; \

cout<<'\t'<<MES<<endl;}

#define outmatr(mas,n,m) { for (int i=0;i<n;cout<<endl,i++)\

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

cout<<mas[i][j]<<"\t"; \

}

//---------------------------------------------------------------------------

#define SUM(mas,n,Sum) { Sum =0; \

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

Sum+=mas[j]; \

}

 

#endif

 


2 ++

 

 

2.2

 

, , , /, . .

, .

, x_f1ags long ios. . 10.1.

10.1.

       
skipws 0x0001 +
left 0x0002  
right 0x0004 +
internal 0x0008   , . x_fill
dec 0x0010 +
oct 0x0020  
hex 0x0040  
showbase 0x0080   ( 0 )
showpoint 0x0100  
uppercase 0x0200  
showpos 0x0400  
scientific 0x0800  
fixed 0x1000   ( precision, . )
unitbuf 0x2000  
stdio 0x4000   stdout stderr

 

(left, right internal), (dec, oct hex), (scientific fixed) , .

 

ios flags, setf unsetf:

long ios::f lags(); ;
long ios::flags (long); ;
long ios::setf (long, long); , , ;
long ios::setf(long); , ;
long ios::unsetf(long); , .

.

, :

cout.setf(ios:: right);

, :

cout.unsetf(ios::right);

cout.setf(ios::left);

 

, ios:

int x_width ;
int x_precision ;
int x_fill .

width, precision fill:

int ios::width() ;
int ios::width (int) ;
   
int ios::precision() ;
int ios::precision (int) , ;
char fill() ;
char fill (char) , .

, . setf ios:

adjustfield (left | right | internal)

basefield (dec | oct | hex)

floatfield (scientific | fixed)

:

, .

#include <iostream>

using namespace std;

const int n=2;

//

//

struct Tstudent

{

char FIO[20];

float bal;

}StudetnPotok[n]={"Petrov",3.5,"Sidorov",5.0/3};

int main (int argc, char * const argv[])

{

//

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

{

//

cout.unsetf(ios::right);//

//(

// )

cout.setf(ios::left);//

cout.fill('.');// -

cout.setf(ios::fixed);//

//

//

// cout.setf(ios::scientific);//

//

// cout.unsetf(ios::fixed);//

// (

//)

cout.precision(3);// (

// )

cout.width(15); // 20 .

//

cout <<StudetnPotok[i].FIO;//

cout.setf(ios::right);//

cout.width(10);//

cout.fill('_');//

cout<<StudetnPotok[i].bal;

cout<<'\n';

}

cin.get();

return 1;

}

// :

Petrov........._____3.500

Sidorov........_____1.667

 

, . , , . , .

, .

dec ;
oct ;
hex ;
ws ;
endl ;
ends ;
flush .

.

:

cout << 13<< hex<< ' '<< 13 << oct<< ' '<< 13 << endl;

, :

13 d 15





:


: 2017-02-25; !; : 381 |


:

:

, ,
==> ...

739 - | 732 -


© 2015-2024 lektsii.org - -

: 0.222 .