KEMBAR78
Comp Rog | PDF | Algorithms | Computer Data Storage
0% found this document useful (0 votes)
30 views8 pages

Comp Rog

Uploaded by

loves sicheng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views8 pages

Comp Rog

Uploaded by

loves sicheng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

I.

Introduction to Computer Technology

1. Concept of a Computer System

What is a Computer?
- A computer is a collection of electronic devices operating under a set of instructions stored in its
own memory.
▪ It performs four general tasks, often remembered as IPOS:

• Input: Accepts data (raw facts like text, sound, image, video).
• Process: Manipulates data to produce information (processed data that is meaningful).
• Output: Produces results (e.g., display on screen, sound from speakers, hardcopy from printer).
• Storage: Stores these results for future use in its own memory or separate storage devices.

Simple devices like calculators and mobile phones can be considered simple computers due to their IPOS
functionality.

Types of Computers
- Computers vary in size, speed, and storage capacity, and can be categorized based on their operations
and specifications.

Analog Computers - Use analog signals (continuous range of values) and deal with physical variables like
voltage, pressure, temperature, speed. Found in research institutes, hospitals, and flight centers.

Digital Computers - Use electrical inputs (ON/OFF), representing data as 0s (OFF) and 1s (ON). Offer
accurate and faster results, ideal for complex problems. The PC (Personal Computer) is a popular example.

Super Computers - The fastest and most expensive computers, processing billions of instructions per
second. Used for complex scientific simulations, stock analysis, and weather forecasting.

Mainframe Computers - High-speed computers processing millions of instructions per second, also
expensive. Used for applications in banking, airlines, and railways.

Mini Computers - Lower speed and less expensive than mainframes, often supporting multiprocessing for
up to 200 users. Used as servers for major business applications.

Micro Computers - The most common type today, made cheaper and powerful by single-chip processors
(CPUs). Includes desktop computers (PCs), laptops, mobile phones, smartphones, tablets, and PDAs.

Hybrid Computers - Combine operations of analog and digital computers using digital-to-analog and
analog-to-digital converters. Used for specialized tasks, such as in hospital ICUs to monitor patient vital
signs.
Features of Computers
Speed
- Operate at very high speeds (milliseconds, microseconds, nanoseconds for billions of
instructions per second).

Accuracy
- 100% accurate unless given wrong data or instructions by the user.

Consistency
- Work efficiently and continuously for long hours without rest, maintaining speed and
accuracy as long as powered.

Versatile
- Can perform a variety of tasks, from complex science simulations to simple computations and
games, used in many fields and industries.

Storage
- Can store large amounts of data, replacing physical files with digital ones.

Reliability
- Data and work are easily accessible for future use due to their speed, accuracy, and
consistency.

2. Computer Hardware and Computer Software


- the two essential components of a computer; a computer is useless without either.

Hardware: Consists of the "hard" (physical, electronic, or mechanical) components of the computer.
Examples include input/output devices, processing units, and storage devices.

Software: Consists of the "soft" components, also called programs, which are applications used to
perform tasks and are sets of instructions fed to the computer.

Types of Software:
System Software: Programs that control and maintain computer operations and its devices.
Examples: Operating Systems (Windows OS, Ubuntu, Linux, Mac OS) and utility programs.

Application Software: Programs that perform specific tasks for the user. Examples: Microsoft
Office (word documents, spreadsheets, presentations), web browsers (Chrome, Mozilla, Internet
Explorer), and games.

Program Software: Also known as programming languages or development tools, used to create
other programs or applications. Examples: Java, C#, PHP, and C++. C++ will be used in this
subject.

3. Hardware Components of a Computer


