C++ G10 slides presentation and notes
C++ G10 slides presentation and notes
Compiler Interpreter
• The compiler translate the whole • Translates the program one statement
program in one go. at a time (line by line)
• As it scans the code in one go, the • Considering it scans code one line at a
errors (if any) are shown at the end time, errors are shown line by line.
together. • It is easier to debug for an error
• It is difficult to debug for an error • It is less efficient.
• It is more efficient. • Python, Ruby, Perl, SNOBOL, MATLAB,
• C, C++, C#, etc are programming etc are programming languages that
languages that are compiler-based. are interpreter-based.
Programming terms
•Debugging> is the process of detecting and
removing of existing and potential errors.
•Compile> Convert (a program) into a machine-
code or lower-level form in which the program can
be executed.
•Syntax > means the same as rules
•Syntax errors> type of error that comes as a result
of not following programming language rules
•Errors> means the same as mistakes
Types programming languages
Any question
Introduction C++
• C++ is one of the world's most popular programming
languages.
• C++ is an extension of C programming Language
• C++ can be found in today's operating systems, Graphical
User Interfaces, and embedded systems.
• C++ is an object-oriented programming language which
gives a clear structure to programs and allows code to be
reused, lowering development costs.
• C++ is portable and can be used to develop applications that
can be adapted to multiple platforms.
• C++ is fun and easy to learn!
• As C++ is close to C, C# and Java, it makes it easy for
programmers to switch to C++ or vice versa.
Key things to Note
• C++ is case sensitive. This means declared
should be used exactly the it was declared to
avoid syntax errors.
• C++ has key words that can not be used as
variables. Examples of key words include: const,
continue, double, default, delete, else, enum,
explicit, friend, float, for, int, long, mutable, new,
operator among others.
C++ syntax (structure)
Example explained
• Line 1: #include <iostream> is a header file library that lets us
work with input and output objects, such as cout (used in line
5). Header files add functionality to C++ programs. It is also
refared to as. preprocessor directive
• Line 2: using namespace std means that we can use names
for objects and variables from the standard library. Replaced
std::
•:: (full colons are called scope resolution operators )
Example explained
Line 3: A blank line. C++ ignores white space. But we use it to make the
code more readable.
Line 4: Another thing that always appear in a C++ program, is int main().
This is called a function. Any code inside its curly brackets {} will be
executed.
Line 5: cout (pronounced "see-out") is an object used together with
the insertion operator (<<) to output/print text. In our example it will output
"Hello World".
Note: Every C++ statement ends with a semicolon ;.
Note: The body of int main() could also been written as:
int main () { cout << "Hello World! "; return 0; }
Remember: The compiler ignores white spaces. However, multiple lines
makes the code more readable.
Line 6: return 0 ends the main function.
Line 7: Do not forget to add the closing curly bracket } to actually end the
Omitting namespace std;
•If you want to omit namespace std, write your code as
statement in bold text
•#include <iostream>
•int main() {
• std::cout << "Hello World!”<<std::endl;
• return 0;
•}
Any question
C++ Get Started
• To start using C++, you need two things:
• A text editor, like Notepad, to write C++
code
• A compiler, like GCC, to translate the C++
code into a language that the computer will
understand
IDE
•An IDE (integrated Development Environment) is a
text editor with a compiler.
•There are different types of IDEs. Some of them
include Dev C++, Code blocks and Visual Studio
code.
•In our lessons we will be using Dev C++ for it is
easier to use. You can use the link below to
download IDE
•https://sourceforge.net/projects/orwelldevcpp/
Data types in C++
•Data type represents the type of data you want to
enter in the computer
•Different types of data that can be entered into
the computers includes characters (‘a’ ,’B’, ‘?’),
strings (“jacaranda”, “Ruth”, “4!Harison*”),
Boolean( true or false), integers numbers
(1,2,3,4..), decimal numbers (1.4,2.5,6.8..),
Examples of C++ datatypes
Data Type Size Description
Output
Any question
Variables in C++
• Variable (containers/placeholders) is a storage
space associated with a unique name to identify
them.
•A variable is not a value, it keeps a value.
•It is made up of non key words that can be a
combination of letters, numbers, some characters
such as Underscore (_)
•Examples of variable name Decimal_Num1;
Variable Syntax (structure)
•The general Syntax for declaring a variable is
<datatype><variable name>;
•Example
•int var_num1;
•int is a datatype
•var_num1 is a variable name
•; semicolon that is used to show the end of
declaration.
Declaring and initializing a variable