Examination_IT / Programming bases on With C++
.pdf41
, - ; = Geometry.h Statistics.h, @ =,
;@ = Geometry.cpp Statistics.cpp.
.d -
= =
t>FR.cpp, = test.h. . Z , -
= ( 1.7 … 1.9).
8 58 9 1.7. !6:; Ex01_06.cpp
#include "stdafx.h"
#include <iostream> // ^=; ab?Pc@@ system. // GQ^P=mJ>?@> ?Hw>dQ IHdQ=Q<QJ?QdQ aHK=H. #include "test.h"
void _tmain()
{
ReadIn();
Sort();
Print(); system("pause");
}
8 58 9 1.8. !6:; test.h
// GBQRQR@AD AQ=fIQ<HR>=fFP@E ab?Pc@K. void ReadIn();
void Sort(); void Print();
8 58 9 1.9. !6:; test.cpp
#include "stdafx.h"
#include <iostream>// ^=; P=HFFH cout. using namespace std;
// GQ=fIQ<HR>=fFP@> ab?Pc@@.
void ReadIn(){ cout << "read_in" << endl;} void Sort() { cout << "sort" << endl;}
42
void Print() { cout << "print" << endl;}
/ , ; cpp-=, = test.cpp,
#include "stdafx.h"
! , = test.cpp = Ex01_06.cpp
#include <iostream> using namespace std;
. = Ex01_06.cpp d , =
, ; =,
:
#include "test.h"
e t>FR.cpp test.h ,
@ , , -
= Ex01_06.cpp. F Z =
; , ;@ cp1251,
@ Z ; VSC++.
, @ . ?
Z Ex01_06 = Ex01_06.cpp. 3 VSC++
= t>FR.cpp test.h. t Z , @ d d
; Add|New Item… ?
New Item - Ex01_06. . ; Categories -
Visual C++ ; – Code. . ;
Templates d C++ File (.cpp), -
Name = d test
8]. ? = test.cpp - ; . ? = test.h, -
, d
Header File (.h). ? =, -
43
1.7 1.9. .
.
D ( -1.7 … 1.9)
=. 5 - d . ?
= = t>FR.cpp test.h - ; -
; -
.
1.2
3 @-
. . = =
Square.
D d 1.10, –
. 1.6.
8 58 9 1.10. !6:; Ex01_07.cpp
#include |
"stdafx.h" |
// AQRQPQ<DK <<Q^/<D<Q^. |
#include |
<iostream> |
using namespace std;
//////////////////////////////////////////////////////
//zb?Pc@; <QI<BH{H>R P<H^BHR J@F=H n double Square(double n)
{
double Nb = n*n; return Nb;
}
//////////////////////////////////////////////////////
//t=H<?H; ab?Pc@;
void _tmain()
{
setlocale(LC_CTYPE, "Russian_Russia.1251");
double Number = 2.5;
44
double Result;
Result = Square(Number);
cout << "|>Ib=fRHR 1 = " << Result << e ndl; cout << "|>Ib=fRHR 2 = " << Square(5.0) << endl;
system("pause");
}
D . 1.6. / Ex01_07
D d . !
= _tmain. ? Z = ;
double Number = 2.5; double Result;
: ; double,
Number
2.5 double. 5 ;
d = . B
Number
Z , ,
.
/ – Z Z ; -
d -.
F
= Sqare:
Result = Square(Number);
45
5 @
= , = Number,
; = @
; Result. t Z , = Sqare.
double Square(double n)
{
double Nb = n*n; return Nb;
}
? =,
. . @ Z ,
, = . 3 n
double. ? = Z
,
Number = n, Z
= Square. .
:
double Nb = n*n;
r Nb …
n. : ,
return Nb;
d = @ Nb
Result @ = _tmain. ?
@ ; =. .
double , = …
@ double.
:
double Square(double n)
46
? @ d ; = ;
;
cout << "|>Ib=fRHR = " << Result << endl; cout << "|>Ib=fRHR = " << Square(5.0) << endl;
? ,
; @… = Sqare. e Squa re , Z
@… :
double Square(double n){ return n*n; }
.
= . .
:
f = 5.0* Square(b) + Square(c)* Square(c)/4.0 + d;
B = Z :
+ + !"
- – = .
? – ;@ ,
=.
F , =
, . . Z
; ;
: 1.10 d ,
; = . F d = ;, @ ;@ ; @
;- @ ; :
double Area(double b, double h);
47
? = ,
… . !, -
; ;@ ;
=, = -
. ? -
@ = -
, .
? , @
= ;@ :
_#
{
_#
return $ %;
}
:
$_# ( _1, _2, …,
_3)
{
_#
return $ %;
}
s – Z @ ,
void = @ (
);$_# – ; =,
;@ =.
? =
, ; ;
=. ! , =
,
, , void. ? =
=
=, @ . ~ = @ ,
void, = d
48
return ;@ ,
d ; = ;. ?
= return . B,
@
@ = ,
=. ~ = @ void ( @), return =,
, , Z = return
. : = return
= …
d ;.
. . 1.2 =
=.
|
3 1.2 |
? = = |
|
|
|
e |
e |
@ |
@ |
void func1() |
void func2(void) |
{ |
{ |
// R>=Q ab?Pc@@ |
// R>=Q ab?Pc@@ |
} |
} |
e |
e |
@. . … |
int double @ |
d ; |
. . … |
|
d ; |
void func3() |
int func4(int a, double b) |
{ |
|
// R>=Q ab?Pc@@ |
{ |
return; |
int d=0, e=0, r=0, k=0; |
// R>=Q ab?Pc@@ |
// R>=Q ab?Pc@@ |
return; |
return d; |
} |
// R>=Q ab?Pc@@ |
|
return e + r*k; |
|
} |
|
49 |
|
|
|
/ . 1.2 |
|
|
|
e |
|
e |
int @ |
|
int @ |
double. |
|
. |
double func5(int a) |
|
bool func6(int a) |
{ |
|
{ |
double e=0; |
|
bool f = true; |
// R>=Q ab?Pc@@ |
|
// R>=Q ab?Pc@@ |
return e; |
|
return f; |
} |
|
} |
1.12. 5 0P ..0 <628 C++
+ C++ d . / Z (#include) , -
@… Z .
# #define
5 ; =, … -
=. ? -
#define 1.11.
8 58 9 1.11. !6:; Ex01_8.cpp
#include "stdafx.h" #include "iostream"
// ~@B>PR@<D AB>ABQc>FFQBH. #define TWO 2
#define PRINT std::cout << "Hello!\n" #define begin {
#define end }
50
#define FOUR TWO*TWO #define STR "Robert Huk"
// t=H<?H; ab?Pc@;. void _tmain() begin
PRINT;
std::cout << TWO << " " << 2*FOUR << std::endl; std::cout << STR << std::endl;
system("pause");
end
?
( . 1.7).
/
using namespace std;
;@ std. ? -
Z
d @ Z . 3, -
cout << STR << endl;
Z ;
std::cout << STR << std::endl;
r
std. !, @… -
– Z ,
@ .
3 d . ? -
#define
#define TWO 2
F # , ;
. ! ; define , -