SlideShare una empresa de Scribd logo
1 de 17
C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 1
About CodeBlocks
Code::Blocks is a free C++ IDE built to meet the most +demanding needs of its users. It is designed to
be very extensible and fully configurable.
Features
Highlights:
• Open Source! GPLv3, no hidden costs.
• Cross-platform. Runs on Linux, Mac, Windows (uses wxWidgets).
• Written in C++. No interpreted languages or proprietary libs needed.
• Extensible through plugins
Compiler:
• Multiple compiler support:
o GCC (MingW / GNU GCC)
o MSVC++
o Digital Mars
o Borland C++ 5.5
o Open Watcom
o ...and more
• Very fast custom build system (no makefiles needed)
• Support for parallel builds (utilizing your CPU's extra cores)
Multi-target projects
• Workspaces to combine multiple projects
• Inter-project dependencies inside workspace
• Imports MSVC projects and workspaces (NOTE: assembly code not supported yet)
• Imports Dev-C++ projects
C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 2
Introduction
Through the aid of a compiler, a program written in a computer language, such as C++, is turned into
machine code, which is executed on the computer.
The purpose of this manual is to help the student develop the skills to organize program coding and
develop sound techniques for finding and isolating errors.
Here you will learn how to trace the code step by step, so that it becomes clear where the problem is
and why your program does not execute properly. This is called debugging the program. Hand tracing is
useful in helping beginners understand where the bugs are and correct the program appropriately.
Automatic tools have also been developed to help you trace programs that you have written and will be an
important tool as your programs become more complex. This type of tool is called a debugger.
A debugger lets you pause a program, while it is in the middle of running, and watch what is going on.
Some debuggers work as command-line line debuggers, but newer debuggers have a nice graphical user
interface, which is useful in helping you watch variables that you have defined as the program executes.
The graphically- based debugger environment is part of what is called the Integrated Development
Environment (IDE).
A debugger cannot solve your problems for you. It is merely a tool to assist you when programming.
You should first attempt to read over your code and using paper and pencil analyze the code to get an
understanding of what is going on. Once you have gotten an idea of where in your code you have an error,
you can then set the debugger to watch certain variables in your program. Watching your code will show
you step by step how your program is being executed.
The debugger that you will use is part of an Open Source free IDE called Code::Blocks, which we
have found easy to use and is described in these notes. Code::Blocks has a C++ editor and compiler. It
will allow you to create and test your programs from one easy to use application. We hope these notes will
assist you in making programming more enjoyable and help you develop better programming skills.
You may find additional information regarding Code::Blocks at: http://www.codeblocks.org/
A complete manual for Code::Blocks is available here: http://www.codeblocks.org/user-manual
C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 3
Installation of Code Blocks
Step 1: Get the Software
In order to install the Code::Blocks IDE as well as the compiler, pick the one from the accompanying
CDROM as per the operating system you are using. You will get the installer application in the folder of
appropriate OS on the CDROM.
Open the folder and proceed with the instructions. In this section, we are covering the installation of
Windows based Code Blocks software.
If you are using Mac OS X or Linux, please see Appendix I for installation instructions.
Step 2: Install the Software
Next, open (click on) CodeBlocks install file and the CodeBlocks Setup will begin installing as
follows:
Click Next.
C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 4
Select I Agree
.
Take the default settings by pressing Next
C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 5
Take the default folder to install CodeBlocks to and then select Install.
C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 6
Using Code::Blocks
This section explains how to create a console project, which is suitable for basic C++ programs that
use the console (keyboard input and text output) for a user interface. The example screenshots in this
section are from a Windows installation. Macintosh users may see slightly different screens, but the
commands should be identical.
For each new program, you’ll need to create a project. A project will contain your source code,
generated executables and various configuration files within a single folder.
1. From the Start Here screen, click on Create a new project. You can also start from the main
menu using the command : File New Project .
2. Select "Console application" and press "Go".
C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 7
3. Select "C++" as the language you want to use and press "Next".
C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 8
4. The next screen asks you to name your project and select a location for your project. Be sure you place the
project in an easy to find location
and give it a meaningful name, so
that you can find it again later.
For this example, the project
has been created in the directory
C:codeblocks-tutorial, with name
first-project.
5. The next screen sets up the compiler and configuration for the project. Select the GNU GCC Compiler and
be sure that both the Debug and Release check boxes are selected. Press Finish to create your project.
C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 9
6. This will create a new folder for the project within the location folder you selected. You can verify the
location of the project by navigating to the appropriate directory. For example:
When the project is initially created, it will contain two files. The .cbp file is the Code::Blocks project file, which
can be used to reopen the project later. The .cpp file is the C++ program file that you will edit to create your
program.
7. Expand the tree in the Projects tab to the left of the Code::Blocks window and double click on main.cpp
to load the program file into the editor.
C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 10
8. Edit the code to create your program. As you are working periodically save your changes (main
menu:: File Save all files . You can also save all files with the short cut CTRL-SHIFT-s , or save a single
file with the short cut CTRL-s .
9. Build the project to compile your program into an executable. Use the Build menu and select
Build (or press CTRL-F9 ).
C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 11
10. Check for error messages in the lower window. If there are errors, return to step 8 and correct
them. If there are no errors, proceed to step 11.
11. Run your program. main menu :: Build Run (or press CTRL-F10 ).
12. If the program runs as expected, you’re finished. If it does not run as expected, return to step 8
and correct your program.
C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 12
Capturing Program Execution
This section is specific to Windows installations.
Most assignments will require you to capture a snapshot of the program’s console. Do this at the end
of program execution, before closing the console.
1. The console will remain open until you press some key to close it. It should look similar to this:
2. Right-click the mouse anywhere in the black console area. To capture the entire output of the
program, choose Select All . To capture only part of the output, choose Mark, then drag your
mouse over the area you want to copy. In either case, the selected area will turn white.
C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 13
3. Press the Enter key to copy of the selected text to the Windows copy/paste buffer.
4. Return to the edit window for your program. Add a comment at the bottom of your program and
paste the text (CTRL-v) into that comment. Build and run the program to verify that the comment is
correct and then save the file.
Saving and Restoring Projects
If you are working on a machine other than your own, you’ll need to take a copy of your project(s)
with you. To do this, simply locate the folder containing your project and copy it to a removable disk, or
to your network storage space. You can also archive the project folder as a zip file and email it to
yourself.
To save space, you may want to remove unnecessary contents before copying or archiving your file.
The bin and obj folders inside your project folder can both be safely deleted, since the contents of these
folders will be recreated the next time you build your project.
The most important files are your source code (any .cpp or .h files that you have written). If you keep
these files, it is possible to recreate your project by adding them to a new Code::Blocks project later.
C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 14
If you need to return to work on a previous project, start Code::Blocks and load the old project. From
the main menu, select File Open , then navigate to your project folder and locate the .cbp file. Select
the .cbp file and press Open and you’ll be returned to the editing environment for your project. Return
to step 8 in the section Using Code::Blocks and continue working.
Short Alternative
To quickly type and run a simple C++ program, you do the following:
1. Click File New Empty File or press Ctrl+Shift+N
2. Type your code in the blank window that opens.
3. Click File Save File or press Ctrl+S.
4. Type the full name of your program file in double quotes (along with extension .cpp) e.g. to
save a file with name First, save it as “First.cpp”
5. Now compile and run your program by clicking Build Build and Run or by pressing F9.
C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 15
Appendix A
Installation of Code::Blocks for Mac OS X and Linux
If you are using the Mac OS, you will need to do the following:
Pre-Install steps:
Here is a step by step instruction file for setting up X11 and XcodeTools for the Mac.
1. Make sure that X11 is installed in your system (check in your Application menu). If not, you'll need
to install it from your Mac OS disc.
Insert the disc and find the optional packages installer, open it, check the X11 box, and install from that.
If you are using 10.1 through 10.3, you can download X11 from Apple.
2. Install Developer Tools: You may be able to skip this step, if you are using Mac OS X 10.4
Tiger and have installed the Developer tools.
As a test, open up xterm. You cannot use terminal with Code Blocks. Xterm is part of X11 and that is
why you'll need to have X11 installed.
Run the command gcc. If you get an error that there are no input files, that means gcc exists and you are
good to go. If you get an error saying the command is not found, you need to install the Developer Tools.
If you need to install the Developer tools, you can download them from Apple, or you can install them
from your Mac OS disc. Locate the Xcode installer on the installation discs and double click to install.
Check your discs for Xcode or Developer Tools.
Run the installer and install everything other than the documentation:
• For Mac OS X 10.3, you need to install Xcode Tools version 1.2 or later
• For Mac OS X 10.4, you need to install Xcode Tools version 2.2 or later
• For Mac OS X 10.5, you need to install Xcode Tools version 3.1 or later
C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 16
Installation for Fedora 8 Linux:
Installing Code::Blocks
In a console window, become root and then execute the following command:
yum install codeblocks
Running Code::Blocks
In the Applications Pull Down Menu, go to Programming and click on: Code::Blocks IDE
or
Open a console window and then execute the following command:
codeblocks
Installation for Ubuntu Linux:
Installation Instructions From:
http://forums.codeblocks.org/index.php/topic,8208.msg61085.html#msg61085
1) Add the repositories to /etc/apt/sources.list:
Open the file with a graphical editor as root. Paste the following line in a terminal:
gksu gedit /etc/apt/sources.list
Paste this at the end:
# codeblocks
deb http://lgp203.free.fr/ubuntu/ gutsy universe
# wx widgets
deb http://apt.wxwidgets.org/ gutsy-wx main
Note: Depending on what version of Ubuntu you are using, in step 1 you
may need to replace gutsy with feisty.
C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 17
2) To make sure your package system trusts these sources. Add their keys.
Enter these two lines at the terminal:
wget -q http://lgp203.free.fr/public.key -O- | sudo apt-key add -
wget -q http://apt.wxwidgets.org/key.asc -O- | sudo apt-key add -
And update the packages by entering the following lines on the terminal:
sudo apt-get update
sudo apt-get upgrade
3) Install Code::Blocks
Enter the following line in the terminal:
sudo apt-get install libcodeblocks0 codeblocks libwxsmithlib0
codeblocks-contrib
You are able to step 3 whenever you want you to get the latest nightly build.
You should see Code::Blocks in the Programming Languages listing of your programs.

