PINOY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Self-Teaching ng C++

Go down

Self-Teaching ng C++ Empty Self-Teaching ng C++

Post by sirjon Mon Apr 20, 2020 12:43 am

Maraming nag naglalabasan sa online ng free tutorial tungkol s C++ programming. Sabi kasi nila, eto daw isa sa basics ng mga naglalabasang programs, kasama na sa Arduino sofware program na hanggang ngayon, di ko pa rin maunawaan. Sana, kasama ko kayong makatulong para matutunan ng mga baguhan tungkol sa software programming...


SELF-TEACHING C++  PROGRAMMING BY SIRJON
+++++++++++++++++++++++++++++++++++++++

I. DISPLAYING "SENTENCES"

PROGRAM CREATION NO. CP1.1
--------------------------

01 #include
02 using namespace std;
03 int main(void){
04 cout<< "Hello World!";
05 return 0;
06 }
----------------------------
RUN...

Hello World!

------------------------------
END of program

====================================

2) USING THE 'STRING' DESIGNATIONS

PROGRAM CREATION NO. CP1.2
----------------------

01 #include
02 using namespace std;
03 int main(void){
04
05 string say1, say2 ; // intilializing by assigning values
06 say1 = "Hi, my name is Jhunn. ";
07 say2 = "I'm learning C++ programming.";
08
09 cout<< say1 << say2;
10 return 0;
11 }
------------------------
RUN...


Hi my name is Jhunn. I'm learning C++ programming


----------------------------------
END of program

=====================================

LECTURE:

  If you notice, the following always appear in this
C++ programmings



a)       #include

   ... is the C++ main library



b)   using namespace std

   ... is that part of library to be used



c)       int main(void)

   ... int means 'integer', it was taken from the
'main' library. It is like initializing or to start the
program "clean" without any previous data left from
previous composed program



d)  {  - open "bracket" sign
   }  - close "bracket" sign

   ... the brackets indicate that the program is only
within that scope. Later it become clear how this
set of brackets will separate certain program executions
from another separate actions.



e)         return 0

   ... this is a command to tell that everything will
be set back to a 'void' or clean data inputs



f)    ; - semi-colon

   ... most often use after each field. DO NOT FORGET
to put this so that the program will 'run' or else,
the program will not execute. So, the main purpose of
the semi-colon is for the computer to determine that
composed elements on one row is executable.


OTHERS

   ... while the following are also common



g)   cout<<  (output command)

      ... means to display the result



h)   " "  
     ... means the alphabetical letters composing
a phrase or sentence inside, will be displayed, such
as the phrase "Hello World"
   

=========================================================


II.  C++: DEALING WITH BASIC MATH


LECTURE

   In C++, we create a mathematical expression, either
by representing them by letters, constants and
operational symbols

A. OPERATIONAL SYMBOLS

a) + 'PLUS' SIGN (to add)
b) - 'MINUS' SIGN (to subtract)
c) * 'TIMES' SIGN (to multiply)
d) / 'DIVIDED BY' SIGN (to divide)
e) = 'EQUAL' SIGN

examples:

   a, b, c
 
   sum = a + b

   circumference = 2 * pi * r


B. RELATIONAL SIGNS

a) == (EQUAL TO, SAME AS)
b) != (NOT EQUAL TO, NOT THE SAME AS)
c) >  (GREATER THAN)
d) <  (LESS THAN)
e) >= (GREATER AND EQUAL TO)
f) <= (LESS AND EQUAL TO)

-------------------------------

note:

**SPECIAL MATH OPERATIONS

a) incremental (increasing by one)

      ++(variable)

b) decremental (decreasing by 1)

      --(variable)


examples:

    let n = 0
 
       ++n = (n+1),(n+1+1), (n+1+1+1) ... (n+1+1+...)

           = 1, 2, 3, 4, 5, 6, 7, 8, 9,...

   
    let m = 20

       --m = (m-1), (m-1-1), (m-1-1-1)...(m-1-1-...)

           =   19, 18, 17, 16, 15 ...

-----------------------------------


C. VARIABLES AND CONSTANTS

   In C++, before we create a variable, we need to
determine first if we are dealing either with an integer
or a real number (that is, with decimal period included)

