0% found this document useful (0 votes)
80 views14 pages

Overview of C++

C++ is a popular cross-platform language used to create high-performance applications. It has undergone major updates in 2011, 2014, and 2017. C++ is an object-oriented language that provides structure and allows for code reuse. The language includes input/output streams like cout and cin. C++ programs typically include header files, declare a main function, and use statements like cout << to output text and cin >> to accept user input. Variables can be created to store values of different data types.

Uploaded by

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

Overview of C++

C++ is a popular cross-platform language used to create high-performance applications. It has undergone major updates in 2011, 2014, and 2017. C++ is an object-oriented language that provides structure and allows for code reuse. The language includes input/output streams like cout and cin. C++ programs typically include header files, declare a main function, and use statements like cout << to output text and cin >> to accept user input. Variables can be created to store values of different data types.

Uploaded by

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

Overview Of c++

EPHREM T. GOFA SAWLA, 1


C++ introduction
C++ is a cross-platform language that can be used to create high-performance applications.
The language was updated 3 major times in 2011, 2014, and 2017 to C++11, C++14, and C++17.
C++ is one of the world's most popular programming languages.
C++ can be found in today's operating systems, Graphical User Interfaces, and embedded systems.
C++ is fun and easy to learn!
C++ is an object-oriented programming language which gives a clear structure to programs and
allows code to be reused, lowering development costs.

EPHREM T. GOFA SAWLA, ETHIOPIA 2


C++ Syntax

#include <iostream>
using namespace std;

int main()
{
  cout << “Ephrem Computer Tutor!";
   return 0;
}

EPHREM T. GOFA SAWLA, ETHIOPIA 3


cont…
Line 1: #include <iostream> is a header file library that lets us work with input and output
objects. Header files add functionality to C++ programs.
Line 2: using namespace std; means that we can use names for objects and variables from the
standard library.
Don't worry if you don't understand how #include <iostream> and using namespace std works. Just
think of it as something that (almost) always appears in your program.

Line 3: A blank line. C++ ignores white space, is made for better clarity and readablity.
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 “Ephrem Computer Tutor".

EPHREM T. GOFA SAWLA, ETHIOPIA 4


Cont…
Note: Every C++ statement ends with a semicolon ;.
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 main function.

EPHREM T. GOFA SAWLA, ETHIOPIA 5


Omitting Namespace
You might see some C++ programs that runs without the standard namespace library. The using
namespace std line can be omitted and replaced with the std keyword, followed by the :: operator for
some objects:

#include <iostream>

int main() {
std::cout << “Ephem Computer
Tutor!";
return 0;
}

It is up to you if you want to include the standard namespace library or not.

6
EPHREM T. GOFA SAWLA, ETHIOPIA
1. C++ Output (Print Text)
The cout object, together with the << operator, is used to output values/print text:

#include <iostream>
using namespace std;
Ephrem Computer Tutor!
int main()
{
  cout << “Ephrem Computer Tutor!";
   return 0;
}

EPHREM T. GOFA SAWLA, ETHIOPIA 7


C++ New Lines
To insert a new line, you can use the \n character:

#include <iostream>
using namespace std; Ephrem Computer Tutor!
Streaming C++
int main() {
  cout << “Ephrem Computer Tutor! \n";
  cout << “Streaming C++";
  return 0;
}

EPHREM T. GOFA SAWLA, ETHIOPIA 8


C++ Variables
Variables are containers for storing data values.
In C++, there are different types of variables (defined with different keywords), for example:
int - stores integers (whole numbers), without decimals, such as 123 or -123
double - stores floating point numbers, with decimals, such as 19.99 or -19.99
char - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes
string - stores text, such as "Hello World". String values are surrounded by double quotes
bool - stores values with two states: true or false

EPHREM T. GOFA SAWLA, ETHIOPIA 9


Declaring (Creating) Variables
To create a variable, you must specify the type and assign it a value:
Syntax: type variable = value;
Where type is one of C++ types (such as int), and variable is the name of the variable (such as x
or myName). The equal sign is used to assign values to the variable.
To create a variable that should store a number, look at the following example:
 Create a variable called MyIDNo of type int and assign it the value 15:

int MyIDNo = 15;


15
cout << myNum;

EPHREM T. GOFA SAWLA, ETHIOPIA 10


Display Variables
The cout object is used together with the << operator to display variables.
To combine both text and a variable, separate them with the << operator:
Example:
int myAge = 29;
cout << "I am " << myAge << " years old.";

I am 29 years old.

EPHREM T. GOFA SAWLA, ETHIOPIA 11


2. C++ User Input
You have already learned that cout is used to output (print) values.
Now we will use cin to get user input.

cin is a predefined variable that reads data from the keyboard with the extraction operator
(>>).
In the following example, the user can input a number, which is stored in the variable x. Then
we print the value of x:
int x;
cout << "Type a number: ";
cin >> x;
cout << "Your number is: " << x;

EPHREM T. GOFA SAWLA, ETHIOPIA 12


Cont…
Good To Know
cout is pronounced "see-out". Used for output, and uses the insertion operator (<<)
cin is pronounced "see-in". Used for input, and uses the extraction operator (>>)

EPHREM T. GOFA SAWLA, ETHIOPIA 13


This Much is Enough for Overview

Thank you!!!

if you like it share with your friends!


EPHREM T. GOFA SAWLA, ETHIOPIA 14

You might also like