Examination_IT / ComputerScience_LaboratoryWork_ForStudent
.pdf162
{
setlocale(LC_CTYPE, "Russian_Russia.1251");
char str[LIM_STR]; char *ptr;
size_t i; int count;
cout << "! % ! 9> ";
cin.getline(str, LIM_STR-1); // ! .
//J% % ! str
//I ! OEM ! ANSI. OemToAnsi(str, str);
//1. w ; I ! I % QI I L. for(count = 0, i=0; i<strlen(str); i++)
{
if(str[i]=='%') break; count++;
}
cout << &str[count] << endl; // J ! _ .
//2. w ; I ! % QI I L. ptr = str;
while (*ptr != '%' && *ptr != '\0') ptr++;
cout << ptr << endl; |
// J ! _ . |
system("pause"); |
|
} |
SymbolicalLine1 |
H |
|
. 13.1. |
|
H. 13.1. H SymbolicalLine1
D ,
Windows ( VSC++) -
: -
, – Windows – VSC++. D
163
OEM1, – ANSI2. D -
B A
char -
OEM, , VSC++, -
ANSI. Windows -
> OemToAnsi AnsiToOem -
OEM ANSI . D > OemToAnsi
void OemToAnsi( |
|
I Q OEM- |
const char *OemStr, // |
||
char *AnsiStr |
// ( - ). |
|
// |
I Q ANSI- . |
|
); |
// ( -%). |
|
|
|
-( 13.1) R -
AB :
cin.getline(str, LIM_STR-1); // ! .
//J% % ! str
//I ! OEM ! ANSI. OemToAnsi(str, str);
` > OemToAnsi -- - .
B (
, > ). 4
B R . =-
> OemToAnsi A
> windows.h.
. C while. G
C, , 0 ( '\0'). D C AB A : «
, ».
1OEM - Original Equipment Manufacturer.
2ANSI - , American National Standards
Institute
164
. C R
13.2, . 13.2
, 3, 0 13.2. #+5. SymbolicalLine2.cpp
#include "stdafx.h" |
|
#include <iostream> |
|
#include <locale.h> |
// ! AnsiToOem |
#include <windows.h> |
|
using namespace std; |
|
#define LIM_STR 255 |
|
void _tmain()
{
setlocale(LC_CTYPE, "Russian_Russia.1251"); // " ! .
char str[LIM_STR]; // ! . // _ % ;.
char buf[LIM_STR];
int LenStr; // ! . int start, end, i, j;
cout << "! : ";
cin.getline(str, LIM_STR-1); // ! .
//J% % ! str
//I ! OEM ! ANSI. OemToAnsi(str, str);
LenStr = strlen(str); // % ! ! ! L . // r% ! % 9 (start) % L .
for(start=0; start<LenStr && str[start]!='.'; start++); // r% ! % 9 (end) % ! L . for(end=LenStr; end>start && str[end] != '.'; end--);
// z % J buf % L ! % ! L . for(j=0, i=start; i<=end; i++)
buf[j++] = str[i];
buf[j] = '\0'; // I ; :e L 0.
cout << buf << endl;
system("pause");
}
165
H. 13.2. H SymbolicalLine2
H C -
> > ( [ StringCut). . , > StringCut ( -
13.3) str buf -
Source Destination.
, 3, 0 13.3. SymbolicalLine3.cpp
#include "stdafx.h" #include <iostream> #include <locale.h> #include <string.h> #include <windows.h>
using namespace std;
#define LIM_STR 255
/////////////////////////////////////////////////////////////////
//Source J! % ! 9! % L % ! L
//L. w I Q J! % e Destination. void StringCut(char *Source, char *Destination);
void _tmain()
{
setlocale(LC_CTYPE, |
"Russian_Russia.1251"); |
|||
char str[LIM_STR] = |
" |
.!.9I"; |
// ! . |
|
char |
buf[LIM_STR]; |
|
|
|
cout |
<< "! |
: "; |
|
cin.getline(str, LIM_STR-1); // ! .
//J% % ! str
//I ! OEM ! ANSI. OemToAnsi(str, str);
StringCut(str, buf);
cout << buf << endl;
system("pause");
166
}
/////////////////////////////////////////////////////////////////
//Source J! % ! 9! % L % ! L
//L. w I Q J! % e Destination. void StringCut(char *Source, char *Destination)
{
int LenStr;
int start, end, i, j;
LenStr = strlen(Source); |
// |
% ! ! ! L |
|
// |
. |
// r% ! % 9 (start) % L . for(start=0; start<LenStr && Source[start]!='.'; start++); // r% ! % 9 (end) % ! L . for(end=LenStr; end>start && Source[end] != '.'; end--);
// z % J buf % L ! % ! L . for(j=0, i=start; i<=end; i++)
Destination[j++] = Source[i]; Destination[j] = '\0'; // I ; :e L 0.
}
2, C.
e ,
. [
A > string.h. - C > ,
.
sprint_s(Buffer, SizeInBytes, Format, arg1, arg2, … , argN) – > A > A - > SizeInBytes;
strcpy_s(strDestination, SizeInBytes, strSource) –
strDestination strSource -
SizeInBytes;
strcat(strDestination, SizeInBytes, strSource) –
strDestination, C
SizeInBytes, strSource; , R > -
A, , ;
strcmp(str1, str2) stricmp(str1, str2) – >
A str1 str2 A
167
. f str1 == str2, B ;
str1 > str2 – B ,
, B . - >
.
strlen(str) – B str;
strchr(str, c) – B str B -
R . f -
, > B NULL;
strstr(str1, str2) – B str2
str1 B R str1, -
str2
strtod(str, EndPtr) –
, B; B
C ,
. D > -
EndPtr R ;
atoi(str) – A str int
B R ;
atof(str) – A str
float B R .
=, ,
> strcpy, strncpy, sprintf strcat. = R >, A , -
> >> _s, , strcpy_s, strncpy_s. 4 > A -
– > . 4 -
A C , -
>, -
AB A .
168
> R >,
B MSDN .
13.3. + ,+ 34 )+*+ ,5
- , ,
> C++, B A -
>-
. D >, R
13.2, C .
|
: |
|
|
% |
- |
|
; |
|
|
|
|
1 |
1 |
1. |
- [ B |
|
|
|
. |
|
|
2. |
- R |
|
|
|
|
2 |
1 |
1. |
- |
|
|
2. |
. |
|
|
- R , A |
|
|
|
|
, C . |
3 |
1 |
1. . B >. |
|
|
|
2. |
- n - |
|
|
|
|
4 |
1 |
1. |
- , AB A > A |
|
|
|
. - R > A . |
|
|
2. |
- > , |
|
|
|
. P R > A |
|
|
|
AB : Q < > |
|
|
|
< > |
5 |
2 |
1. |
- , , - |
|
|
|
AB A A « ». |
|
|
2. |
- - |
|
|
|
. - R R |
62 1. - «D» «RRR».
2.-
>.
|
|
|
169 |
|
|
|
|
|
: |
|
|
% |
- |
|
; |
|
|
|
|
7 |
3 |
1. |
- A |
|
|
|
A. |
|
|
2. |
- , - |
|
|
|
. |
8 |
3 |
1. |
- [ - |
|
|
|
> . |
|
|
2. |
- , B |
|
|
|
. 2, |
|
|
|
, a |
9 |
3 |
1. |
- , B > , |
|
|
|
C- |
|
|
|
. |
|
|
2. |
- >, |
|
|
|
, |
|
|
|
« » |
10 |
3 |
1. |
- - |
|
|
|
« » « ». |
|
|
2. |
- |
|
|
|
« » « » |
11 |
3 |
1. |
- , |
|
|
|
. |
|
|
2. |
- |
|
|
|
|
12 |
3 |
1. |
- , B A > - |
|
|
|
, C , – |
|
|
|
> . |
|
|
2. |
- [ AB - |
|
|
|
, |
13 |
4 |
1. |
- |
|
|
|
, |
|
|
|
. |
|
|
2. |
- , |
|
|
|
? H- |
|
|
|
|
144 1. - . -
-
.
2.- R «
»
|
|
|
170 |
|
|
|
|
|
: |
|
|
% |
- |
|
; |
|
|
|
|
15 |
4 |
1. |
- S1 S2 B |
|
|
|
. ;> S , |
|
|
|
C S1 - |
|
|
|
S2. |
|
|
2. |
- , - |
|
|
|
« » |
16 |
4 |
1. |
- . : |
|
|
|
A . . |
|
|
|
. |
|
|
2. |
- - |
|
|
|
« » «B». = C |
17 |
4 |
1. |
- , R - |
|
|
|
A , . |
|
|
2. |
- , |
|
|
|
|
18 |
4 |
1. |
- , B |
|
|
|
[. |
|
|
2. |
- R |
|
|
|
, B « », |
|
|
|
|
19 |
4 |
1. |
- R |
|
|
|
. |
|
|
2. |
- R A - |
|
|
|
AA >, AB |
20 |
4 |
1. |
- > |
|
|
|
. |
|
|
2. |
- , |
|
|
|
« ». H |
21 |
4 |
1. |
- . D - |
|
|
|
, , |
|
|
|
. |
|
|
2. |
- >- |
|
|
|
|
225 1. - R
.
2.- ,
. ;, -
, . D -
: (34.67+56)*ms + (23.2 - alpha)(3+5*b)/rad