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

Chapters 1 and 2

An overview of computers and programming , Elements of high-quality programs

Presented by:
Joshua
Joel
Precious
Understanding computer systems

.Hardware
. Software
. Application software
.System software
.Input
. Processing
.Output

-Hardware
Is the physical devices associated with a computer, which need
instructions to control its operations, such as data input,
processing, and output

-Software
Is computer instructions that tell the hardware what to do.
Programs are written by programmers and can be bought or
downloaded from the Web. Programming is the process of writing
software instructions, which this book focuses on.

-Application software
Is the software used to perform tasks, such as word-processing,
spreadsheets, payroll and inventory programs, and games.

-System Software
Is the software used to manage a computer, such as operating
systems and smartphones.

-Input
Data items are text, numbers, and other raw material entered into
and processed by a computer. They can include facts and figures
about entities such as products, customers, and personnel, as well
as images, sounds, and mouse movements.
-Processing
Processing data items involves organizing, sorting, checking
accuracy, and performing calculations with a CPU, which requires
special programming techniques to efficiently use multiple
processors.

-Output
Data items are usually sent to a printer, monitor, or other output
device for people to view, interpret, and use the results.
Sometimes output is placed on storage devices, such as hard
drives, flash media, or a cloud-based device, which can be used
later as input for another program.

.Programmers write computer instructions in a computer


programming language such as Visual Basic, C#, C++, or Java.
Each language has rules governing its word usage and
punctuation, known as the language’s syntax a few examples are

Language Statement that displays Hello on a single line


Java System.out.println(“Hello);
C++ cout << “Hello” << endl;
Visual Basic Console.WriteLine(“Hello”);
Python print “Hello”
COBOL DISPLAY “Hello”.

More about computers and programming

. Computer memory is stored in temporary internal storage, in


places like Random Access Memory (RAM)

RAM- is a form of internal, volatile memory. It is used to store


programs and data items but its content is lost when computers
are turned off or loses power Permanent storage devices, such as
disks, are nonvolatile and keep their contents even when there is
power lost. If a power loss occurs while working on a computer,
the system has been set to automatically save the work on a
nonvolatile storage devices such as a hard drive

For a computer program to work properly, it requires translation


into machine language, formulated as binary digits 0s and 1s.
Interpreters or compilers play an important role in translating
source code into this machine language. Detecting syntax errors
becomes relatively effortless with its prompt notification system
and displaying software-generated error messages upon
translating the program.
Understanding simple program logic

-It is essential to construct programs in a specific order, including


all required instructions while excluding any surplus ones. Syntax
errors present a critical challenge as they prevent complete
translation and effective execution. Even though eliminating syntax
errors limits complications, there is still possible exposure to logical
errors leading to flawed output.

Suppose you instruct someone to make a cake as follows:

Get a bowl
Stir Add two eggs
Add a gallon of gasoline
Bake at 350 degrees for 45 minutes
Add three cups of flour

-The most important details are that cake-baking instructions use


English language syntax correctly, but are out of sequence,
missing, and belong to procedures other than baking a cake.
Logical errors are more difficult to locate than syntax errors, and
most simple computer programs include steps that perform input,
processing, and output. For example, if you want to write a
computer program to double any number, you would write it using
English-like statements.

input myNumber
myAnswer = myNumber * 2
output myAnswer
The number doubling process includes 3 instructions:

-Provided instructions for inputting myNumber demonstrate an


example of an input operation. Upon retrieval, the resulting number
is stored in a dedicated memory location imposed upon it through
naming conventions - that being 'myNumber'. The value saved to
this variable may differ each time it's used; for instance, it can
stand at "3" on one use and "45" during another. It should also be
emphasized that variable names within this book cannot have
spaces embedded.

-It is important to note that the hardware device holds no relevance


once you input, process, or output a value. Similar to how
obtaining eggs can be done through purchasing them at a store or
harvesting them from your own chickens, practical considerations
may exist but this book solely prioritizes the logic of operations.
Understanding the progamming

development cycle

- A programmer's job involves writing instructions, but not just


typing them on a computer keyboard, the steps of a programming
development cycle is:

1. Understand the problem.


2. Plan the logic.
3. Code the program.
4. Use software (a compiler or interpreter) to translate the program
into machine language.
5. Test the program.
6. Put the program into production.
7. Maintain the program.

Understanding the problem


-Programmers write programs to satisfy the needs of end users,
such as Human Resources departments, Billing departments, and
Order departments. To do this, programmers must first understand
the needs of the users.

Psuedocode and Flowchart symbols


-Pseudocode is an English-like representation of the logical steps
it takes to solve a problem, which is false code, or sentences that
appear to have been written in a programming language but do not
necessarily follow all syntax rules

- A flowchart is a practical representation of the same logical steps


Pseudocode is a planning tool that involves writing down all the
steps used in a program. It is usually prefaced with a beginning
statement and end with a terminating statement. It does not
require punctuation or capitalization, and is flexible because it is a
planning tool, not a final product. Here is an example of
pseudocode:

Start

Input myNumber

myAnswer= myNumber*2

Output myAnswer

End
Quick reference

Terminal:

Flowline:

Input/output:

Process:

External module call:


Understanding data types
A data type is a classification of:

- What values the item can hold


- How the item is stored in the computer memory
- What operations can be performed on the item

There are 2 data types which is…

Numeric: it describes data that consists of numbers, it can hold


digits and also have mathematical equations perform on it

