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

C++ G10 slides presentation and notes

The document provides an introduction to C++ programming, defining key concepts such as computer programming, programs, and programmers. It explains how computers understand human language through assemblers, compilers, and interpreters, and highlights the differences between compilers and interpreters. Additionally, it covers the basics of C++ syntax, data types, and variables, along with practical examples and resources for getting started with C++.

Uploaded by

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

C++ G10 slides presentation and notes

The document provides an introduction to C++ programming, defining key concepts such as computer programming, programs, and programmers. It explains how computers understand human language through assemblers, compilers, and interpreters, and highlights the differences between compilers and interpreters. Additionally, it covers the basics of C++ syntax, data types, and variables, along with practical examples and resources for getting started with C++.

Uploaded by

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

Introduction to C++ programming

• Define computer programming


• Define a program
• define a programmer
• Why write computer programs
• How computers understand our language
• Assembler, Compiler and Interpreter
• Difference between compiler and interpreter
• Programming terms
• Introduction to C++ programming
• Structure of C++ program
What is computer programming
• A computer is a device that cannot perform any task without human
inputs.
• Instructions has to be written to tell the computer what to do.
• Computer programming is the process that professionals use to write code
that instructs how a computer, application or software program performs.
• A program is a set of instructions and related data meant to carry out a
specific task
• A Programmer is a person who write programs (instructions) in a
computer.
• The process of writing instructions to the computer is called programming
• Computer programs are written to tell a computer what to do
Computer Language
• Computers does not understand the human language
(source codes/High-level language)
• Machine language (Binary code) is a language the
computers understand.
• Binary codes are simply 0s and 1s
• First computer only accepted binary codes and programmers
wrote 0s and 1s to communicate
• E.g. instead of writing A (human language),
01000001(machine language) was being written for
computer to understand.
How does computer understand human
language
• Programmers created software to translate programs
written in human language into machine language
called Assembler, Compiler, and interpreter.
• Assembly language was the first human language
which programmers came up with. In this language,
mnemonics (abbreviations) where being used to write
codes. In order to communicate with computers, An
Assembler was designed to translate a program
written in assembly language into machine language.
Compiler and Interpreter
• The most and easy way of writing codes in more human
way was introduced called High-level language. This
enables programmer to write in most readable way using
human languages like English instead of using
abbreviation.
• Two programs where created to translate programs
written in high-level language (source code) into
machine codes (binary codes). These programs where
called compiler and interpreter.
Difference between compiler and interpreter

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

Boolean 1 byte Stores true or false values


char 1 byte Stores a single character/letter/number, or ASCII values

int 2 or 4 bytes Stores whole numbers, without decimals

float 4 bytes Stores fractional numbers, containing one or more decimals.


Sufficient for storing 7 decimal digits
Double 8 bytes Stores fractional numbers, containing one or more decimals.
Sufficient for storing 15 decimal digits
String 8 bytes Store a sequence of characters
To Know the size of datatype use the following
code

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

•To initialize a variable means to assign a value to a


variable
•Example
•int var_num1;// variable declared
•int var_num1=30;// variable initialized (meaning
the variable is assigned to a value 30) it is storing a
value 30
Program to print value in a variable

The output for the program


Any question
For Question and others
Mr. Kaonga JTS Bachelor degree ICT
Contact: 0978734443/0966253335
Follow me on
YouTubehttps://www.youtube.com/watch?v=u2Vj26q5dq8&t=387s
email: [email protected]

Former student: Zambia University College of Technology and UNZA

You might also like