1 / 44

INF160 IS Development Environments AUBG, COS dept

INF160 IS Development Environments AUBG, COS dept. Lecture 06 Title: Dev Env: Code::Blocks (Extract from Syllabus) Reference: www.codeblocks.org. Lecture Contents:. Code::Blocks – introduction Code::Blocks – functionality Code::Blocks – configuration. Code::Blocks – introduction.

abena
Télécharger la présentation

INF160 IS Development Environments AUBG, COS dept

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. INF160 IS Development Environments AUBG, COS dept Lecture 06 Title: Dev Env: Code::Blocks (Extract from Syllabus) Reference: www.codeblocks.org

  2. Lecture Contents: • Code::Blocks – introduction • Code::Blocks – functionality • Code::Blocks – configuration

  3. Code::Blocks – introduction • Code::Blocks: The open source, cross platform, free C, C++ and Fortran IDE. • Code::Blocks is a free C, C++ and Fortran IDE built to meet the most demanding needs of its users. • Built around a plugin framework, Code::Blocks can be extended with plugins. Any kind of functionality can be added by installing/coding a plugin. For instance, compiling and debugging functionality is already provided by plugins! • Code::Blocks 13.12 is here! (as of March 2014)

  4. Code::Blocks functionality • Code::Blocks includes: • Code Editor • Compiler • Debugger • Other SW tools

  5. Code::Blocks • How to Use?

  6. Code::Blockshow to use • To download and set up Dev-C++: • Already installed in COS lab120

  7. Code::Blocks how to use • To start Code::Blocks: • Start Menu >All Programs >CodeBlocks >CodeBlocks • Read and Close the “Tip of the Day” dialog box

  8. Code::Blocks how to use To create project .cbp file • File > New > Project… • Select project category/type • Name the project – select project title • Locate the project – select folder to locate project in

  9. Code::Blocks how to use • To add a new source file to an open project, in case your choice was Empty project • File > New > Empty File • Type the source text of C++ program. • Save the file • File > Save As

  10. Code::Blocks how to use • To add an existing file to an open project: • Project > Add Files… • Locate and then click the name of the file you want to add to the project, and then click the Open button

  11. Code::Blocks how to use To run a C++ program: • Type your source text • Save your project: How? (File > Save All) • Compile the source: How? (Build > Build) • Read, Analyze Compiler Progress messages • Run the program: How? (Build > Run)

  12. Code::Blocks how to use • To debug a C++ program: • If there are compiler errors, you should re-edit your source text in order to get successful compilation

  13. Code::Blocks how to use • To print program’s instructions: • File > Print… • Dialog box opens (check box line numbers?)

  14. Code::Blocks how to use • To close a project: • File > Close Project or • File > Close all Projects or • File > Close workspace

  15. Code::Blocks how to use • To open an existing project, .cbp file: • File > Open… • Open File dialog box gets opened • Navigate to the folder that contains the project .cbp file • Click Open button

  16. Code::Blocks • How to Configure?

  17. Code::Blocks how to configure • Note: The asterisk on the MyFirstSourceFile.cpp tab indicates that the changes made to the file have not been saved.

  18. Code::Blocks how to configure • NOTE: The font type and size used by default are Courier New and 14 point, respectively. If you want to change your editor window’s font type or size, click • Settings > Editor… > Editor settings tab, click Choose • When you are finished, click the OK button.

  19. Code::Blocks how to configure • NOTE: You can change the appearance (for example, the font, size, colors, and so on) of the Command Prompt window by right-clicking the window’s title bar and then clicking Properties. • When you are finished, click the Ok button to close the Properties window.

  20. Code::Blocks how to configure • NOTE:To display lines numbers in the editor window: • 1. Settings > Editor… > Editor settings tab, • 2. Section other options, select the Line Numbers check box.

  21. Code::Blocks how to configure • Settings > Environment… • Settings > Editor… • Settings > Compiler… • Settings > Debugger…

  22. Exercises/Tasks • Code::Blocks • Write a C++ program to: • display your personal data incl name, age, email address • Read two numeric data items • Compute and display result of their addition, subtraction, multiplication, division and modulus (in case of integer data).

  23. Exercises/Tasks • To demonstrate advantages of Code::Blocks • Back to MS Visual Studio • Write a C++ program to operate on arrays: #include <iostream> using namespace std; void main() { int m; // int m=10; cin>>m; const int m=10; int arr[m]; for(int i=0; i<m; i++) { arr[i]=i*10; cout << arr[i] << ‘ ‘; } }

  24. Exercises/Tasks • To demonstrate advantages of Code::Blocks • Back to Code::Blocks • Write a C++ program to operate on arrays: #include <iostream> using namespace std; void main() { int m; // int m=10; cin>>m; const int m=10; int arr[m]; for(int i=0; i<m; i++) { arr[i]=i*10; cout << arr[i] << ‘ ‘; } }

  25. Exercises/Tasks • To demonstrate command line arguments in Code::Blocks • Back to Code::Blocks • Write a C++ program: void main(int argc, char *argv[]) { for(int i=0; i<argc; i++) { cout << ‘\n’ << argv[i]; } } • Run the program without command-line arguments • Run the program with command-line arguments. How to specify? • Open cmd line window and run the program

  26. Exercises/Tasks • Write CompactProg project to calculate • Factorilal: facti(7), factr(7) • GCD: gcdi(40,15), gcdr(40,15) • Fibonacci: fibi(5), fibr(5) • All functions and main() in the same file

  27. Exercises/Tasks #include <cstdlib> #include <iostream> using namespace std; int factr(int); int facti(int); int gcdr(int, int); int fibr(int); int main(int argc, char *argv[]) { cout << factr(6) << “ “ << facti(6)<< “ “; cout << ‘\n’ << gcdr(40,15); cout ,, ‘\n’ << fibr(5); system("PAUSE"); return EXIT_SUCCESS; }

  28. Exercises/Tasks int factr(int n) { if (n==0 ) return 1; return n *factr(n-1); } int facti(int n) { if (n==0 ) return 1; int res=1; for (int i=1; i <=n; i++) res *=i; return res; }

  29. Exercises/Tasks int gcdr(int m, int n) { if (n==0 ) return m; return gcdr(n, m%n); } int fibr(int n) { if (n==0 || n==1 ) return 1; return fibr(n-1) + fibr(n-2); }

  30. Exercises/Tasks • To demonstrate: • How to create a static library • How to use a static library

  31. Exercises/Tasks • Write SBCreateStaticLib project to create a static library .a file • All functions definitions in one or more files • File > New > Project… Select Static Library >Go • Type project title • Type folder to create project in • Select Debug / Release option • Build > Build Static library .a file gets created

  32. File functions01.cpp // // factorial - recursion, iteration // int factr(int n) { if (n==0 ) return 1; return n *factr(n-1); } int facti(int n) { if (n==0 ) return 1; int res=1; for (int i=1; i <=n; i++) res *=i; return res; } // // greatest common divisor - recursion, iteration // int gcdr(int m, int n) { if (n==0 ) return m; return gcdr(n, m%n); } int fibr(int n) { if (n==0 || n==1 ) return 1; return fibr(n-1) + fibr(n-2); }

  33. Exercises/Tasks • Write SBUseStaticLib project to use static library .a file • Source file – only main() function • File > New > Project… Select Console Application >Go • Type project title • Type folder to create project in • Select Debug / Release option • Attention! It’s must to add the user library file. How?

  34. Exercises/Tasks • How? • 1. To set the location of the user library file • 2. to set the library name

  35. Exercises/Tasks • 1. To set the location of the user library file Settings >Compiler… > Search Directories tab select Linker Tab Add the folder where the library file is in

  36. Exercises/Tasks • 2. to set the library name Right click on the bolded project name Choose Build options Click the linker tab. Under the “Link libraries” window, press the “Add” button and add the library you wish your project to use. Press OK button

  37. Exercises/Tasks • To run the application • Build > Build • Build > Run • Or • Build > Build and Run

  38. File mainUseStaticLib01.cpp #include <cstdlib> #include <iostream> using namespace std; int facti(int), factr(int), fibr(int), gcdr(int, int); int main(int argc, char *argv[]) { cout << "\n Factoial = " << factr(6) << " " << facti(6); cout << "\n GCDivisor = " << gcdr(40,15); cout << "\n Fibonacci = " << fibr(4); system("PAUSE"); return EXIT_SUCCESS; }

  39. Exercises/Tasks • To demonstrate: • How to create a second static library • How to use a second static library

  40. File functions02.cpp #include <iostream> void MyName() { std::cout << "\n\n My name is Stoyan\n"; } void MyAddress() { std::cout << "\n\n My address is 1504 Sofia, BG\n"; }

  41. File mainUseStaticLib02.cpp #include <cstdlib> #include <iostream> using namespace std; void MyName(), MyAddress(); int main(int argc, char *argv[]) { MyName(); MyAddress(); system("PAUSE"); return EXIT_SUCCESS; }

  42. Exercises/Tasks • To demonstrate: • How to use two static libraries in the same project

  43. File mainUseTwoLibraries.cpp #include <cstdlib> #include <iostream> using namespace std; int facti(int), factr(int), fibr(int), gcdr(int, int); void MyName(), MyAddress(); int main(int argc, char *argv[]) { cout << "\n Factoial = " << factr(6) << " " << facti(6); cout << "\n GCDivisor = " << gcdr(40,15); cout << "\n Fibonacci = " << fibr(4); MyName(); MyAddress(); system("PAUSE"); return EXIT_SUCCESS; }

  44. Thank You For Your Attention!

More Related