Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

P1 (Programming)

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

LESSON 1

Computer Organization and Why Programming


Digital computers

 are comprised of hardware (equipment) and software (instructions that make the equipment operate).
 A computer needs a software for you to be able to run such applications and do it base on your purposes.

Computer hardware consists of the following electronic or electro-mechanical devices:

1. Memory
 a collection of registers and storage devices that store the computer's state map.
Two types of memories:
 Primary memory: temporary store files
-Random access memory: ex: phones
 Secondary primary: permanently store files
-The hard disk
2. Central Processing Unit (CPU)
 The "brains" of the computer, which does the work of changing the state map stored in memory.
3. Input/Output (I/O) Processor
 manages and performs the work associated with reading information that is added to portions of the computer's state map.
4. Peripherals
 a.devices that store ancillary software and data,
b. output devices such as printers and plotters,
c. input devices such as a mouse or scanner, as well as the keyboard or display device (e.g.,the monitor).

KEYWORD:

1. Microcode
low-level instructions that make the CPU run correctly.
2. Machine Code
slightly higher-level than microcode, these instructions are loaded directly into memory and comprise a stored, executable program.
3. I/O and Computational Libraries
Sets of procedures and instructions that the I/O processor and CPU use to input or output data, as well as compute various arithmetic, math,
and data handling operations.
4. Application Software
programs that users run to accomplish various home, business, and scientific tasks such as word processing, spreadsheets, drawing or
sketching, graphics, and games.
5. Operating System
interfaces application software (and hardware) with libraries and microcode in a convenient manner that is transparent to the user.
Example: windows 10 or 11

A program is a set of step-by-step instructions that directs the computer to do the tasks you want it to do and produce the results you want.

Programming is the process of writing an algorithm into a sequence of computer instructions. (process of writing programs)

A set of rules that provides a way of telling a computer what operations to perform is called a programming language

LESSON 2
The Internet and Number Systems
Internet
 is a worldwide interconnection of thousands of different computers and networks. It allows users to efficiently share information, programs
and equipment and to communicate with each other.
 All computers on the Internet communicate with one another using the Transmission Control Protocol/Internet Protocol (TCP/IP)
suite.

Uses of Internet
 E-mail and other forms of communication
 searching for jobs
 instant messaging, video conferencing and social media
 Online discussion groups and forums, dating, gaming, and shopping
 Research, Reading electronic newspapers and magazines, and File transfer

Security and the Internet


 Installing antivirus and antimalware
 Creating difficult, varied passwords that are impossible to guess.
 Using a virtual private network (VPN) or, at least, a private browsing mode, such as Google Chrome's Incognito window.
 Only using HTTPS
 Making all social media accounts private.
 Deactivating autofill.
 Turning off the device's GPS.
 Updating cookies so an alert is sent anytime a cookie is installed.
 Logging out of accounts instead of just closing the tab or window.
 Using caution with spam emails and never opening or downloading content from unknown sources.
 Using caution when accessing public Wi-Fi or hotspot

NUMBER SYSTEM CONVERSION

 As you know decimal, binary, octal and hexadecimal number systems are positional value number systems. To convert binary, octal and
hexadecimal to decimal number, we just need to add the product of each digit with its positional value. Here we are going to learn other
conversion among these number systems.

NUMBER SYSTEM CONVERSION


Binary – use by the computer (1 and 0)

Optal – 8 numbers (0-7)

Decimal – 10 numbers (0-9)

Hexa-decimal – (16)

LESSON 3
Most people access the Internet through Internet Service Providers (ISPs). In most locations, you can now access Internet with local telephone
lines.

Introduction to C++ Template

Properly written C++ programs have a particular structure. The syntax must be correct, or the compiler will generate error messages and not produce
executable machine language.

Syntax-is the set of rules that define what the various combinations of symbols mean. This tells the computer how to read the code.

Compiler - is a special program that processes statements written in a particular programming language and turns them into machine language or
"code" that a computer's processor uses.

General Structure of a Simple C++ Program

Listing 2.1 (simple.cpp) is one of the simplest C++ programs that does something

o The actual name of the file is irrelevant, but the name "simple" accurately describes the nature of this program.
o The extension .cpp is a common extension used for C++ source code.
o After compiling and executing (usually, the term used is "running")

#include <iostream>

o This line is a preprocessing directive.


o All preprocessing directives within C++ source code begin with a # symbol.
o This one directs the preprocessor to add some predefined source code to our existing source code before the compiler begins to process it.
o The iostream is actually an external file named iostream.h (which is one of a lot of header files available in C++, it will be discussed
later).
o The header file is like an instruction manual that contains information on how the compiler translate a statement or command

