0% found this document useful (0 votes)
17 views

Lesson 4 - C++ Basics

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Lesson 4 - C++ Basics

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Welcome!

C++
Basics
Let’s
pray…
Review…
• The Programming Process
 Defining the Problem
 Planning the Solution
 Coding the Program
 Testing the Program
 Documenting the
Program
Today, we’ll talk
about…
 C++ Basics
 What is C++?
 C++ Installation
 Your First C++
Program
 C++ Output
Look…
There are three
things wrong in this
picture. Find them.
What is C++?
C++ is a popular cross-platform language that can
be used to create from simple programs to
performance applications like high- operating
browsers, video-games, art applications, systems,
and so on.

Developed by Bjarne Stroustrup in 1979 at Bell Labs, C+


+ is
largely based on the C programming language.
Uses of C++
C++ programming language is capable of
developing diverse types of secure, efficient, and
reliable applications, like:
• Computer Games
• Web client and server applications
• Device drivers
• Embedded Systems, and more.
C++ Installation
To get started, you need to download an
Integrated Development Environment (IDE) and a C++
compiler. Today, will be using Dev-C++ by Bloodshed, a
free, portable, and simple C++ IDE with a built-in
compiler. For smartphone users, we will use Cxxdroid.
Once installed you may start working on your very first C+
+ program.
Using Dev-C++
To start writing a program, you have to start by
creating a New Project. Go to File > New >
Project… then select “Console Application” under
the “Basic” tab, click the “C++ Project” button, enter
the project name and click OK.
You will be prompted to select where you want to
save the project. Once set, click “Save”. You can now
begin working on your very first C++ program.
Using Dev-C++
Using Cxxdroid
To start writing a program using your smartphone,
install and open Cxxdroid. You will be routed to a new
C++ file. You should be able to start writing you program
from there. However, to write and compile your program
easier, you have to save your work first by tapping at the
----- icon then Save as. Navigate to the folder
where you want to save your file then tap Select
folder. Input the filename with file extension .cxx, then
click Save.
Using Cxxdroid
Your First C++ Program
Let’s begin by writing a simple program that will
display “Hello World” on the screen. Write the following
code. Output:
Your First C++
Program
Let us understand each part of the program below.

• #include <iostream> - It includes the standard input and output library


function. This is necessary so that our program is capable of receiving
and displaying data.
• using namespace std – It
sets

any undeclared identifiers to

default (standard).
Your First C++
Program
• int main () - it is the main function where the program execution
begins. It is followed by curly brackets {} indicating the start and
end of the function.
• //This program displays "Hello World" on the screen. – This is a
comment, it does not contribute to how the program works or display in
the
program execution. This is
only used to keep
programmers be guided
writing long lines of codes.
Your First C++
Program
• cout<<”Hello World”!; - This is a command to display the “Hello
World”
message on the screen. Syntax for output.
• return 0; - It tells the compiler that it is the end of the main() function,
thus, terminating the program.
Note: Each line in the function must
always end with a semi-colon (;).
It serves as a statement
terminator, this means the
compiler must proceed to the
next line.
Testing Your C++
Program
To see if the program is working, we need to compile
and run it. To do so, click the “Execute” menu,
select “Compile and Run” or just simply press F11 in your
keyboard.

For the Cxxdroid, simply tap the -------- icon at the


bottom of the screen.
Code
Outpu
t
progra
m

Using
C++ Output
To display any data from the program, we will use a
predefined object for output, cout. In our example, the
cout object is used to display a single line of text “Hello
World”.
To do so, type cout, followed by << and the text.
The text must be enclosed with double quotation marks
(“”), then end with a semi-colon (;).
Example:
cout<<”This is an output”;
C++ Output
We can also display multiple lines of texts. To do so, we
will use the object “endl”. The endl is used to insert a new
line of the output stream. To do so, put two open brackets
(<<) after the text, add the “endl”, and end with a semi-
colon (;). Another way of inserting a new line is to put “\n”
inside the text body.
For example:
cout<<“This is a the first line.”<<endl;
cout<<“This is the second line.\n”;
cout<<“This is the last line.”;
Code

Output
C++ Output
We can also use cout to call out the values
of variables to perform more complex functions. It will
be discussed in the next topic in the upcoming classes.
Assignmen
ttext:
W rite a C++ program that will display the following

Hi, my name is (your Sample


output:
name).
I am (your age) years
old. I live in (your home
Note:
town).Submit only the screenshot for the code and the
result. Deadline:
Wednesday, September 18, 2024 at 11:59 PM
through Google Classroom.
That’s all
for
today!
Thank you.
Keep safe.
God bless.

You might also like