Download presentation
Presentation is loading. Please wait.
Published byAugusta Pitts Modified over 9 years ago
1
? ? ? ?
2
Course name: Algorithms and programming techniques Course and seminars: Cristian Uscatu Course: Monday 15:00 - 16:20 Seminars: Monday 12:00 - 13:20 (1025) Monday 16:30 - 17:50 (1026) Tuesday 13:30 - 14:50 (1028) Friday 12:00 - 13:20 (1027) Consultations ▪Room 2301, Monday 13:30-14:50 ▪Appointment by email cristian.uscatu@ie.ase.rocristian.uscatu@ie.ase.ro ▪(use your institutional address, provided by the university) Algorithms and programming techniques
3
Prerequisites Basic computer knowledge and abilities Programing basics (first semester) Basic Visual Studio skills You must understand and know how to work with C/C++ ▪Write console applications ▪Arrays -1, 2, 3 etc. dimensions ▪Pointers-operations, memory (de)allocation ▪Subprograms-build, use, parameters Visual Studio ▪Create a simple Console Application (no precompiled headers) ▪Write C/C++ code ▪Compile/build the application ▪Debug the application Algorithms and programming techniques
4
You will study Function libraries Pointers to functions Iterativity and recursivity Divide et Impera method Search, sort, merge arrays Data validation External data structures: files - text, binary (sequential, relative, indexed) Graphs: representation, traversing, connectivity, paths, trees Greedy method Backtracking method Algorithms and programming techniques
5
Books, available at library Manual ▪C. Uscatu, C. Cocianu, B. Ghilic-Micu, M. Stoica, M. Mircea, Algoritmi i tehnici de programare, Editura ASE Bucureti 2014, 2015 Solved problems /examples book ▪C. Uscatu, C. Cocianu, M, Mircea, L. Pocatilu, Algoritmi i tehnici de programare. Aplicaii, Editura ASE 2015 Other books ▪I. Gh. Roşca, B. Ghilic-Micu, C. Cocianu, M. Stoica, C. Uscatu, M. Mircea, Programarea calculatoarelor. Algoritmi în programare, Editura ASE Bucureşti, 2007 ▪C. Uscatu, M. Popa, L. Pocatilu (Bătăgan), C. Silvestru, Programarea calculatoarelor. Aplicaii, Editura ASE Bucureti 2012 ▪Thomas H. Cormen, Charles E. Leiserson, Ronald R. Rivest, Introducere în algoritmi, Computer Libris Agora, 2000 ▪D. Knuth, Arta programării calculatoarelor, vol. 1-3, Ed. Teora, 1999, 2000, 2001 Algorithms and programming techniques
6
Evaluation ▪Seminar: 40% ▪Mandatory homework (prerequisite for practical test): 10% ▪Practical test: 30% ▪Examination: 50% ▪Ex officio: 10% Miscellaneous ▪Attendance, missed classes, individual study, rules, collaboration online.ase.ro – accessible from ASE intranet online.ase.ro Course description (fia disciplinei), presentations, other materials Algorithms and programming techniques
7
Libraries Library: collection of functions Purpose Code reuse for multiple applications Distribution to other users Types Source code, binary (object) code Static, dynamic
8
Libraries Work options Command line ▪cl.exe- compiler ▪lib.exe- library manger ▪link.exe- link editor In IDE (Visual Studio) ▪Same solution (with multiple projects) ▪Separate solutions
9
Static libraries Function code is inserted into the program File extension Windows:.lib Linux:.a Advantages Single executable file Only called functions are extracted from the library and inserted in the program Drawbacks Larger executable file Each executable includes a separate copy of the same functions
10
Static libraries Create static library Use the library Link editor Source code (.c,.cpp,.h) Object code (.obj) Object code library (.lib) Source code files (.c,.cpp,.h) Executable file (.exe) Compile Library manager Object code library (.lib) Object code (.obj) Compile
11
Static libraries Source files header (antet)matrice.h implementationmatrice.cpp testtest.cpp //alocare dinamica matrice // I - nr. linii, nr. coloane // E - adresa matricei double **aloca_matrice(int m, int n); //dezalocare matrice dinamica // I - adresa matricei, nr. linii // E - adresa matricei (NULL) double** dezalocare_matrice(double **a, int m); //produs matrice patrate de dimensiuni egale, prealocate // I - a, b, n // E - c void produs_mpn(double** a, double **b, int n, double** c); //copiaza matrice prealocate // I - a, m, n // E - b void copiaza(double** a, int m, int n, double** b); //citire matrice patrata cu alocare // I - // E - adresa matrice, dimensiune double** citire_matrice(int *m); //afisare matrice patrata // I - adresa matrice, dimensiune // E - void afisare_matrice(double** a, int m); #include #include "matrice.h" //citire matrice patrata cu alocare // I - // E - adresa matrice, dimensiune double** citire_matrice(int *m) { int i,j; double** a; printf_s("\n\nDimensiune: "); scanf_s("%d",m); a=new double*[*m]; for(i=0;i<*m;i++) a[i]=new double[*m]; for(i=0;i<*m;i++) for(j=0;j<*m;j++) { printf_s("a[%d,%d]= ",i,j); scanf_s("%lf",&a[i][j]); } return a; } //afisare matrice patrata // I - adresa matrice, dimensiune // E - void afisare_matrice(double** a, int m) { int i,j; //cout<<"\nMatricea este: \n"; for(i=0;i<m;i++) { for(j=0;j<m;j++) printf_s("%10.6lf ",a[i][j]); printf_s("\n"); } printf_s("\n"); } #include #include "matrice.h" void main() { double** a; int m,n; a=citire_matrice(&m); afisare_matrice(a,m); _getch(); }
12
Static libraries Command line Create a new folder and save the required files Run vcvars32.bat, found in Visual Studio’s folder bin ▪ C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin cl -c matrice.cpp ▪ matrice.obj lib matrice.obj /out:matrice.lib ▪ matrice.lib cl test.cpp matrice.lib ▪ test.exe
13
Static libraries In IDE – create binary library Create a new project, Win32 Console Application ▪ solution name: BSIDE, project name: matrice In Application settings dialog choose ▪Application type: Static library ▪Additional options: Empty project, no Precompiled headers Add source files to the project (header and implementation) Compile solution (Build) The library is created in folder BSIDE\Debug ▪Library name: matrice.lib
14
Static libraries In IDE – use binary library in the same solution Create a new project Win32 Console Application ▪ project name: Test, add to existing solution BSIDE In Application settings dialog choose: ▪Application type: Console Application ▪Additional options: Empty project, no Precompiled headers Add source file to the project (test file, with main function) Project > Properties > Common Properties > Framework and References > Add New Reference… > matrice Project > Properties > Configuration Properties > C/C++ > General > Additional Include Directories > path to matrice.h Project > Set As StartUp Project Compile (Build) Launch from IDE or separately ▪Test.exe is in BSIDE\Debug
15
Static libraries In IDE – use binary library in the separate solution Create a new project Win32 Console Application in a new solution ▪ solution name (also for project): TestS In Application settings choose ▪Application type: Console Application ▪Additional options: Empty project, no Precompiled headers Add source file to the project (test file with main function) Copy to the project folder the files matrice.h and matrice.lib Project > Properties > Configuration Properties > Linker > Input > Additional Dependencies > add matrice.lib Compile (Build) Launch
16
Dynamic libraries Function code is separated from the main program File extension Windows:.dll Linux:.so Advantages Smaller executable The library is shared by several applications Drawbacks Several files (main executable + dynamic libraries) Additional processing time Library must be on the search path or current folder
17
Dynamic libraries Create dynamic library Use library Launch application with dynamic library Link editor Source code (.c,.cpp,.h) Object file Object file (.obj) Import table (.lib) Dynamic library (.dll) Source code (.c,.cpp,.h) Executable file (.exe) Compile Link editor Object code library Object file (.obj) Compile Executable file (.exe) Dynamic library (.dll)
18
Dynamic libraries Building and using dynamic libraries is similar to static libraries Differences Function prototypes must include (only the header file.h) __declspec(dllexport) For each function: __declspec(dllexport) double** citire_matrice(int *m); At execution,.dll file must be available (same folder or known search path)
19
Dynamic libraries Command line Create a new folder for the project, include the 3 files Run vcvars32.bat, from bin folder of Visual Studio ▪ C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin cl matrice.cpp /LD ▪ matrice.dll, matrice.lib cl test.cpp matrice.lib ▪ test.exe For execution you need both: ▪ text.exe and matrice.dll
20
Dynamic libraries In IDE – create dynamic library Create new project Win32 Console Application ▪ Solution name: BDIDE, project name: matrice In Application settings dialog choose ▪Application type: DLL ▪Additional options: Empty project Add source files to the project (header and implementation) Build solution (Build) The dynamic library will be in the folder BDIDE\matrice\Debug ▪files: matrice.dll, matrice.lib
21
Dynamic libraries In IDE – use the dynamic library in the same solution Create a new project Win32 Console Application ▪ project name: Test, add to existing solution BDIDE In Application settings dialog choose ▪Application type: Console Application ▪Additional options: Empty project, no Precompiled headers Add source file to the project (text file with main function) Project > Properties > Common Properties > Framework and References > Add New Reference… > matrice Project > Properties > Configuration Properties > C/C++ > General > Additional Include Directories > path to matrice.h Project > Set As StartUp Project Build solution (Build) Run the application
22
Dynamic libraries In IDE – use the dynamic library in a separate solution Create a new project Win32 Console Application ▪ solution name (same for project): TestD Copy matrice.h and matrice.lib to project folder In Application settings dialog choose ▪Application type: Console Application ▪Additional options: Empty project, no Precompiled headers Add source file (test file with main function) Project > Properties > Configuration Properties > Linker > Input > Additional Dependencies > add matrice.lib Project > Properties > Configuration Properties > Debugging > Environment > add path to matrice.dll Build solution (Build) Run the application
23
Libraries H O M E W O R K ! Create and test a library with functions for processing arrays (1/2 dimensions) – must include reading and displaying the arrays. All arrays will be allocated dynamically. ▪Static library ▪Work in command line ▪Work in IDE (same solution) ▪Dynamic library ▪Work in command line ▪Work in IDE (separate solution)
24
Dynamic libraries H O M E W O R K ! Size comparison: When should we use libraries? When should we choose static / dynamic library? Static (.lib)Dynamic (.dll) L.C.IDEL.C.IDE matrice.h ???? matrice.lib ???? matrice.dll --?? test.exe ????
25
Spor la înv ă ţat!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.