Más contenido relacionado

La actualidad más candente

Let us c yashwant kanetkar(1)
Let us c   yashwant kanetkar(1)Let us c   yashwant kanetkar(1)
Let us c yashwant kanetkar(1)
OMWOMA JACKSON
 
Access Protection
Access ProtectionAccess Protection
Access Protection
myrajendra
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
Gayathri Gaayu
 
Knapsack problem dynamicprogramming
Knapsack problem dynamicprogrammingKnapsack problem dynamicprogramming
Knapsack problem dynamicprogramming
rowntu
 

La actualidad más candente (20)

The pseudocode
The pseudocodeThe pseudocode
The pseudocode
 
Let us c yashwant kanetkar(1)
Let us c   yashwant kanetkar(1)Let us c   yashwant kanetkar(1)
Let us c yashwant kanetkar(1)
 
0 1 knapsack using branch and bound
0 1 knapsack using branch and bound0 1 knapsack using branch and bound
0 1 knapsack using branch and bound
 
Files in java
Files in javaFiles in java
Files in java
 
Access Protection
Access ProtectionAccess Protection
Access Protection
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 
03. oop concepts
03. oop concepts03. oop concepts
03. oop concepts
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
Java packages
Java packagesJava packages
Java packages
 
Packages in java
Packages in javaPackages in java
Packages in java
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
Lecture 1 introduction to vb.net
Lecture 1   introduction to vb.netLecture 1   introduction to vb.net
Lecture 1 introduction to vb.net
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
Knapsack problem dynamicprogramming
Knapsack problem dynamicprogrammingKnapsack problem dynamicprogramming
Knapsack problem dynamicprogramming
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
0/1 knapsack
0/1 knapsack0/1 knapsack
0/1 knapsack
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
 
AUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESAUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTES
 

Similar a How to work with code blocks

Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
meharikiros2
 

Similar a How to work with code blocks (20)

codeblocks-instructions.pdf
codeblocks-instructions.pdfcodeblocks-instructions.pdf
codeblocks-instructions.pdf
 
Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).doc
 
Prg 218 entire course
Prg 218 entire coursePrg 218 entire course
Prg 218 entire course
 
Programming in c_in_7_days
Programming in c_in_7_daysProgramming in c_in_7_days
Programming in c_in_7_days
 
C in7-days
C in7-daysC in7-days
C in7-days
 
C in7-days
C in7-daysC in7-days
C in7-days
 
C++Basics2022.pptx
C++Basics2022.pptxC++Basics2022.pptx
C++Basics2022.pptx
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptx
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
 
Session 1 - c++ intro
Session   1 - c++ introSession   1 - c++ intro
Session 1 - c++ intro
 
C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...
 
CIS 170 Focus Dreams/newtonhelp.com
CIS 170 Focus Dreams/newtonhelp.comCIS 170 Focus Dreams/newtonhelp.com
CIS 170 Focus Dreams/newtonhelp.com
 
CIS 170 Life of the Mind/newtonhelp.com   
CIS 170 Life of the Mind/newtonhelp.com   CIS 170 Life of the Mind/newtonhelp.com   
CIS 170 Life of the Mind/newtonhelp.com   
 