Examples:

 integers ( 3, 77, -8, -113 ...)

 decimal numbers ( pi = 3.1416, 5.0 ...)

   In entering data in the computer, it is necessary to
give it an idea of what you are entering... are you going
to enter a whole number, a number with decimal value, a
phrase or a whole sentence? To do that, first we need
to determine and designate a 'data entry' code for the
computer to read

____________________________________________________

DATA TYPE    SIZE      DECRIPTION


  int      4 bytes   stores whole number (integer)
                     regardless of sign (+n or -n)

 float     4 bytes   a number that has a combined
                     decimal period ( ex. 0.5  3.1416)
                        (floating number)
 
 double    8 bytes   similar to floating number except
                     that it can represent longer
                     decimal value( ex. 0.030303030303)

 boolean   1 byte    either yes or no, true or false
                      or between 0 and 1

 char      1 byte    represented by a letter or special
                      character
                     
_____________________________________________________

SIMPLE MATH PROGRAM

PROGRAM CREATION NO. CP2.1
---------------------------

01 #include
02 using nameplace std;
03 int main(){ // adding two numbers
04
05 int a ;
06 int b ;
07 int sum ;
08 a = 2 ;
09 b = 5 ;
10 sum = a + b ;
11
12 cout<< sum;
13
14 return 0 ;
15 }

---------------------------

options:
...

05 int a, b, sum ;
06 a = 2 ;
07 b = 5 ;
08 sum = a + b ;

...

---------------------------

another options:

...

05 int a = 2 ;
06 int b = 5 ;
07 int sum = a + b ;

...

---------------------------

RUN...

( will display ... )

     7

---------------------------
END of program


===========================================================


III. C++: BASIC MATH WITH COMBINED SENTENCES
==============================================

LECTURE 1:

   In this part of our lecture, it is important that you
already read and understood the previous lectures (part 1
and part 2).

   Now, let's apply what we previously learned and apply
it by defining the measure of a circle's circumfernce and
area.

   From our Math textbooks, the measure of the
circumference, is:
 
            Circumference = 2 x radius x pi

by which, pi = 3.1416

While the area of a circle, will then be:

           Area = pi x square of the radius


    Since, in C++, the multiplication sign "x", is not use
but rather represented by the asterisk sign, then we can
represent them these way:

          Circumference = 2 * radius * pi

          Area = pi * radius * radius

PROGRAM CREATION NO. CP3.1
-------------------------------

01 #include
02 using namespace std;
03 int main (void){
04
05 double radius; // initialization, designating variables
06 double pi;
07 double Circumference;
08
09 radius = 5.0;
10 pi = 3.1416;
11 Circumference = 2 * radius * pi;
12
13 cout<< Circumference;
14 return 0;
15 }

---------------------------

RUN...

 31.416

---------------------------
END of program

=========================================


LECTURE 2:

    The above program is considered to be very simple and
it does, directly give us the output or result. However,
it is not flexible, in a sense that it only applies to one
value,that is, if the radius is fixed at a value of 5.0 .

Now, let me now introduce a new code of command:
 

               cin>>

The above code means, 'to enter' or to input 'something'...

In creating the next program, we will notice the flexibility
of using the command " cin>> " and combining sentences.


PROGRAM CREATION NO. CP3.2
--------------------------

01 #include
02 using namespace std;
03 int main(void) {
04
o5 double r;
06 cin>> r ; // need to put this in this line
07 double pi = 3.1416;
08 double C = 2 * r * pi;
09 double A = pi * r * r
10
11 cout<<  "If the radius of a circle is "<12 cout<<  "Then the circumferce will be "<13 cout<<  "While the area will be "<14 cout<<  "Provided that pi = 3.1416.";
15
16 return 0;
17 }
18
-------------------------------

RUN...

INPUT: 100


   If the radius of a circle is 100 cm.
   The circumference will be 628.32 cm.
   While the area will be 31416 cm.
   Provided that pi = 3.1416.

-------------------------
END of program

=========================================

ADDITIONAL LECTURE:

     Note that instead of putting the whole words radius,
area and circumference, we represented them by letters
and make sense of their meaning by providing set of words
in displaying the outputs.

     Also, we created flexibility by making it possible
