SCOPE Introduction to C++ Selection Structure for Loop Introduction to Data Structures and Algorithms Arrays Functions Structures
C++
a good foundation of learning other programming languages like Java, Python, etc.
Bjarne Stroustrup
C++ general-purpose programming language developed by__________as an extension of the C language.
int main()
entrypoint of the program. The codes in main will be executed.
return 0;
exit status of the application. If 0 is the exit status, the program worked fine until the end, without errors.
cout<<
is used for printing a certain text or number. To use, the header file must be included
<<insertion operator
That sends the text or value in the console to be printed.
Data Structure
a way of arranging data on a computer so that it can be accessed and updated efficiently
Escape Sequences
are special characters characterized by a backslash (\) and a letter or symbol beside it
Escape Sequences
used in cout statements to show spaces, new lines, or show symbols that cannot be outputted using the normal way of printing
New Line
Moves the cursor to the beginning of the next line.
/n
What is new line symbol?
Tab
Inserts a horizontal tab.
\t
What is tab symbol?
Pre defined and user defined functions
Function two Types are ___________, ____________?
Function Declaration
Function Definition
Function Call
The Three Function Aspects are?
\\
What is symbol of backlash character?
Variables
they act as containers or buckets where the data will be put into and stored
objects that are used to store values
Variable
A___________ data type remains as it is once declared, so when you try to assign a letter to an integer variable, the character value will be converted into its integer equivalent.
- American Standard Code for Information Interchange
What is the meaning of ASCII?
65
ASCII of “A”
97
ASCII of “a”
48
ASCII of “o”
cin>>
allows the user to type in the data asked by the program. works if the iostream header file is included.
>> extraction operator
that reads the input from the keyboard
Algorithm
a set of well-defined instructions to solve a particular problem it takes a set of input(s) and produces the desired output.
Good Quality Program
precisely defined input and output
clear and unambiguous steps
most effective in solving problems
not written in computer code
usable in any programming language
Data Structures
a storage that is used to store and organize data
a way of arranging data on a computer so that it can be accessed and updated efficiently
Linear Data Structures
elements are arranged in sequence one after the other, making it easy to implement.
Linear Data Structures
Examples: arrays, stacks, queues, linked lists
Nonlinear Data Structures
Elements are not in any sequence. They are arranged in a hierarchical manner where one element will be connected to one or more elements.
Nonlinear Data Structures
Examples: graphs and trees
Data Structure
are used to hold data
Algorithm
used to solve the problem using that data.
Arrays
It is an ordered collection of values of the same type.
Elements can be accessed via its index (address, location).
All arrays consist of contiguous memory locations.
One-dimensional Arrays
It is made up of one row or one column of array members with the same name but different index values
2D Array
is the most basic type of multi-dimensional array.
Outer Loop, Inner Loop
Using for loop to access all elements of the 2D array. The ________ is for the rows, the________ is for the columns.
Functions
Container for a few lines of code to accomplish a specific task
Set of programming statements enclosed in { and }
Functions
For reusability and modularity, they can be called numerous times.
Pre-defined Functions.
Built into the language to perform operations. It is stored in Standard Function Library.
User-defined Functions.
Defined by the user to perform specific tasks.
Function Declaration
tells the compiler about a function name and how to call the function.
Function Definition
contains the actual statements which are to be executed
Function Call
performs the defined tasks
Actual Parameters or arguments
are values which are passed in the function call.
Formal Parameters
are variables local to that function and cannot be used in other parts of the program,
return Keyword
Terminates the function and returns the value.
-Define the function’s return data type
-Use the return keyword inside the function body.
Two things are required to return a value to the caller:
void Keyword
It is defined before the function name.
The call to the void function is a standalone statement.
Void functions don’t need to have the return statement
Recursive Functions
A function whose definition contains a call to itself.
TAIL RECURSION
• The function calls itself as the final statement of the function.
• When it is called, it must process or carry out some action.
• It does nothing after that call.
HEAD RECURSION
• The initial statement of a recursive function is also the first time it calls itself.
• At the time of calling, is not required to process anything.
• Everything is completed when the method returns.
LOCAL VARIABLES
Only statements that are inside that function or block of code can use them.
• They are not known to functions outside their own.
GLOBAL VARIABLES
• Their values are maintained throughout the life of your program.
• It may be accessed from any of the program’s functions.
Base case, Recursive case
A recursion has two parts:
Base Case
Or the halting case. It is the indication of when the recursion will stop.
Recursive Case.
It is the recursive call with a different input that progressively gets closer to the base case.
Structures
A collection of different data types under a single name.
Used to express data about anything that is more complex than what can be represented by a single integer, character, or Boolean.
Importance of Structure
-compile multiple pieces of information on a single topic in one location
-collect data of the same data kinds and parameters incredibly simple to maintain
-aggregating together related data in one entity through the struct keyword allows programs to construct user-defined types.
Syntax and Implementation
Structures are declared by starting with the struct keyword then the structure name (identifier).
Inside the curly braces are the member variables with different data types.
Accessing Elements
Use the dot [.] operator to access the inner variables of the structure
Typedef
is a keyword used to specify alternative names for primitive types.
typedef struct,
With the application of ____________ variable declaration no longer needs the keyword struct.
True
True or False | The main method is the entrypoint of the program
std::cout
statements to show spaces, new lines, or show symbols that cannot be outputted using the normal way of printing.
#include<iomanip>
to be able to use std::setprecision, defines the manipulator functions that are used to manipulate the format of the input and output of our program. It is a part of the input/output library in C++.
std::cout << std::fixed;
this is needed to change the default formatting of the numbers that are printed to "fixed-point notation".
std::setprecision(3)
- this is the line that sets the number of decimal places to be printed.
Namespace
cout is part of the standard library, and all the elements in the standard C++ library are declared within what is called a ____________
Character
A letter, symbol, or white space). This should be enclosed in single quotes.
Integer
Whole numbers ranging between ±32767.
Floating Point Values
Real numbers that can handle up to 7 decimals. To indicate
that it is float, you should add an f
at the end of the value.
Double Floating Point Values
Real numbers that can handle up to 15 decimals
Double is just the same as a
Float but can hold larger
numbers.
Boolean
Truth values (true/false).
Constant variables
are special type of variables whose values can't be changed.
const data_type CONSTANT_NAME = value;
Declaring a constant variable using that follows this
syntax:
Uppercase letters
The naming of constants are usually in____________ to easily identify that the variable is indeed a constant.
Comments
in your code will not be executed because they serve as guide to the programmers, which makes it very useful especially when making a project with lots of lines of codes.
Flat Case
All words are in lowercase but connected directly.
Camel Case
Uncapitalized first word, capitalized proceeding words (like a camel shape) and connected directly.
Pascal Case
All words are capitalized and connected directly.
Snake Case
All words are in lowercase and connected by an underscore (_).
Macro Case
All words are in uppercase and connected by an underscore (_).
This casing is often used in constants.
Overriding Shortcuts
There are instances when we wish to perform calculations on the value of a variable and then overwrite the value of the variable by the result it garnered.
pow ( )
Returns the value of the left operand
(base) raised to the power of the right
operand (exponent).
sqrt ( )
Returns the square root of a number.
floor ( )
Rounds down a number to the largest
integer less than or equal to the number.
ceil ( )
The opposite of floor. Rounds up the
number to the smallest integer greater
than or equal to the number
fabs ( )
Returns the absolute, positive value of num.
Data Structure
-a storage that is used to store and organize data
. It is a way of arranging data on a computer so that it can
be accessed and updated efficiently
Graphs
Example of Non-Linear Data Structure that each node is called vertex, and each vertex is connected to other vertices through edges.
Trees
Example of Non-Linear Data Structure also a collection of vertices and edges. But there can only be one edge between two vertices.
ARRAY TRAVERSAL
-Used for visiting, accessing, and printing each element of an array exactly once
• It is necessary to create a variable that will track the position of the element that is currently being accessed