.


:




:

































 

 

 

 


.

 

, - ?

- , .

 

, . , , , , 4 , .. , , . , , , , , . .
, , , . , , , , . . , .

, , , .

 

, , .

:

class < >

{

public:

< , , >

private:

< , , >

protected:

< , , >

};

class. , , , , . : public, private, protected. .

public . , .

private , . , ( ) . .

protected , , .

 

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

, () (.. ) .

 

, , , . , , , .

:

  • ;
  • ( );
  • ().

 

 


.

 
()
bool   0 / 255
()
char   0 / 255
int   -2 147 483 648 / 2 147 483 647
float   -2 147 483 648.0 / 2 147 483 647.0
double   -9 223 372 036 854 775 808.0 / 9 223 372 036 854 775 807.0

 

bool

bool. true false. true - (.. 1), false - ( 0).

char

char - , . , [0;255]. char , ++ char. C++ char , 8 , 8 256 , . , char 256 . ASCII.

ASCII ( . American Standard Code for Information Interchange) .

 

.

:

short - , , ;

long - , , .

, , , int. short, long, int, () .

++ : float double. . float double , . float , double, . float long, double. , , , .

 

string

, () . ( ) .

, string:

#include <string>

 

.

, . , Edit-. , :

int x;

x = Edit1->Text;

Cannot convert 'UnicodeString' to 'int'. . , , .

< >To< >

:

int x;

x = StrToInt(Edit1->Text);

, , - , Edit-e. , .
.

C/C++ ( ). .

printf() . , , ...

, :

printf(, !);

:
, !

 

printf() . , , . . % .

:

 

%
%d
%f xx.xxxx
%o
%s
%u
%x
%X
%% %
%p
%n

 

, x=10.3563 float 3- , :

printf(" x = %.3f",x);

:
x = 10.356

 

:

\f ,
\n ,
\"
\'
\0 ,
\N
\xN
\?

\n. .

 

 

scanf():

scanf() - . (). , , , .

 

:

%c
%d
%i
%e float ( )
%o
%s
%x
%p

 

 

:

 

/* 1 */

#include <stdio.h>

void main(void)
{
int age;

printf("\n ?:");
scanf("%d",&age);
printf(" %d .", age);
}


:

- , . . . ( C++).

 

. . .

 

. , , employee:

class employee

{
public:
employee(char *, char *, float);
void show_employee(void);
private:
char name[64];
char position[64];
float salary;
};

, manager, employee:

float annual_bonus;
char company_car[64];
int stock_options;

: -, manager, employee, manager employee. manager employee, .

class, manager, employee, :

//-----> class manager: public employee { <-------//

//
};

public, employee, , (public) employee manager. , manager.

class manager: public employee

{
public:
manager(char *, char *, char *, float, float, int);
void show_manager(void);
private:
float annual_bonus;
char company_car[64];
int stock_options;
};

 

:

.

, .

( ), .

class, , , class dalmatian: dog.

 

́ ́ , - , ( -). ( ) (. single inheritance), .

, , computer_screen:

class computer_screen

{
public:
computer_screen(char *, long, int, int);
void show_screen(void);
private:
char type[32];
long colors;
int x_resolution;
int y_resolution;
};

, mother_board:

class mother_board

{
public:
mother_board(int, int, int);
void show_mother_board(void);
private:
int processor;
int speed;
int RAM;
};

, computer, :

class computer: public computer_screen, public mother_board

{
public:
computer(char *, int, float, char *, long, int, int, int, int, int);
void show_computer(void);
private:
char name[64];
int hard_disk;
float floppy;
};

, , computer.

class computer: public computer_screen, public mother_board //>


C++

, , , .

, . , , . C++ , if.

:

: Label1 , Edit1 , Button1 .

if else. :

if ( 1 ) {

1; }

else {

2; }

:

int x = 10; // ,

int y = StrToInt(Edit1->Text);

// Edit1, StrToInt()

if (y>=x) {

Label1->Caption=" , 10";}

else {

Label1->Caption=" ";}

Label 1:

switch-case. :

switch (<>) {

case 1:

<> == 1

break;

case 2:

<> == 2

break;

...

default:

,

break;

}

:

int x = 10;

int y = StrToInt(Edit1->Text);

 

switch (y) {

case 1:

Label1->Caption=" 1";

break;

 

case 2:

Label1->Caption=" 2";

break;

............

 

case 10:

Label1->Caption=" 10";

break;

 

default:

Label1->Caption=" 10"; }

case break, , . .. case break , :

5

6

7

8

9

10

10

, .


for C++

. , - . , , .

++ :

  • for
  • while
  • do while

for .

, (. . true).

  // for:   for (/*1*/; /*2*/; /*3*/) { /* */; } 1 , 2 , 3 , .

, Memo1 . Memo1->Lines->Add( 1 10), 10 , 1 100, , . .

for (int i = 1; i = 100; i++) {

Memo1->Lines->Add(i);

}

1 100.

Int i = 1 .

i = 100 , .. i 100, .

i++ - , i .



<== | ==>
 |
:


: 2016-09-06; !; : 1715 |


:

:

, ; , .
==> ...

1783 - | 1547 -


© 2015-2024 lektsii.org - -

: 0.09 .