CIS 170 Imagine Your Future/newtonhelp.com   
CIS 170 Imagine Your Future/newtonhelp.com   CIS 170 Imagine Your Future/newtonhelp.com   
CIS 170 Imagine Your Future/newtonhelp.com   
 
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
 
Cis 170 Extraordinary Success/newtonhelp.com
Cis 170 Extraordinary Success/newtonhelp.com  Cis 170 Extraordinary Success/newtonhelp.com
Cis 170 Extraordinary Success/newtonhelp.com
 
ID E's features
ID E's featuresID E's features
ID E's features
 
Cis 170 Education Organization -- snaptutorial.com
Cis 170   Education Organization -- snaptutorial.comCis 170   Education Organization -- snaptutorial.com
Cis 170 Education Organization -- snaptutorial.com
 
Visual c++ demo
Visual c++ demoVisual c++ demo
Visual c++ demo
 
Cis 170 c Enhance teaching / snaptutorial.com
Cis 170 c  Enhance teaching / snaptutorial.comCis 170 c  Enhance teaching / snaptutorial.com
Cis 170 c Enhance teaching / snaptutorial.com
 

Más de Tech Bikram

Troubleshooting and maintenance
Troubleshooting and maintenanceTroubleshooting and maintenance
Troubleshooting and maintenance
Tech Bikram
 
Classification of computers
Classification of computersClassification of computers
Classification of computers
Tech Bikram
 

Más de Tech Bikram (11)

Internet of Things (IoT).pptx
Internet of Things (IoT).pptxInternet of Things (IoT).pptx
Internet of Things (IoT).pptx
 
Exploring the World of IoT.pptx
Exploring the World of IoT.pptxExploring the World of IoT.pptx
Exploring the World of IoT.pptx
 
Computer mouse
Computer mouseComputer mouse
Computer mouse
 
Troubleshooting and maintenance
Troubleshooting and maintenanceTroubleshooting and maintenance
Troubleshooting and maintenance
 
Classification of computers
Classification of computersClassification of computers
Classification of computers
 
Sql injection
Sql injectionSql injection
Sql injection
 
Firewall
FirewallFirewall
Firewall
 
Cdsl c nad-training_module
Cdsl c nad-training_moduleCdsl c nad-training_module
Cdsl c nad-training_module
 
Windows 7 installation step by step
Windows 7 installation step by stepWindows 7 installation step by step
Windows 7 installation step by step
 
Virus prevention
Virus preventionVirus prevention
Virus prevention
 
Channel price
Channel priceChannel price
Channel price
 

Último

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 

Último (20)

%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 

