0% found this document useful (0 votes)
19 views13 pages

BASIC PzdbzcbvROGRAMMING PRINCIPLES

The document discusses 10 basic programming principles including KISS, DRY code, open/closed, composition over inheritance, single responsibility, separation of concern, documenting code, refactoring, and clean code. It also discusses 5 basic steps in programming, algorithms, programming symbols, logical structures, and accumulator variables.

Uploaded by

Brent Sebastian
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)
19 views13 pages

BASIC PzdbzcbvROGRAMMING PRINCIPLES

The document discusses 10 basic programming principles including KISS, DRY code, open/closed, composition over inheritance, single responsibility, separation of concern, documenting code, refactoring, and clean code. It also discusses 5 basic steps in programming, algorithms, programming symbols, logical structures, and accumulator variables.

Uploaded by

Brent Sebastian
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/ 13

10 BASIC PROGRAMMING PRINCIPLES

1. KISS - Keep It Simple, Stupid


a. write code as simple as possible.
b. Never be overly clever or showing off with a thick block of advanced code.
c. Use a clear variable names

2. Write DRY Code (Don’t Repeat Yourself)


a. Avoid duplication of data or logic
b. Find an algorithm that uses a loop instead.

3. Open/Closed
a. Make your code open to extension but closed to modification.

4. Composition over inheritance


a. Object w/ complex behaviors should contain instances of objects w/ individual
behaviors.

5. Single Responsibility
a. Every class or module in a program should only provide one specific
functionality.

6. Separation of concern
a. is an abstract version of the single responsibility principle. This idea states that a
program should be designed with different containers, and these containers
should not have access to each other.

7. You aren’t going to need it


a. Never code for functionality on the off chance that you may need something in
the future.
b. You shouldn’t try to solve a problem that doesn’t exist.

8. Document Your Code


a. Make it a habit to print your code.
b. Leave comments to explain objects.
c. Enhance variable definitions.
d. Make functions easier to understand.

9. Refactor (proofread and summarize with same result)


a. Refactoring code means reviewing your code and looking for ways to optimize it,
making it more efficient while keeping the results the same.

10. Clean Code at All Costs


a. Leave your ego at the door and forget about writing clever code.
b. Dont code to impress others. You’re into this coding profession to solve
problems.
c. Don’t try to pack a ton of logic into one line.
d. Put yourself in the next guy’s shoes whenever possible.

5 BASIC STEPS IN PROGRAMMING

1. Problem analysis (break down a problem) - a problem is generally considered to be a


task, or a situation. In each case, a problem is considered to be a matter which is difficult
to solve or settle; a doubtful case, or a complex task involving doubt and uncertainty.

2. Logic formulation (single step / resolution to the problem) - the process of coming out w/
the basic steps to implet a procedure in programming. This is usually resorted to when
having top-down design. Flowcharts and pseudo-codes are the two of most common
output of the exercise.
a. Logic - is a grammar of correct thinking and reasoning.
3. Coding (conversion) -

4. Testing - if program is correct


a. ERROR TO ENCOUNTER:
i. Syntax error - incorrect grammar, or command use is incorrect.
ii. Logic error -
iii. Runtime error (Aben) - error during runtime or execute time

5. Documentation - need print on a paper.

ALGORITHM (all types of command)


● An algorithm is a procedure or formula for solving a problem, based on
conducting a sequence of specified actions.
● In mathematics and computer science, an algorithm usually means a small
procedure that solves recurrent problems..
1. Expressing ALGORITHM
● Pseudocode is an informal way of programming description that does not
required any stricts programming language syntax.
● It is used for creating an outline or a rough draft of a program.
● Pseudocode summarizes a programm’s flow but excludes underlying details.
2. FLOWCHART
a. Is a driving which defines the pictorial view of the logic use to solve a problem.
b. It is composed of special symbols connected with straigh line.
c. It also summarizes a program’s flow and excludes underlying details.

2 TYPES OF FLOWCHART
1. System flowchart
a. display how data flows in a system and how decisions are made controls events.
b. Show the flow of data to and through the major components of a system such as
data entry, programs, storage media, processors, and communication networks.

2. Program Flowchart
a. A graphical representation of the sequence of operations in a program.
b. It shows the sequence of instructions in a single program or subroutine.

PROGRAMMING SYMBOLS

1. TERMINAL - indicates start or end of the program.

STOP, START OR
RETUNR

2. PROCESS - used to define a single a variable or mathematical operation. = / ()

= / ( OPEN CLOSE -
+)

3. INPUT/OUTPUT - indicates input or output operation.

INPUT - ppsok ex. INPUT X, Y


READ - mg bbsa galing sa
specific locAtion
WRITE - write to storage
DISPLAY PRINT - print sa
printer

4. DECISION - indicates logical comparison between two values. Evaluating wether the is
equal greater, or less than the second value.
=
>
NO / <
YES /
else /
TRUE
False Example x
>5
x=y
5. PREPARATION - used to define twi or more variable. Should appear only once for every
flowchart.