- Hardware components are divided into: Input Devices, Processing Unit, Storage Devices, and
Output Devices. Data flow always passes through the processing unit from input or storage before
going to output or storage.
Input Devices
- Peripheral devices used to provide data in the form of instructions (keystrokes, mouse clicks,
touch screens, barcodes, sounds, images, videos) to the computer.
▪ examples: Keyboard, Mouse, Microphone, Joysticks, Image Scanners, Web Camera, Graphic
Tablets, Barcode Reader.

Processing Unit
- In digital computers, it's called the Central Processing Unit (CPU), or the "brain" of the computer.
It interprets program instructions and processes data.
▪ Speed is determined by: Clock frequency (MHz or GHz – instructions per second) and cache
memory (MB or GB – amount of instructions it can hold).
▪ The CPU is embedded in the system unit's motherboard, which also contains main memory and
slots for additional memory or I/O cards (sound, video).

Storage Devices
- Consist of a storage medium (physical media holding data) and storage devices/drives (record and
retrieve data from the medium).
▪ Primary Storage: Directly accessible to the CPU, stores currently used/active data.
• Read-Only Memory (ROM): Data cannot be modified, standard instructions from manufacturers.
Non-volatile (data remains after power off).
• Random-Access Memory (RAM): Data can be accessed at any order. Temporary/volatile (data
loses after power off).
▪ Secondary Storage: Not directly accessible to CPU, slower but higher capacity. Data is non-
volatile. Examples: hard disks, USB flash drives, memory cards, compact discs.
▪ Common Storage Devices: Hard disk drive, CD-ROM/CD-RW drives.

Output Devices
- Peripheral devices used to display or output information in a human-understandable form after
data is processed (image, video, text, sound).
▪ Examples: Monitor (displays texts and images, temporary record, types: CRT, LCD), Printer
(produces hard copies, permanent record, types: inkjet, dot matrix, laser), Speakers (produces
sound), Projector (displays output for larger audience), Plotters (uses pens to draw large images
like engineering designs).

II. Introduction to Computer Programming

1. What is a Computer Program?


- Computer programs are sequences of instructions or steps that the computer interprets and
executes.
- A single application (e.g., Facebook) can consist of several small computer programs.
examples: sending text messages, playing games, checking social media feeds, role-playing
games like DOTA.

2. What is Computer Programming?


- Computer programming is simply describing the steps or writing down the steps to do something.
- Since computers don't understand human languages, a specific programming language is used.
- Programmers write instructions ("source codes") in a high-level programming language (e.g., C+
+).
- A language compiler (e.g., C++ compiler) interprets and translates the source code into machine
language (0s and 1s), which the computer understands, creating an executable file (.exe).
- Computers only do what they are told; they behave based on how the program is designed and
programmed.

3. Process of Program Design


- There are two major phases in creating a program:
▪ Problem-Solving Phase: Defines the problem and identifies the instructions to solve it. This
involves creating algorithms and flowcharts.
▪ Implementation Phase: Converts the instructions (from the problem-solving phase) into source
codes using a programming language (for this course, C++).

Simulations or tests are crucial in both phases to verify the solution.


- The key to a good program is to write specific and detailed sets of instructions that provide a clear
solution to the problem.

III. Algorithm Analysis and Design

1. Concepts of Algorithms
- An algorithm is a sequence of steps to reach a goal or achieve a desired output.
- Algorithms exist in everyday life, from signing into social media to baking a cake.
- A typical algorithm has inputs (values needed), a step-by-step process, and outputs (desired
data/values).
- Algorithms can be expressed as pseudocode or flowcharts in programming.

2. Designing Algorithms using Pseudocodes


- Pseudocodes are written in simple English and do not follow any particular computer language.
- They may include common mathematical expressions (=, *, +, -) and conditional statements
(if..then..else).
- Simulation/Testing: To check an algorithm, assign actual values to input variables and follow the
steps to see if it accomplishes its purpose.

Characteristics of a good pseudocode:


▪ Well ordered: Steps are clear and logical.
▪ Unambiguous operations: Steps are clearly defined and leave no room for misinterpretation.
▪ Effectively computable operations: Operations can be performed.
▪ Produces results: Leads to a desired output.

