0% found this document useful (0 votes)
31 views11 pages

Lab 1 Updated

The document introduces Code::Blocks, a free C++ IDE. It describes the main components of Code::Blocks including the menu bar, main toolbar, debugger toolbar, compiler toolbar, manager window and logs window. It then provides steps to create a new C++ project in Code::Blocks and write a simple "Hello World" program. It also demonstrates various C++ code examples including comments, multiple statements, endl usage and formatting output. The document concludes with an introduction to common programming errors.

Uploaded by

MUHAMMAD RIZWAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views11 pages

Lab 1 Updated

The document introduces Code::Blocks, a free C++ IDE. It describes the main components of Code::Blocks including the menu bar, main toolbar, debugger toolbar, compiler toolbar, manager window and logs window. It then provides steps to create a new C++ project in Code::Blocks and write a simple "Hello World" program. It also demonstrates various C++ code examples including comments, multiple statements, endl usage and formatting output. The document concludes with an introduction to common programming errors.

Uploaded by

MUHAMMAD RIZWAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

LAB # 01

Introduction to C++ Language

Objectives:
Introduction to Code::Blocks
Writing a new C++ Program
Programming Errors

Introduction to Code::Blocks
Code::Blocks is a free C++ IDE developed by The Code::Blocks Team. It is a free, open-source and
cross-platform IDE, which supports various free compilers.
1. Menu bar:
Few important links in menu bar are:

File: It contains options to create a new project, open an already existing project, save file,
save project, save workspace and save everything. Other options in File are to print, export
and quit the Code::Block
Edit: All the editing options required for editor are provided in Edit.
View: This menu link contains link for various perspectives and toolbars along with manager,
logs, script console, status bar, full screen.
Project: Options related to the project is provided in this link which includes adding files,
removing files and auto versioning of project.
Build: Options for building the project, compiling a single file, running, building and running
the project, rebuilding and cleaning the project/workspace is provided in build.
Debug: Various Debugging options are provided in this link.
Plugins: Various plugins can be executed using this link. The link to manage the plugins is
also provided here.
Settings: This contains link for various settings, setting related to Environment, Editor,
Compiler and debugger, Global Variables and Script to be executed can also be edited here.
Help: It contains information about Code::Block version, tips which can be toggled to be
displayed at start-up and information about various plugins.

2. Main Tool Bar:

New File: For creating a new project.


Open: For opening an already created project.
Save: To save the file open in active editor (active editor means the editor tab in focus).
Save all files: To save all the files for the current/selected project.
Undo: To undo the executed action.
Redo: To redo the undone action.
Cut: To cut the selected/highlighted part in editor.
Copy: To copy the selected/highlighted part in editor.
Paste: To paste the cut/copy message in editor.
Find: To find required text in the file in active editor.
Replace: To replace required text in the file in active editor by some alternate text.

3. Debugger tool bar:


Debugger tool bar is used to debug the current/selected project.

4. Compiler tool bar:


Compiler tool bar is used in building/compiling/running the current/selected project. The buttons
in Compiler toolbar are (from left to right):

Build: For building the current/selected project.


Run: For running the current/selected project.
Build and run: For building and running the current/selected project.
Rebuild: For rebuilding the current/selected project.
Abort: For aborting the build process for the current/selected project.

5. Manager:
Manager window provides the list of all the open projects and files for easy access to any required
file of any project.
A short-cut on Starting page of IDE for creating a new project and opening an already created
project is present. It also contains link for Code::Block forum where many useful resources can be
found along with other useful discussions.

6. Logs:
It is labelled as Logs & others. This window acts as log for various actions performed in IDE.
All logs related to various activities can be checked at appropriate windows.

Writing a new C++ Program

Click File New Project. A new window opens. Click Console application Click
Go.
When Go button is clicked, a new window opens. Select checkbox Skip this page next time so
that the page is not displayed again. Click Next.

Next window enables user to select the language to be used for project. Click C++ Next

Next windows enables user to provide title for the project and the folder where user wishes to
create the project in. After filling in the details click on Next.
Use a meaningful name, Camel case (if necessary).
Next window is used to select the compiler. By default GNU GCC Compiler is selected.

Click Finish.

Code 1: Hello World

Line 1: #include <iostream>


Lines beginning with a hash sign (#) are directives. They are special lines interpreted before the
compilation of the program itself begins. In this case, the directive #include <iostream>, instructs the
preprocessor to include a section of standard C++ code, known as header iostream, that allows to
perform standard input and output operations, such as writing the output to the screen.

Line 2: A blank line


Blank lines have no effect on a program. They simply improve readability of the code.

Line 3: using namespace std;


cout is part of the standard library, and all the elements in the standard C++ library are declared
within what is called a namespace: the namespace std.

Line 5: main ( )
This line initiates the declaration of a function. Main is a special function in all C++ programs; it is
called when the program is run. The execution of all C++ programs begins with the main function.

Lines 6 and 8: { }
The open brace { at line 6 indicates the beginning of main's function definition, and the closing brace
} at line 8, indicates its end. Everything between these braces is the function's body that defines what
happens when main is called. All functions use braces to indicate the beginning and end of their
definitions.

Line 7: cout << "Hello world ! ";


This line is a C++ statement. A statement is an expression that can actually produce some effect. A
sentence within quotes is the content inserted into the standard output. Notice that the statement ends
with a semicolon (;)

Code 2: Multiple C++ Statement

Code 3: Use of End of Line (endl)


The endl can be replace by \n

Code 4: Line Comment


Code 5: Block Comment

Programming Errors:

Syntax Errors
Logical Errors
Run time Errors
Lab Report:
1: Write down the following code in compiler and see the result.

2: Write a program that prints a box, an oval, an arrow and a diamond as follows: [Hint: setw( ) &
<iomanip >]
3: What does the following code print?

4: What does this program print?

You might also like