Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Examination_IT / ComputerScience_LaboratoryWork_ForStudent

.pdf
Скачиваний:
13
Добавлен:
16.05.2015
Размер:
5.86 Mб
Скачать

221

, B n double.

8.! > double?

9.P C AB char

>.

10.P C , AB >

int.

11.P C , AB >

double.

12.! > double?

13.! > char?

14.D > B

?

15.! A > A, AB A

, ?

16.; A ^ -

C ?

222

18.

9 % LIB DLL

18. 18. 9 % LIB DLL

18.1. %-./ +E(34

G A -

(LIB) (DLL) -

, B >.

18.2. -( -3,D- ,- 6-*- ,

P n3, - A , . 4 « » -

R – , >, . -

B B ->. - >,

A .

= -

, R

> A -

.

- -

LIB DLL, B >, - B AB B. P

R B -

> ( ). =

.

223

-B (.(0, 1 (;-*: (5 *- (>1(),;,,. (0 +>>, (6+ ,-+ : (6 - 9+5.(6

D Tria2

B >:

1)> Tria2.cpp, B A _tmain;

2)> Triangle.cpp, B >-

, B AB -

B.;

3)> Triangle.h >, B

> Gip Area.

4 > 18.1 – 18.3.

, 3, 0 18.1. #+5. Triangle.h

#ifndef __TRIANGLE_H__ #define __TRIANGLE_H__

double Gip(double a, double b); double Area(double a, double b);

#endif

, 3, 0 18.2. #+5. Triangle.cpp

#include "stdafx.h" #include <cmath>

//I e % I % Q Q. double Gip(double a, double b)

{

return sqrt(a*a + b*b);

}

//I e % e !Q % Q Q. double Area(double a, double b)

{

return a*b/2.0;

}

224

, 3, 0 18.3. #+5. Tria2.cpp

#include "stdafx.h" #include "Triangle.h"

// š !, 9 Q ! ! K L Gip Area void _tmain()

{

double a = 2.0, b = 3.0;

cout << Gip(a, b) << endl; cout << Area(a, b) << endl; system("pause");

}

= A A, -

C . . , -

, A .

3+3,D- + E,E.,(3- +

# "

D -(LIB), Tria.lib, > Triangle.h ( 18.1) Triangle.cpp ( 18.2). R

Tria. - Welcome to the Win32 Application Wizard Finish

Next. - C Application Settings

A Static Library Finish. - Tria

> Triangle.h ( 18.2) Triangle.cpp ( 18.3). - A R > . R B C -

A Add|Existing Item…

> Tria.cpp. D (! A

Build). - Debug

Tria.lib.

225

9 & 7 " "

- > Gip Area, - B Tria.lib, -

, Tria3. - ,

> Tria.lib Triangle.h, > Tria3.cpp , -

18.4.

, 3, 0 18.4. #+5. Tria3.cpp

#include "stdafx.h" #include "triangle.h"

// ! : L Tria.lib. #pragma comment(lib,"Tria.lib")

void _tmain()

{

std::cout << Gip(2., 3.) << std::endl; std::cout << Area(2., 3.) << std::endl;

}

D ( 18.4)

( 18.3) , AB A -

,

#pragma comment(lib,"Tria.lib")

A

A . 4 C -

. H R . ` . .C .

226

$, +>,D- + E,E.,(3- +

- B C -

DLL (Dynamic Link Library).

# "

; , , -

, > Triangle.h ( 18.1) Triangle.cpp ( 18.2). R Triangl. - Welcome to the Win32 Application Wizard Next. - C Application Settings A dll B Finish. -

LIB DLL

> stdafx.cpp B cpp-> dllmain.cpp, AB

dll- . 4 > .

C Triangl

> Triangle.h ( 18.1) Triangle.cpp ( 18.2) - A . R B C

A

Add|Existing Item… Q Triangl.cpp . = R > , 18.5 18.6.

, 3, 0 18.5. #+5. Triangle.h

#ifndef __TRIANGLE_H__ #define __TRIANGLE_H__

//extern "C" _declspec(dllexport) - _ I, K

//! _% Q -K L % J.

extern "C" __declspec(dllexport) double Gip(double a, double b); extern "C" __declspec(dllexport) double Area(double a, double b);

#endif

227

, 3, 0 18.6. #+5. Triangle.cpp

#include "stdafx.h" #include <cmath>

// J % e !Q.

extern "C" __declspec(dllexport) double Area(double a, double b)

{

return a*b/2.0;

}

// J % I .

extern "C" __declspec(dllexport) double Gip(double a, double b)

{

return ::sqrt(a*a + b*b);

}

D (! A Build). -

Debug Triangl.dll -

Triangl.lib. ` R -

!

9 & 7 " "

; Tria4. ;

> Triangl.lib Triangl.dll. Q Triangle.h

. - > Tria4.cpp , -

18.7.

, 3, 0 18.7. #+5. Tria4.cpp

#include "stdafx.h"

#include <windows.h> // ( % K L Windows. #include <iostream>

#include <locale>

// I! % I Q K functionDll. typedef double(*functionDll)( double, double);

using namespace std;

// ! : L Triangl.lib. #pragma comment(lib,"Triangl.lib")

void _tmain()

228

{

setlocale(LC_CTYPE,

"Russian_Russia.1251");

double a = 2.0, b =

3.0;

 

double g, s;

"r; I I DLL";

char *cpErrorDLL =

char *cpErrorFunc =

"r; I I ~ ";

HINSTANCE hDllInstance;

// _! DLL.

functionDll fpFunction;

// I Q K :.

// ( J % e ! I 9 DLL % Q. hDllInstance = LoadLibrary(_T("Triangl.dll")); if(hDllInstance) // I I dll % ;.

{

// I Q K : Area. fpFunction =

(functionDll)GetProcAddress(hDllInstance,"Area");

if(fpFunction) // I I K % ;.

{

s = fpFunction(a, b);

// JIJ K : Area.

FreeLibrary(hDllInstance); // 9! % Q.

}

 

else

 

cout << cpErrorFunc << endl;

}

 

else

 

cout << cpErrorDLL << endl;

 

// k

I K Gip , ! , % e.

cout

<<

g

<< endl;

cout

<<

s

<< endl;

}

P , A -

DLL R . ; R A -

A A , A R

DLL.

18.3. + ,+ 34 )+*+ ,5

+*+ ,-. ; A A ,

>, B AB B ^

> .

229

%

 

& '

 

 

 

 

 

 

1

1.

D B

 

 

.

 

 

 

 

 

 

 

2.

.^ .

2

1.

D B

 

 

¼

 

½

.

 

 

.

 

 

 

 

2. .^ -

3

1. .^ -

 

 

B [ .

 

 

 

2. .^ R B

 

 

 

 

 

 

 

 

 

4

1.

D B .

 

2. .^ R

 

 

>

 

 

 

 

 

 

5

1.

D B

 

 

.

 

 

 

 

 

 

 

2. .^ ,

 

 

B .

 

 

 

 

 

 

6

1.

D B

 

 

 

 

 

 

 

 

 

 

2. .^ R B -

 

 

.

 

 

 

 

 

 

7

1.

D B , AB -

 

 

.

 

 

 

 

 

 

 

2.

.^ .

 

 

8

1.

D B C.

 

2.

.^ C .

 

 

 

9

1.

D B ,

 

 

.

 

 

 

 

 

 

 

2.

.^ >,

 

 

.

 

 

 

 

 

 

18.4. ( *( 641(. - , +E(34

1. . , n3, -

>,

cpp->. >

230

h->, . . - C >.

2.= VSC++, . D A C cpp- h->.

3.; A .

4.= VSC++, . D A A A -

. ` > A _tmain -

.

5.= VSC++, -. D A C cpp- h->.

6.; A .

7.A > A.

8.= VSC++, . D A A A

. ` > A _tmain

.

18.5.-E(6+ , (*- 2+ ,j (3D-3+

. :

1)> ;

2);

3);

4)R A A .

--

. - R ,

A.

Соседние файлы в папке Examination_IT