Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Calderon, Karl Raymund A.

11 – ICT 2
COMPUTER PROGRAMMING
WRITTEN WORK 1 – REVIEWER

 String – used for storing text


-A string variable contains a collection of characters surrounded by
double quotes.
-to use strings, must include an additional header file in the source
code library.

1. The + operator can be used between strings


2. Strings length ( ), size ( )
3. Change string characters - You can access the characters in a string
by referring to its index number inside square brackets [ ]. (Note:
string index start with 0.)
4. Maximum and minimum – The max (x, y), min (x, y) function can be
used to find the highest and lowest value of x, y.
5. <cmath> Header: Other functions, such as sqrt (square root), round
(rounds a number) and log (natural logarithm), can be found in the
<cmath> header file.

 Condition and If Statements – C++ supports the usual logical condition


from mathematics

Less than: a < b


Less than or equal to: a < = b
Greater than or equal to: a > = b
Equal to: a = = b
Not equal to: a ! = b

You can use these conditions to perform different actions for


different decisions. C++ has the following conditional statements:
 Use if to specify a block of code to be executed, if a specified
condition is true.
 Use else to specify a block of code to be executed, if the same
condition is false.
 Use else if to specify a new condition to test, if the first condition is
false.
 Use switch to specify many alternative blocks of code to be executed.
1. The switch expression is evaluated once
2. The value of the expression is compared with the values of each
case.
3. If there is a match, the associated block of code is executed.
4. The break will stop the execution of more code, default
specifies some code to run if there is no case match.
(Note that it is in lowercase letters. Uppercase letters If or IF will generate
an error.)

 Loop
- Loops can execute a block of code as long as a specified
condition is reached.
- Loops are handy because they save time, reduce errors, and
they make code more readable.

1. For loop
Syntax:
Statement 1 - is executed (one time) before
Statement 2 – defines the condition for executing the code block
Statement 3 – is executed (every time) after the code block has
been executed.
2. While loop
3. Do/while loop

You might also like