to input different values for the circle's radius.

============================================================


IV. THE 'IF AND ELSE' STATEMENTS

    Now that you have the idea behind the very basics of C++
program, we can now create a program, that atleast, can do or
obey a command statement.

The 'if' command, should always be followed by the 'else'
command, to create the impression of a conditional statement.

That is, the output will follow, the condition or conditions
given.

You should always remember to put a condition after the
command 'if' enclosed by these symbols: ( ).

Inside these symbols, is the given condition.

Let's consider the program below:

PROGRAM CREATION NO. CP4.1
-----------------------------

01 #include
02 using namespace std;
03 int main(void){
04
05 int a;
06 cin>> a;
07 string say1, say2, say3;
08 say1 = "The number you entered is seven!"
09 say2 = "The number you entered, "
10 say3 = " is not seven."
11
12 if (a == 7){
13     cout<< say1 ;
14   }
15 else {
16   cout<< say2 << a << say3;
17   }
18 return 0;
19 }
-------------------------------
Run...

Example a:

(Input = 12)

... the computer will display:

 
    The number you entered, 12, is not seven.

Example b:

(Input = 7)

... the computer will display:

    The number you entered is seven.

--------------------------------
END of Program

=========================================

LECTURE:

   The given condition a == 7 means the 'if statement'
will only display, unless the corresponding setup
output is at the right response, that will match the
'if code command'

    In C++, you have to use the indicator, == (double
equal signs) to indicate 'equal to or same to' condition.

    You can also create a program, that has opposite
conditions but will still, conform with the same output

    In C++, you have to use the indicator, != (punctation
mark, then equal signs) to indicate that the value 'is not'
or not equal to the given variable.

    Let's study the progrm below:

PROGRAM CREATION NO. CP4.2
-------------------------------

01 #include
02 using namespace std;
03 int main(void){
04
05 int a;
06 cin>> a;
07 string say1, say2, say3;
08 say1 = "The number you entered is seven!"
09 say2 = "The number you entered, "
10 say3 = " is not seven."
11
12 if (a != 7){
13     cout<< say2<14   }
15 else {
16   cout<< say1 ;
17   }
18 return 0;
19 }

-------------------------------

Run...

Example a:

(Input = 12)

... the computer will display:

 
    The number you entered, 12, is not seven.

Example b:

(Input = 7)

... the computer will display:

    The number you entered is seven.

==============================================  

LECTURE

     If you will notice, the condition given is that,
if the input is not equal to 7, then the corresponding result
to display should be...
----------------------------
13     cout<< say2 << a << say3; (line 13 of CP4.2)
----------------------------

     Which, is the same as to...

----------------------------
16     cout<< say2 << a << say3;  (line 16 of CP4.1)
----------------------------
     
     Also, you will notice the similar reponds...

------------------
16   cout<< say1 ;  (line 16 of CP4.2)
------------------
------------------
13   cout<< say1 ; (line 13 of CP4.1)
------------------

     THEREFORE, IT IS IMPORTANT TO ALWAYS REMEMBER THAT THE
CORRESPONDING RESPONSE SHOULD ALWAYS AGREE WITH THE
GIVEN CONDITION.

=============================================================


Last edited by sirjon on Mon Apr 20, 2020 12:59 am; edited 4 times in total

sirjon
Starter

Posts : 11
Join date : 2010-01-19

Back to top Go down

Self-Teaching ng C++ Empty Re: Self-Teaching ng C++

Post by sirjon Mon Apr 20, 2020 12:46 am


NOTE: Use this link to check my created program and clickRUN below to check kung tama nga...

[You must be registered and logged in to see this link.]

sirjon
Starter

Posts : 11
Join date : 2010-01-19

Back to top Go down

Self-Teaching ng C++ Empty Re: Self-Teaching ng C++

Post by sirjon Mon Apr 20, 2020 1:13 am

Mga bossing, mali yata ko ng forum na na-post. Pwede bang malipat sa tamang venue?

sirjon
Starter

Posts : 11
Join date : 2010-01-19

Back to top Go down

Self-Teaching ng C++ Empty Re: Self-Teaching ng C++

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum