You are on page 1of 4

Slide 1: C++ Programming.

This is a presentation full of information that was gathered and compiled by


group 1. Together, let us learn what c++ programming language is.

Slide2: Since c++ is an attempt to add object-oriented features to C, earlier it was called “C with
Objects”. It was designed by Bjarne Stroustrup at Bell Laboratories in 1979. To know more about c++, let
us know what an object-oriented program is since it was mentioned.

Object-oriented programming is used in c++. Object-oriented programming - As the name implies, this
type of programming makes use of objects. Object-oriented programming aims to implement real-world
entities in programming such as inheritance, hiding, polymorphism, and so on. The primary goal of OOP
is to connect the data and the functions that operate on it so that no other part of the code can access
the data except that function.

Slide 3: Now in c++ there is a thing called a keyword. So, what is a keyword in c++, pls read everyone (1)
meaning keywords are short in which their meanings are already predefined on the compiler. (2)
keywords cannot be uppercase (Read 1,2,3 on the PowerPoint)

Slide 4: Here are examples of commonly used keywords... in this example the keyword int indicates that
money is a variable of type integer. Now you must be wondering if money is a variable, then what is a
variable?

Slide 5: Variables are containers for storing data values. A variable can be in lowercase or uppercase
letters. 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

Slide 6: In creating or declaring a variable specifies the type and you can assign a value. Here is an
example:

This example uses the keyword and data type int, and money is the name of the variable. In assigning a
value to the variable we use the equal sign.

You can also create or declare a variable without assigning the value, and assign the value later.
Example:

But there is another way. The user can assign the value. Here is an example and pls listen as I explain the
process. This is the input. The keyword or data type is int and the variable name is money. Notice that I
did not assign a value. Instead, I input cout and let the user enter the value. Once the user entered the
value it will be processed and stored hence the value of the variable money is now the number entered
by the user which is 160. In the output it is stated “Your money is: 160” but in my input, I only typed the
words Your money is: followed by the cout sign and the word money which is the variable, and in this
part, the variable has now the value 160 so in the output 160 is also shown.
Slide 7: Now we will proceed to operators. 1st is the arithmetic or mathematical operators. From the
word itself, these operators perform mathematical operations on operands. (explain).

There are various operators used in c++ Programming In C++, assignment operators are used to assign
values to variables, an example of this is the equal sign, Logical operators are used to checking whether
an expression is true or false, end many more. But I am going to elaborate more about the following
operators

2nd are the increment and decrement operators. ++ this is the increment operator which increases the
value of the operand by 1, while this is the decrement operator which decreases the value of the
operand by 1. Example: the value of x is 19 and the value of y is 6. Notice that there are 2 other variables
namely result1 and result2, in these variables we are going to store the result of the incremented and
decremented numbers. (line12) by using this operator we are incrementing the value of x meaning we
are adding one to 19 so the output now is 20. In line 16 by using this operator we are decrementing the
value of y meaning we are subtracting one to 6 so the output now is 5.

3rd is the relational operator. These are used to check the relationship between two operands or values.
If the relation is true, it returns 1 whereas if the relation is false, it returns 0. Example: we have 3
variables x with the value 19, and y with the value 6. We have another variable the result, with the
keyword bool. If you listened a while ago you would know what bool is. Does anyone have an idea?
Okay bool stores values with two states: true or false. this == operator checks if 19 is equal to 6 which
gives us 0 meaning false. This operator != checks if 19 is not equal to 6 which gives us 1 meaning true.
And below are other relational operators. The less than and greater than. There is also less than or equal
to and greater than or equal to.

The cin object is used to accept input from the standard input device i.e. keyboard while In C++, cout
sends formatted output to standard output devices, such as the screen. We use the cout object along
with the << operator for displaying output

Slide 8: Now let us apply all that I have discussed and all that you have learned. This is a sample code
that finds the quotient of 2 numbers.

//C++ sample

This is a comments line. All lines beginning with two slash signs are considered comment and do not
have any effect on the behavior of the program. The programmer can use this to include short
explanations. In this case the line is a brief description of what our program is.

#include <iostream>

Lines beginning with a hashtag sign are directives for the preprocessor. They are not regular code lines
with expressions. In this case the directive #include <iostream> tells the preprocessor to include
iostream standard file. The specific file includes the declarations of the basic standard input-output
library in C++, and it is included because its functionality is going to be used later in the program.

Using namespace std;


All the elements of the standard C++ library are declared within what is called a namespace, the
namespace with the name std.

As you have noticed there are blank lines and spaces, Blank lines have no effect on a program. They
simply improve readability of the code.

int main ()

This line initiates the declaration of a function. Essentially, a function is a group of code statements
which are given a name: in this case, this gives the name "main" to the group of code statements that
follow.

Brackets

Different programming languages have various ways to delineate the start and end points of a
programming structure, such as a loop, method or conditional statement. For example, Java and C++ are
often referred to as curly brace languages because curly braces are used to define the start and end of a
code block.

Int this code we used the keyword int meaning this code contains integers that will be stored in the
keyword int. We used the variables a and b for 2 values that will be entered, and the variable qt
represent quotient. The next line contains cout The "c" in cout refers to "character" and "out" means
"output". Hence cout means "character output". The phrases here will be shown in the output. It also
has cin meaning the user will input. Same goes to lines 13 and 14. Line 15 has qt=a/b meaning the value
of qt from the value of a divided by the value of b. The next line has cout “Your quotient is” and this
operator then the variable qt. In the output, The phrase together with the quotient will be shown. All
the lines are ended with a semi colon

You may have noticed that not all the lines of this program perform actions when the code is executed.
There is a line containing a comment (beginning with //). There is a line with a directive for the
preprocessor (beginning with #). There is a line that defines a function (in this case, the main function).
And, finally, a line with a statements ending with a semicolon (the insertion into cout), which was within
the block delimited by the braces ( { } ) of the main function.

Return 0;

The return statement causes the main function to finish. Return may be followed by a return code in our
example it is followed by the return code 0. A return code of 0 for the main function is generally
interpreted that the program worked as expected without any errors during its execution. This is the
most usual way of ending a C++ console program.

Now this is the output (explain)

Tips:

Know the basics; Know how to read between the lines in order to spot errors; Have blank spaces and
lines to make the program more readable, They are ok and are not considered as errors; Include all
library and functions in one go if possible, to avoid complicated codes that are not understandable

You might also like