



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Chapter 5: Looping Structures Repetitions
Repetition repeating a block of code until a condition is met.
Three Repetition Structures
while(Boolean Expression) { //Executable Statements ⋮ } while statement ([pre] while loop)
- validation before executing statement
do { //Executable Statements ⋮ } while(Boolean Expression); do while ([post] while loop)
- execute statement before validation
For loop
These three steps are essential for looping structures.
Difference of while and do while statement while statement (no semicolon) do while (with semicolon)
*sa do while tsaka while, boolean expression lang yung initialization tsaka yung pagchange ng loop control variable ilalagay niyo siya sa executaable statement (kasama siya dun sa loob ng block) *unlike sa for statement, required ka mag-initialize, magvalidate tapos kumbaga process nalang yung nasa loob ng for loop (sa may executable statement) *mas simplified yung sa for statement
Break and Continue Statements The break statement can also be used to jump out of a loop.
The continue statement breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop.
Break statement - exit loop Continue statement - pag nakita yung continue babalik siya sa boolean expression
Chapter 6: Functions Function
function name(function argument) *parameters
Types of Functions
Return statement – causes the value to be returned to the calling function. Format: return expression;
Value returning functions Value returning functions are used when only one result is returned and that result is used directly in an expression.
Function prototype – a function declaration that does not include the body of the function.
FORMAT: returnDataTypeFunctionName(ListofArgumentData Types);
Function definition– a function declaration that includes the body of the function. It is the actual code of the function and always outside the main ( ) function. General form: returnDataType FunctionName(ListofParameters) {
//Executable Statements } Function Declaration
*match dapat yung parameters
Void functions
Void Function
Accessing variables in functions Local variable
Local Variable
Chapter 7: Strings String a string variable contains a collection of characters surrounded by double quotes. to use strings, you must include an additional header file in the source code, the
#include
Arrays composed of multiple storages
Sa character array, laging may space na alotted kaya minus 1 start from index 0
String concatenation The + operator can be used between strings to add them together to make a new string. This is called concatenation. NOTE: C++ uses the + operator for both addition and concatenation. Numbers are added. Strings are concatenated.
String Concatenation Addition for integer purposes Concatenation for string purposes *pero pag nagcombine ka ng string at integer, mag eerror yon
String Functions Manipulation sa characters
Difference between cin and getline function cin *for integer datatype *treats space or enter as terminator sa pagstore ng bawat characters dun sa variable name getline function
*more appropriate to use in string manipulations *lahat ng special characters tinetreat niya as string (like space, endl)
*para maging same sa output ng cin lagyan lang ng character delimiter (space) meaning magstop siya magstore pagdating sa space.
Final example: Hangman activity
Get character functions getch(); a pre-defined function in “conio.h” reads a single character from the keyboard and it doesn’t echo to the console and doesn’t wait for an enter to store in a variable. Get Character function
- kung ano yung tinatype mo hindi makikita sa console
ASCII TABLE / Carriage Return enter - 13 backspace – 08
Mas malaki decimal value ng lower case letter kesa sa upper case letters
exam kasama din yung ascii codes
If the number is negative then it is represented using 1’s complement. First represent the number with positive sign and then take 1’s complement of that number.
A namespace is designed to overcome this difficulty and is used as additional information to differentiate similar functions, classes, variables etc. with the same name available in different libraries. Using namespace , you can define the context in which names are defined. In essence, a namespace defines a scope.