void main () {

o This specifies the real beginning of our program.


o we are declaring a function named main All C++ programs must contain this function to be executable.
o The opening curly brace at the end of the line marks the beginning of the body of a function.
o The body of a function contains the statements the function is to execute.
o The body of our main function contains only one statement. This statement directs the executing program to print the message

std::cout << "This is a simple \nC++ program!\n";

o The body of our main function contains only one statement.


o This statement directs the executing program to print the message This is a simple C++ program! on the screen.
o A statement is the fundamental unit of execution in a C++ program.

Functions contain statements that the compiler translates into executable machine language instructions.

All statements in C++ end with a semicolon (;).

The combination of backslash and the letter n represents the newline character. The "n" indicates that the printing on that line is complete, and any
subsequent printing should occur on the next line.

The closing curly brace ( } ) marks the end of the body of a function.
Both the open curly brace and close curly brace are required for every function definition

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

int main() (

o The type of data to pass on to other codes is always placed before the name of the function (main). In Listing 2.1, it returns nothing,
that is why void is placed before the main().

return 0;

o If the return value from Main is not used, returning void allows for slightly simpler code.
o The return value from Main is treated as the exit code for the process.
o If void is returned from Main, the exit code will be implicitly 0.
o Take note that 0 is also an integer.

Variations of our simple program

o The using directive in Listing 2.2 (simple2.cpp) allows us to use a shorter name for the std::cout printing object. We can omit the std::
prefix and use the shorter name, cout. This directive is} optional, but if we omit it, we must use the longer name. The name std stands for
"standard," and the std prefix indicates that cout is part of a collection of names called the standard namespace.
o The std namespace holds names for all the standard C++ types and functions that must be available to all standards-conforming C++
development environments.

o name cout known to the compiler via its focused using directive
o provides a blanket using directive that makes all names in the std namespace available to the compiler.
o This approach offers some advantages for smaller programs
o This blanket using directive allows programmers to use shorter names as in the more focused using directives, and it also can use
fewer lines of code than the more focused using directives, especially when the program uses multiple elements from the std namespace.
o The statement in the main function in any of the three versions of our program uses the services of an object called std::cout.
o The std::cout object prints text on the computer's screen. The text of the message as it appears in the C++ source code is called a string, for
string of characters.
o Strings are enclosed within quotation marks(").
o The symbols << make up the insertion operator.
o You can think of the message to be printed as being "inserted into the cout object. The cout object represents the output stream; that is, text
that the program prints to the console window. The end of the message contains the symbol sequence in. This is known as a character
escape sequence. This newline character effectively causes the cursor to move down to the next line.
o The cout object, which is responsible for displaying text on the screen, receives the text to print terminated with the newline character to
move to the next line.
o we'll refer to this type of statement as a print statement, even though the word print does not appear anywhere in the statement.
o any statement in C++ must appear within a function definition. Our single print statement appears within the function named main

std::cout object does not need #include and using directives

Template for simple C++ programs

o we need the #include directive that brings the cout definition from <iostream> into our program. Depending on what we need our program
to do, we may need additional #include directives.
o The main function definition is required for an executable program, and we will fill its body with statements that make our program do as
we wish. Later, our programs will become more sophisticated, and we will need to augment this simple template

Multiple Statements

o Any function, including main, may contain multiple statements.

Each print statement "draws" a horizontal slice of the arrow. The six statements constitute the body of the main function. The body consists of all
the statements between the open curly brace The word delimit means to determine the boundaries or limits of something.

Character Escape Sequence

o Character Escape Sequence are non-printable characters.


Below are the rest of the escape sequence:
‘\t'- the tab character
‘\n'- the newline character
‘\r’- the carriage return character
‘\f’- the form feed character
‘\b’- the backspace character
‘\a’- the "alert" character (causes a "beep" sound or other tone on some systems)
‘\0’-the null character (used in C strings, will be part of a topic later)
o These special non-printable characters begin with a backslash (\) symbol.
o backslash (\) is called an escape symbol, and it signifies that the symbol that follows has a special meaning and should not be interpreted
literally. This means the literal backslash character must be represented as two backslashes: ‘\\’
o These special non-printable character codes can be embedded within strings. To embed a backslash within a string, you must escape it; for
example, the statement cout << "C:\\Devicppcode" << "\n';
o The following two statements behave identically:
cout << "End of line" << ‘\n";
cout<<"End of line\n";
o The first line has two different data, a string (enclosed by double quote) and a character (enclosed by single quote). Different data in a cout
statement must always be separated by the symbol <<
o Listing 2.7 uses the \t to arrange the alphabet letters A to N with equal spacing in between. The default tab spacing is composed of 7
characters' space.

Template for simple C++ programs

o The main function definition is required for an executable program, and we will fill its body with statements that make our program do as
we wish.

COUT- Character Out

LESSON 4
Cin- >>, known as the Extraction Operator

Cout - <<

SUM = value1 + value2

o An assignment statement, it contains the assignment operator (=)

ARTIHMETIC EXPRESSION

o Involving two variables anjd the =

Evaluation

o The process of determining the expression’s value

ARTIHMETIC OPERATIORS:

+ ADDTION

- SUBTRACTION

* MULTIPLICATION

/ DIVISION

% MODULUS

UNARY OPERATOR

o Has only one operand


o Expects a single numeric expression

TRUNCATION

o Process of discarding the fractional part leaving the only whole no. part
o Simply removes any fractional part of the value

You might also like