How to work with code blocks

  • 1. C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 1 About CodeBlocks Code::Blocks is a free C++ IDE built to meet the most +demanding needs of its users. It is designed to be very extensible and fully configurable. Features Highlights: • Open Source! GPLv3, no hidden costs. • Cross-platform. Runs on Linux, Mac, Windows (uses wxWidgets). • Written in C++. No interpreted languages or proprietary libs needed. • Extensible through plugins Compiler: • Multiple compiler support: o GCC (MingW / GNU GCC) o MSVC++ o Digital Mars o Borland C++ 5.5 o Open Watcom o ...and more • Very fast custom build system (no makefiles needed) • Support for parallel builds (utilizing your CPU's extra cores) Multi-target projects • Workspaces to combine multiple projects • Inter-project dependencies inside workspace • Imports MSVC projects and workspaces (NOTE: assembly code not supported yet) • Imports Dev-C++ projects
  • 2. C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 2 Introduction Through the aid of a compiler, a program written in a computer language, such as C++, is turned into machine code, which is executed on the computer. The purpose of this manual is to help the student develop the skills to organize program coding and develop sound techniques for finding and isolating errors. Here you will learn how to trace the code step by step, so that it becomes clear where the problem is and why your program does not execute properly. This is called debugging the program. Hand tracing is useful in helping beginners understand where the bugs are and correct the program appropriately. Automatic tools have also been developed to help you trace programs that you have written and will be an important tool as your programs become more complex. This type of tool is called a debugger. A debugger lets you pause a program, while it is in the middle of running, and watch what is going on. Some debuggers work as command-line line debuggers, but newer debuggers have a nice graphical user interface, which is useful in helping you watch variables that you have defined as the program executes. The graphically- based debugger environment is part of what is called the Integrated Development Environment (IDE). A debugger cannot solve your problems for you. It is merely a tool to assist you when programming. You should first attempt to read over your code and using paper and pencil analyze the code to get an understanding of what is going on. Once you have gotten an idea of where in your code you have an error, you can then set the debugger to watch certain variables in your program. Watching your code will show you step by step how your program is being executed. The debugger that you will use is part of an Open Source free IDE called Code::Blocks, which we have found easy to use and is described in these notes. Code::Blocks has a C++ editor and compiler. It will allow you to create and test your programs from one easy to use application. We hope these notes will assist you in making programming more enjoyable and help you develop better programming skills. You may find additional information regarding Code::Blocks at: http://www.codeblocks.org/ A complete manual for Code::Blocks is available here: http://www.codeblocks.org/user-manual
  • 3. C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 3 Installation of Code Blocks Step 1: Get the Software In order to install the Code::Blocks IDE as well as the compiler, pick the one from the accompanying CDROM as per the operating system you are using. You will get the installer application in the folder of appropriate OS on the CDROM. Open the folder and proceed with the instructions. In this section, we are covering the installation of Windows based Code Blocks software. If you are using Mac OS X or Linux, please see Appendix I for installation instructions. Step 2: Install the Software Next, open (click on) CodeBlocks install file and the CodeBlocks Setup will begin installing as follows: Click Next.
  • 4. C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 4 Select I Agree . Take the default settings by pressing Next
  • 5. C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 5 Take the default folder to install CodeBlocks to and then select Install.
  • 6. C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 6 Using Code::Blocks This section explains how to create a console project, which is suitable for basic C++ programs that use the console (keyboard input and text output) for a user interface. The example screenshots in this section are from a Windows installation. Macintosh users may see slightly different screens, but the commands should be identical. For each new program, you’ll need to create a project. A project will contain your source code, generated executables and various configuration files within a single folder. 1. From the Start Here screen, click on Create a new project. You can also start from the main menu using the command : File New Project . 2. Select "Console application" and press "Go".
  • 7. C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 7 3. Select "C++" as the language you want to use and press "Next".
  • 8. C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 8 4. The next screen asks you to name your project and select a location for your project. Be sure you place the project in an easy to find location and give it a meaningful name, so that you can find it again later. For this example, the project has been created in the directory C:codeblocks-tutorial, with name first-project. 5. The next screen sets up the compiler and configuration for the project. Select the GNU GCC Compiler and be sure that both the Debug and Release check boxes are selected. Press Finish to create your project.
  • 9. C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 9 6. This will create a new folder for the project within the location folder you selected. You can verify the location of the project by navigating to the appropriate directory. For example: When the project is initially created, it will contain two files. The .cbp file is the Code::Blocks project file, which can be used to reopen the project later. The .cpp file is the C++ program file that you will edit to create your program. 7. Expand the tree in the Projects tab to the left of the Code::Blocks window and double click on main.cpp to load the program file into the editor.
  • 10. C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 10 8. Edit the code to create your program. As you are working periodically save your changes (main menu:: File Save all files . You can also save all files with the short cut CTRL-SHIFT-s , or save a single file with the short cut CTRL-s . 9. Build the project to compile your program into an executable. Use the Build menu and select Build (or press CTRL-F9 ).
  • 11. C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 11 10. Check for error messages in the lower window. If there are errors, return to step 8 and correct them. If there are no errors, proceed to step 11. 11. Run your program. main menu :: Build Run (or press CTRL-F10 ). 12. If the program runs as expected, you’re finished. If it does not run as expected, return to step 8 and correct your program.
  • 12. C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 12 Capturing Program Execution This section is specific to Windows installations. Most assignments will require you to capture a snapshot of the program’s console. Do this at the end of program execution, before closing the console. 1. The console will remain open until you press some key to close it. It should look similar to this: 2. Right-click the mouse anywhere in the black console area. To capture the entire output of the program, choose Select All . To capture only part of the output, choose Mark, then drag your mouse over the area you want to copy. In either case, the selected area will turn white.
  • 13. C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 13 3. Press the Enter key to copy of the selected text to the Windows copy/paste buffer. 4. Return to the edit window for your program. Add a comment at the bottom of your program and paste the text (CTRL-v) into that comment. Build and run the program to verify that the comment is correct and then save the file. Saving and Restoring Projects If you are working on a machine other than your own, you’ll need to take a copy of your project(s) with you. To do this, simply locate the folder containing your project and copy it to a removable disk, or to your network storage space. You can also archive the project folder as a zip file and email it to yourself. To save space, you may want to remove unnecessary contents before copying or archiving your file. The bin and obj folders inside your project folder can both be safely deleted, since the contents of these folders will be recreated the next time you build your project. The most important files are your source code (any .cpp or .h files that you have written). If you keep these files, it is possible to recreate your project by adding them to a new Code::Blocks project later.
  • 14. C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 14 If you need to return to work on a previous project, start Code::Blocks and load the old project. From the main menu, select File Open , then navigate to your project folder and locate the .cbp file. Select the .cbp file and press Open and you’ll be returned to the editing environment for your project. Return to step 8 in the section Using Code::Blocks and continue working. Short Alternative To quickly type and run a simple C++ program, you do the following: 1. Click File New Empty File or press Ctrl+Shift+N 2. Type your code in the blank window that opens. 3. Click File Save File or press Ctrl+S. 4. Type the full name of your program file in double quotes (along with extension .cpp) e.g. to save a file with name First, save it as “First.cpp” 5. Now compile and run your program by clicking Build Build and Run or by pressing F9.
  • 15. C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 15 Appendix A Installation of Code::Blocks for Mac OS X and Linux If you are using the Mac OS, you will need to do the following: Pre-Install steps: Here is a step by step instruction file for setting up X11 and XcodeTools for the Mac. 1. Make sure that X11 is installed in your system (check in your Application menu). If not, you'll need to install it from your Mac OS disc. Insert the disc and find the optional packages installer, open it, check the X11 box, and install from that. If you are using 10.1 through 10.3, you can download X11 from Apple. 2. Install Developer Tools: You may be able to skip this step, if you are using Mac OS X 10.4 Tiger and have installed the Developer tools. As a test, open up xterm. You cannot use terminal with Code Blocks. Xterm is part of X11 and that is why you'll need to have X11 installed. Run the command gcc. If you get an error that there are no input files, that means gcc exists and you are good to go. If you get an error saying the command is not found, you need to install the Developer Tools. If you need to install the Developer tools, you can download them from Apple, or you can install them from your Mac OS disc. Locate the Xcode installer on the installation discs and double click to install. Check your discs for Xcode or Developer Tools. Run the installer and install everything other than the documentation: • For Mac OS X 10.3, you need to install Xcode Tools version 1.2 or later • For Mac OS X 10.4, you need to install Xcode Tools version 2.2 or later • For Mac OS X 10.5, you need to install Xcode Tools version 3.1 or later
  • 16. C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 16 Installation for Fedora 8 Linux: Installing Code::Blocks In a console window, become root and then execute the following command: yum install codeblocks Running Code::Blocks In the Applications Pull Down Menu, go to Programming and click on: Code::Blocks IDE or Open a console window and then execute the following command: codeblocks Installation for Ubuntu Linux: Installation Instructions From: http://forums.codeblocks.org/index.php/topic,8208.msg61085.html#msg61085 1) Add the repositories to /etc/apt/sources.list: Open the file with a graphical editor as root. Paste the following line in a terminal: gksu gedit /etc/apt/sources.list Paste this at the end: # codeblocks deb http://lgp203.free.fr/ubuntu/ gutsy universe # wx widgets deb http://apt.wxwidgets.org/ gutsy-wx main Note: Depending on what version of Ubuntu you are using, in step 1 you may need to replace gutsy with feisty.
  • 17. C o d e B l o c k s T u t o r i a l – C o m p u t e r S c i e n c e C + + b y S u m i t a A r o r a Page 17 2) To make sure your package system trusts these sources. Add their keys. Enter these two lines at the terminal: wget -q http://lgp203.free.fr/public.key -O- | sudo apt-key add - wget -q http://apt.wxwidgets.org/key.asc -O- | sudo apt-key add - And update the packages by entering the following lines on the terminal: sudo apt-get update sudo apt-get upgrade 3) Install Code::Blocks Enter the following line in the terminal: sudo apt-get install libcodeblocks0 codeblocks libwxsmithlib0 codeblocks-contrib You are able to step 3 whenever you want you to get the latest nightly build. You should see Code::Blocks in the Programming Languages listing of your programs.