String: describes data that is non numeric, it can hold texts, things
like letters from the alphabet and other special characters

Understanding Unnamed, Literal Constants

-Numeric constant is a non-changing number stored in computer


memory, without additional characters like dollar signs or commas,
which may be added for readability.

-A string constant, also known as alphanumeric value, is used


within quotation marks in computer programs to represent
alphanumeric characters, numbers, and other characters.

-The numeric constant 43 and the string constant “Amanda” are


examples of unnamed
constants—they do not have identifiers like variables do.
Understanding a declaration’s data type

- Numeric variables hold digits and can perform mathematical


operations, like myAnswer 5 and myNumber * 2, resulting in
numeric values.

- A string variable holds text, special characters, and digits, often


used in programming for non-arithmetic purposes like account
numbers or zip codes.

-Type-safety in programming languages prevents incorrect data


type assignments, allowing variables to be assigned only if the
data item is the correct type. This is called strongly typed.

Understanding a Declaration’s identifier

- An identifier is a program component's name chosen by the


programmer, such as myNumber and myAnswer in the number-
doubling example. The language translator associates these
names with specific memory addresses.

- Computer programming languages have unique rules for creating


identifiers, including letters, digits, hyphens, underscores, dollar
signs, foreign-alphabet characters, and reserved keywords. Newer
languages generally have virtually unlimited variable names, while
older languages have uppercase letters. In the past, identifiers
were case-sensitive, with HoUrLyWaGe, hourlywage, and
hourlyWage being separate variable names. Programmers use
multiple conventions for naming variables, depending on the
language or employer's standards.
Assigning values to variables

- myAnswer 5 myNumber * 2

-Such an assignment statement is a binary operator that involves


two actions: computing the arithmetic value of myNumber * 2 and
storing it in the myAnswer memory location. The equal sign is the
assignment operator, which operates from right to left and requires
two operands. The expression to the right of the assignment
operator evaluates first, and the result is assigned to the operand
on the left. The operand to the left represents a memory address,
indicating the location of the result.

Where to declare variables:

- Variables must be declared before first use in a program, with


some languages requiring declaration at the beginning, others at
each module's beginning, and others allowing declaration
anywhere.

Declaring named constants:

Most programming languages allow creating named constants,


which are useful names for non-changing values. They simplify
code by eliminating magic numbers, which are unnamed constants
with unclear purposes.

For example:

num SALES_TAX_RATE 5 0.06


After SALES_TAX_RATE is declared, the following statements
have identical meaning:
taxAmount 5 price * 0.06
taxAmount 5 price * SALES_TAX_RATE
The way in which named constants are declared differs among
programming languages.
Performing Arithmetic Operations

Most programming languages use the following standard


arithmetic operators:
1 + (plus sign)—addition
2 - (minus sign)—subtraction
* (asterisk)—multiplication
/ (slash)—division

-Languages support various arithmetic operators, including the


assignment operator (5) and binary operators like the addition and
subtraction operators. Standard arithmetic operators are binary
operators, requiring expressions on both sides. For example,
adding two test scores and assigning the sum to a variable named
totalScore can be seen as arithmetic operations. However, it is
important to remember that the equal sign is the assignment
operator, and the statement is actually taking the original value of
totalScore, adding 10 to it, and assigning the result to the memory
address on the left of the operator.

-In programming languages, combining arithmetic statements


follows rules of precedence, which dictate the order in which
operations in the same statement are carried out. These rules
include evaluating expressions within parentheses first,
multiplication and division next, and addition and subtraction next.
The assignment operator has a low precedence, meaning that
operations on the right of the assignment operator (multiplication
and addition) are always performed before the final assignment to
the variable on the left.

- In languages like Java, C11, and C#, dividing an integer by


another integer results in an integer, causing the decimal portion to
be cut off or truncated.
Modulrizing

-Programmers break down programming problems into smaller


units called modules, which are referred to as subroutines,
procedures, functions, or methods. These units are used by
programmers in different programming languages, such as Visual
Basic, C, C11, C#, Java, and older languages like COBOL, RPG,
and BASIC.

- A main program calls a module by using its name, causing it to


execute. When the module's tasks are complete, control returns to
the caller's location. Modularization, also known as functional
decomposition, breaks down a large program into modules for
three reasons: providing abstraction, enabling multiple
programmers to work on problems, and allowing easier reuse of
work. Modularization is not mandatory for computer use, but it
offers benefits such as abstraction, problem-solving, and easier
reuse of work.

Modulrizing provides abstractions

- Modularized programs are easier to understand because they


allow programmers to see the "big picture" by focusing on
important properties and ignoring nonessential details. Abstraction,
or selective ignorance, is essential for a more organized and
efficient day. By using a higher-level, abstract list, tasks become
more manageable and complex tasks appear simpler. Without
abstraction, life would be tedious, making it essential to prioritize
tasks and avoid unnecessary details.
Understanding the Most Common Configuration for
Mainline Logic

-Housekeeping tasks are essential steps in a program to prepare


for the rest, including declaring variables and constants, displaying
instructions, and opening files. While global variables and
constants are not widely used, they are used to understand
modularization. Chapter 9 of the comprehensive book explains
how to make variables local. Inputting the first data item is part of
the housekeeping module, and Chapter 7 covers file handling.

-Detail loop tasks are essential for a program's core work,


executing repetitively for input data until no more are needed, like
payroll calculations.

- End-of-job tasks involve finalizing the program, including display


of messages and closing open files, to finish the application.

You might also like