3. Designing Algorithms using Flowcharts


- A flowchart is a graphical representation of an algorithm using symbols.
- Symbols describe operations and are connected by arrows (flow lines) to indicate the sequence of
steps and data flow.
Basic Symbols used in Flowchart:
▪ Terminator (Oblong): Marks the Start/End of the system.
▪ Action or Process (Rectangle): Represents a single step or computation (e.g., mathematical
formula).
▪ Input/Output (Parallelogram): Represents material or information entering (Input) or leaving
(Output) the system.
▪ Flow Line (Arrow): Indicates the sequence of steps and direction of flow, connecting symbols.
▪ Decision (Diamond): Represents a decision or branching point (e.g., if and if-else conditions),
with points representing results (Yes/No) and subsequent steps.

IV. Introduction to C++ Programming Language

1. The Beginnings of C++ Language

Charles Babbage (English Mathematician and physical scientist) designed the first truly programmable
computer in 1873, earning him the title "The father of Modern Computer".

Lady Ada Lovelace became the first programmer and developed the Ada language.

C language: Invented by Dennis Ritchie in 1973.

C++ language: Developed by Bjarne Stroustrup from Bell Labs in the early 1980s, based on C and
Simula.
- versions include Turbo C/C++ (ANSI standard) and Visual C++ (Microsoft's version).

2. Programming Using C++ Language


- C++ is a procedural programming language (also known as structured programming).
- It is crucial to design an algorithm (pseudocode or flowchart) before writing a C++ program, as
these instructions will directly translate to source code.
GIGO (Garbage In, Garbage Out)
- Incorrect program logic or input will lead to incorrect output.
Compiling and Running
- Source code written in C++ must be compiled (translated into machine language) and then run
(executed). Errors during compilation need to be addressed.

3. Basic C++ Program Layout


- A basic C++ program, like "Hello World!", follows a specific structure.

Key Rules:
▪ C++ is case-sensitive (e.g., int is different from Int or INT).
▪ Most line statements end with a semicolon (;) to mark the end of an instruction.

Parts of the Layout:


▪ #include<iostream.h> (Line 1): An include directive that tells the compiler to find information
about items used in the program from the iostream library. iostream contains definitions for routines
handling input from the keyboard and output to the screen (e.g., cout).
▪ int main() (Line 3): The main function, indicating the start of the program. C++ always looks for
this function first. int specifies that the function returns an integer value.
▪ { and } (Lines 4 and 14): Braces that mark the beginning and end of the main() function (or any
block of code). They always come in pairs.
▪ variable declarations; (Line 5 - optional): Where variables are defined and their data types
specified.
▪ statement_1; ... last_statement; (Lines 7 to 10): The program statements containing the
executable code or instructions.
▪ return 0; (Line 13): The return statement, which returns a zero value (conventionally indicating
successful execution).

4. Basic Programming Terms


Reserved Words
- Words already used by the C++ programming language with special meanings. They cannot be used
as identifiers. Examples: #include, int, cout, return.
Identifiers
- Names used to reference variables, functions, labels, and other objects defined in a program.
▪ Rules: 1 to 32 characters; first character must be a letter (a-z, A-Z) or an underscore (_);
subsequent characters can be letters, numbers (0-9), or underscores.
▪ Examples of valid identifiers: count, _player1, first_player.
▪ Examples of invalid identifiers: !count, player.1, first..player.
▪ Case-sensitive: a is different from A, and count is different from COUNT.

Syntax
- The format or structure in which source codes must be written, following specific rules for each
function.
Semantics
- The meaning or description of the syntax. Understanding semantics helps interpret syntax.

V. C++ Basics

1. Variables, Input/Output Streams, and Assignment Statements


Variables
- An identifier used to name and store data values. All variables must be declared before use.

Output Streams (cout):


▪ Used to display text on the screen or the value of a variable.
▪ Uses the insertion operator << (two "less than" signs).
▪ To display text: cout << "write text here"; (text in quotations).
▪ To display a variable's value: cout << variable_name; (no quotations).
▪ To combine text and variables: cout << "Value is " << variable_name;.
▪ \n: Represents a new line character, causing subsequent output to appear on the next line.
▪ Requires #include<iostream.h>.

Variable Declarations:
▪ Allows users to define the kind or type of data a variable will store.
▪ Syntax: type_name var_name_1, var_name_2, ..., var_name_last;.
▪ type_name: The data type (e.g., int for whole numbers).
▪ var_name_1, etc.: The list of variable names (must be valid identifiers).

Input Streams (cin):


▪ Used to store values typed at the keyboard into a variable.
▪ Uses the extraction operator >> (two "greater than" signs).
▪ Syntax: cin >> variable_name;.
▪ Requires #include<iostream.h>.
Assignment Statements
- Statements that change the value of a variable through computation, operation, or simply
assigning a constant value.
- Used to write formulas in program code, similar to mathematical formulas.
- Syntax: variable_name = expression;.
▪ expression: Can be a constant or a combination of variables, operators, and constants.

Arithmetic Operators:
• +: Addition
• -: Subtraction
• *: Multiplication
• /: Division
• %: Modulus (computes the remainder of a division). E.g., 7 % 6 results in 1.

2. Variable Initializations and Constants


Variable Initialization
- Setting an initial value to a variable upon declaration.
- Syntax: type_name variable_name = constant_value;.
- Example: int exchangeRate = 41;.
- Allows the value of the variable to still change later in the program.
Constants:
- Identifiers whose values do not change throughout program execution.
- Declared using the const keyword.
- Syntax: const type_name const_variable_name = constant_value; (can also be a list).
- Attempting to change the value of a constant after its initial assignment will result in a compiler
error.

3. Data Types
- It is important to identify the correct data type for a variable based on its intended use (whole
number, decimal, character, etc.).
- Using an incorrect data type can lead to incorrect or less precise data.

Basic Data Types in C++:


▪ int (integer): Whole numbers (optional + or - sign, sequence of digits). Range: +/- 32,767 (2
bytes).
▪ long (long integer): Whole numbers, can hold larger values than int, takes more memory. Range:
+/- 2,147,483,647 (4 bytes).
▪ float (floating point): Numbers with decimal values (e.g., 5.0, -0.789), includes an optional
exponent. Range: 10^-38 to 10^38 (4 bytes).
▪ double (double precision): Special float type that stores more significant digits and has a larger
exponent, takes more memory. Range: 10^-308 to 10^308 (8 bytes).
▪ long double: Even larger range for decimal numbers. Range: 10^-4932 to 10^4932 (10 bytes).
▪ char (character): A single letter, digit, punctuation mark, or control symbol.
▪ void: Value-less or null, used for functions that do not return a value.

4. Arithmetic Expressions and more Assignment Statements

Arithmetic Expressions: Formulas that use a combination of multiple operators and variables.

Precedence Rule
- C++ follows a specific order of operations for computations in expressions:
1. Parentheses () (computed first).
2. Multiplication *, Division /, Modulus % (evaluated from left to right).
3. Addition +, Subtraction - (evaluated from left to right, last priority).
example: x = 8 + (9-3) * 4 / 2 calculates x = 20 by first handling parentheses, then
multiplication, then division, then addition.

Shorthand Assignment Statements:


- A simplified way to write assignment statements, especially when a variable's value depends on its
current value.
- Syntax: variable_name operator = expression; (equivalent to variable_name = variable_name
operator expression;).
- examples:
• count = count + 1; becomes count += 1;.
• total = total - discount; becomes total -= discount;.
• age = age % 50; becomes age %= 50;.

You might also like