FYI after flow start


symbol. Not to use
twice, being used
after the start. Use
for multiple
variables.
Ex.
X= 0
Y=0
A= 0
B= 0

6. PRE DEFINE PROCESS - indicate another block of programming code giving another
programming steps.
Ex. call name of a flow chart
followed by “RETURN”. FYI. one
time call after return

Ex. TAX

START

7. ON PAGE CONNECTOR - indicates continuation of steps within a page.

Use to
continue flow
chart within
the page

8. OFF PAGE CONNECTOR - indicates continuation of steps into another page.


Used to another
page or off page to
continue. Use a
code.

9. FLOWLINE - indicate the flow of programming steps. fyi : used straight line nt curve line
when making a flow chart.

VARIABLE - is a special register that can assume a value. (a, b,c, d, etc).

3 LOGICAL STRUCTURE IN PROGRAMMING

1. Linear structure (linear sequence ex. Straight flow chart) - nothing more than the
sequential execution of programming steps.
2. Conditional / Relational / Selection Structure (result to an evaluation or w/
decision box) - refers to the branching of control depending on the result of the
evaluation.
3. Loop Structure (reiterate condition or repetitive) - refers to repetitive execution of
steps until a certain condition occurs.

DECISION STRUCTURE

VARIABLE

COUNTER / CTR - is a variable that can accept integer value. it may be incremented or
decremented with a value of 1. (fyi: meaning wlang meaning ung value, either plus 1 or minus.)
ex. Fvotectr, mvctr, ctr

PROBLEM#8
● Draw a flowchart to accept a value 7 times. Print all the value accepted.

PROBLEM # 9 (LOOP)
• Draw a flowchart to Accept a value 7 times.
• Print all the value accepted if the value accepted ranges from 5 to 10 or 20 to 30.
• Count the total no. of values printed and not printed and at the end of processing print it out.
PRTCTR, NPRTCTR.

PROBLEM # 10 (LOOP)
• Draw a flowchart to Accept a value
UNTIL the value is equal to 777.
• Print all the value accepted if the value accepted ranges from 5 to 10 or 20 to 30 or 40 to 55.
• Count the total no. of values printed and not printed and at the end of processing print it out.
PRTCTR, NPRTCTR.

SWITCH / SW - is a register from which a choice can be made. The value that it may
contain usually are “On or Off”. “On” can be represented with value of 1, and “Off” with a
value of 0.

SW - switch
RCTR - record counter
EOFSW - end of file switch
ESW - end switch
FLAGSW -

PROBLEM # 11 (SWITCH)
● Draw a flowchart to accept a value until the accepted value is 777.
● Of the value accepted do the following
Print the first value, skip the next… repeat the process.

PROBLEM # 12 (SWITCH)

● Draw a flowchart to accept a value until the accepted value is 777.


● Of the value accepted do the following
○ Print the first value, skip the next… repeat the process.
PROBLEM # 13 (SWITCH)

● Draw a flowchart to accept a value until the accepted value is 777.


● Of the value accepted do the following
○ Print the first two value, skip the next 5 … repeat the process.

ACCUMULATOR - is a register that can hold bigger values with or without decimal
places. FYI: refers to any variable but doesn’t include SW or CTR.
PROBLEM # 13 (ACCUMULATOR)

● Draw a flowchart to accept a value until the accepted value is 777.


● TWO value to be accepted; one for QUANTITY and the other for SELLING PRICE.
● Get the SALES AMOUNT by multiplying quantity with the selling price.
● Print the SALE AMOUNT only.

fyi. Double - use for numbers with decimal.

PROBLEM # 14 (ACCUMULATOR) – 4 variable


● Draw a flowchart to accept a value until the accepted value is 777.
● TWO value to be accepted; one for QUANTITY and the other for SELLING PRICE.
● Get the SALES AMOUNT by multiplying quantity with the selling price.
● Print the SALE AMOUNT if the sales amount is 5000 to 2000, or 45000 to 75000.
● ACCUMULATE - the total sales amount printed and print at the end of processing.
PROBLEM#15

Draw a flowchart to accept values for the following:


• Basic Salary; BSALARY
• Allowances; ALLOWS
• Deduction Code. DEDCODE

Based on the above input values, compute for the following:


1. Gross Pay. Where Grosspay is the sum of Basic Pay and Allowances.
2. Deductions. Where deduction is based on deduction code. If deduction code is 1, then it is
tax which is 30% of Gross, otherwise, it is philhealth and pag-ibig in the amount of 600.
3. Compute for the Net Pay, where Net Pay is equal to gross pay minus the corresponding
deduction.
4. Print the Gross, deductions, and net pay.
5. Accumulate the total Gross pay, total deductions, and total net pay and at the end of
processing print it out.

You might also like