[go: up one dir, main page]

0% found this document useful (0 votes)
73 views52 pages

CC 102 Chapter 1

This document provides an overview of the history of computers and programming languages. It discusses early calculating devices like the abacus and Pascaline. Important early computers are mentioned, such as the Analytical Engine, Mark I, and ENIAC. The development of programming languages is also summarized, including some of the earliest such as Ada Lovelace's algorithm for the Analytical Engine, assembly language, Fortran, Algol, COBOL, LISP, BASIC, and Pascal. The document is presented as class material on the fundamentals of programming.

Uploaded by

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

CC 102 Chapter 1

This document provides an overview of the history of computers and programming languages. It discusses early calculating devices like the abacus and Pascaline. Important early computers are mentioned, such as the Analytical Engine, Mark I, and ENIAC. The development of programming languages is also summarized, including some of the earliest such as Ada Lovelace's algorithm for the Analytical Engine, assembly language, Fortran, Algol, COBOL, LISP, BASIC, and Pascal. The document is presented as class material on the fundamentals of programming.

Uploaded by

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

09/10/2022

Prepared by Joshua C. Reyes

Information Technology Department


College of Computing

Pangasinan State University • Urdaneta City Campus

Prepared by Joshua C. Reyes

CHAPTER
1
CC 102 Fundamentals of Programming

OVERVIEW OF
COMPUTER
AND PROGRAMMING
Part 1: Computer and
Programming Languages

1
09/10/2022

Prepared by Joshua C. Reyes

CHAPTER
1 Topic Outline
• Introduction
CC
HCI
102 Fundamentals
101 Human Computer
of Programming
Interaction 1

OVERVIEW OF • History of Computer and Programming


Languages
COMPUTER • Elements of a Computer System
• The Language of a Computer
AND PROGRAMMING • The Evolution of Programming
Languages
Part 1: Computer and • Programming Methodologies

Programming Languages

Prepared by Joshua C. Reyes

1.1.1 Introduction

What is the first thing that


comes to your mind when
you hear the terms:
information technology?
Internet Computer Application

2
09/10/2022

Prepared by Joshua C. Reyes

1.1.2 History of Computer and Programming Languages

History of Computer

Abacus
The first device known to carry out
calculations – addition and
subtraction.

300 BC, Babylonian


500 BC, Chinese

Prepared by Joshua C. Reyes

1.1.2 History of Computer and Programming Languages

History of Computer

Pascaline
It is a mechanical calculator capable
of performing addition and
subtraction.

1642, Blaise Pascal

3
09/10/2022

Prepared by Joshua C. Reyes

1.1.2 History of Computer and Programming Languages

History of Computer

Step Reckoner
It is a device that was able to add,
subtract, multiply, and divide.

17th Century, Gottfried von Leibniz

Prepared by Joshua C. Reyes

1.1.2 History of Computer and Programming Languages

History of Computer

Jacquard Loom
It is a machine developed that used a
series of punch cards to control
weave operations.

1819, Joseph Jacquard

4
09/10/2022

Prepared by Joshua C. Reyes

1.1.2 History of Computer and Programming Languages

History of Computer

Difference Engine
It is an automatic mechanical
calculator designed to tabulate
polynomial functions.

1820, Charles Babbage

Prepared by Joshua C. Reyes

1.1.2 History of Computer and Programming Languages

History of Computer

Analytical Engine
It is a general-purpose, fully program-
controlled, automatic mechanical
digital computer.

1837, Charles Babbage

5
09/10/2022

Prepared by Joshua C. Reyes

1.1.2 History of Computer and Programming Languages

History of Computer

Punched Card Tabulator


It is a punch-card tabulation machine
system that was able to collect and
count data more rapidly and
accurately than manual processes
had allowed in the past.

1884, Herman Hollerith

Prepared by Joshua C. Reyes

1.1.2 History of Computer and Programming Languages

History of Computer

Mark I
It is the first computer-like machine; A
programmable, electromechanical
calculator.

1944, Howard Aiken (with IBM and


Harvard University

6
09/10/2022

Prepared by Joshua C. Reyes

1.1.2 History of Computer and Programming Languages

History of Computer

Electronic Numerical Integrator


and Computer (ENIAC)
It was the first programmable
general-purpose electronic digital
computer.

1945, United States

Prepared by Joshua C. Reyes

1.1.2 History of Computer and Programming Languages

History of Computer

Von Neumann Architecture


It is a computer architecture being
used in the computers that we know
today.

1945, John von Neumann

7
09/10/2022

Prepared by Joshua C. Reyes

1.1.2 History of Computer and Programming Languages

History of Programming Languages

Algorithm for the Assembly Language Autocode


Analytical Engine 1949, Kathleen Booth 1952, Alick Glennie
1883, Ada Lovelace

Prepared by Joshua C. Reyes

1.1.2 History of Computer and Programming Languages

History of Programming Languages

Fortran (Formula Translation) Algol (Algorithmic Language) COBOL (Common Business


1957, John Backus 1958, Committee of American & Oriented Language)
European Computer Scientists 1959, Dr. Grace Murray Hopper

8
09/10/2022

Prepared by Joshua C. Reyes

1.1.2 History of Computer and Programming Languages

History of Programming Languages

LISP (List Processing BASIC (Beginner’s All-purpose Pascal


language) Symbolic Instruction Code) 1970, Niklaus Wirth
1959, John McCarthy 1964, J.G. Kemeny, T. E. Kurtz

Prepared by Joshua C. Reyes

1.1.2 History of Computer and Programming Languages

History of Programming Languages

Smalltalk C SQL (Structured Query


1972, Alan Kay, Adele Goldberg 1972, Dennis Ritchie Language) 1972, Donald D.
Dan Ingalls Chamberlin, Raymond F. Boyce

9
09/10/2022

Prepared by Joshua C. Reyes

1.1.2 History of Computer and Programming Languages

History of Programming Languages

MATLAB (Matrix Laboratory) Objective-C C++


1978, Cleve Moler 1983, Brad Cox, Tom Love 1983, Bjarne Stroustrup

Prepared by Joshua C. Reyes

1.1.2 History of Computer and Programming Languages

History of Programming Languages

Perl Haskell Python


1987, Larry Wall 1990, Philip Wadler, 1991, Guido Van Rossum
Stephen Blott

10
09/10/2022

Prepared by Joshua C. Reyes

1.1.2 History of Computer and Programming Languages

History of Programming Languages

Visual Basic R Java


1991, Microsoft 1993, Ross Ihaka 1995, Sun Microsystems
Robert Gentleman

Prepared by Joshua C. Reyes

1.1.2 History of Computer and Programming Languages

History of Programming Languages

PHP (Personal Home Page) Ruby JavaScript


1995, Rasmus Lerdorf 1995, Yukihiro “Matz” Matsumoto 1995, Brendan Eich

11
09/10/2022

Prepared by Joshua C. Reyes

1.1.2 History of Computer and Programming Languages

History of Programming Languages

C# Scala Groovy
2000, Microsoft 2003, Martin Odersky 2003, James Strachan,
Bob McWhirter

Prepared by Joshua C. Reyes

1.1.2 History of Computer and Programming Languages

History of Programming Languages

Go Swift
2009, Google 2014, Apple

12
09/10/2022

Prepared by Joshua C. Reyes

1.1.3 Elements of a Computer System

Computer System
• A computer is an electronic device capable of performing commands.

• The basic commands that a computer performs are:


• input (get data),
• output (display result),
• storage, and
• performance of arithmetic and logical operations.

• There are three main classes of computers: (1) personal computer, (2)
workstation, and (3) mainframe.

• There are two main components of a computer system: hardware and software.

Prepared by Joshua C. Reyes

1.1.3 Elements of a Computer System Hardware

Central Processing Unit Main Memory

13
09/10/2022

Prepared by Joshua C. Reyes

1.1.3 Elements of a Computer System Hardware

Secondary Storage Input/Output Devices

Prepared by Joshua C. Reyes

1.1.3 Elements of a Computer System Software

System Programs Application Programs

14
09/10/2022

Prepared by Joshua C. Reyes

1.1.4 The Language of a Computer

Analog Signal vs Digital Signals

Analog Digital

A continuous signal which Discrete time signals generated by


Signal
represents physical measurements digital modulation

Human voice in air, analog Computers, CDs, DVDs, and other


Example
electronic devices digital electronic devices

Memory Stored in the form of wave signal Stored in the form of binary bit

Prepared by Joshua C. Reyes

1.1.4 The Language of a Computer

Binary Digit and Binary Number


• The digit 0 or 1 is called a binary digit, or bit.

• Sometimes a sequence of 0s and 1s is referred to as a binary code or a


binary number (e.g., 1001, 0011, 1010).

• A sequence of eight bits is called a byte (e.g., 10011001).

15
09/10/2022

Prepared by Joshua C. Reyes

1.1.4 The Language of a Computer

Binary Digit and Binary Number


Unit Symbol Bits/Bytes
Byte 8 bits
Kilobyte KB 1024 bytes
Megabyte MB 1,048,576 bytes
Gigabyte GB 1,073,741,824 bytes
Terabyte TB 1,099,511,627,776 bytes
Petabyte PB 1,125,899,906,842,624 bytes
Exabyte EB 1,152,921,504,606,846,976 bytes
Zettabyte ZB 1,180,591,620,717,411,303,424 bytes

Prepared by Joshua C. Reyes

1.1.4 The Language of a Computer

American Standard Code for Information Interchange (ASCII)

16
09/10/2022

Prepared by Joshua C. Reyes

1.1.5 The Evolution of Programming Languages

• A programming language is a computer language programmers use to develop


software programs, scripts, or other sets of instructions for computers to execute.

• The most basic language of a computer, the machine language, provides program
instructions in bits. Early computers were programmed in machine language.

Equation to calculate weekly wages Machine Language

wages = rate * hours 100100 010001


100110 010010
100010 010011

Prepared by Joshua C. Reyes

1.1.5 The Evolution of Programming Languages

• Assembly languages were developed to make the programmer’s job easier. In


assembly language, an instruction is an easy-to-remember form called a
mnemonic.

Equation to calculate Machine Language Assembly Language


weekly wages
100100 010001 LOAD rate
wages = rate * hours 100110 010010 MULT hours
100010 010011 STOR wages

• Assembler: A program that translates a program written in assembly language into


an equivalent program in machine language.

17
09/10/2022

Prepared by Joshua C. Reyes

1.1.5 The Evolution of Programming Languages

• The next step toward making programming easier was to devise high-level
languages that were closer to natural languages, such as English, etc.

Equation to calculate Assembly Language High-Level Language (C++)


weekly wages
LOAD rate wages = rate * hours;
wages = rate * hours MULT hours
STOR wages

• Compiler: A program that translates instructions written in a high-level language


into the equivalent machine language

Prepared by Joshua C. Reyes

1.1.5 The Evolution of Programming Languages

Compiler Interpreter

A compiler translates the entire source An interpreter translates the entire


code in a single run. source code line by line.

The compiler is used by the language An interpreter is used by languages


such as C, C++. such as Java, Ruby, and Python.

18
09/10/2022

Prepared by Joshua C. Reyes

1.1.5 The Evolution of Programming Languages

First Generation Machine Language 01101001

Second Generation Assembly Language ADD X Y Z

C, C++, Java, Visual Basic,


Third Generation Procedural Language
and JavaScript

Perl, PHP, Python, Ruby, and


Fourth Generation Non-Procedural Language
SQL

Natural Language Programming


Fifth Generation Mercury, OPS5, and Prolog
Language (Artificial Intelligence Language)

Prepared by Joshua C. Reyes

1.1.5 The Evolution of Programming Languages

19
09/10/2022

Prepared by Joshua C. Reyes

1.1.6 Programming Methodologies

1. Structured Programming. Dividing a problem into smaller subproblems is


called structured design. Each subproblem is then analyzed, and a solution
is obtained to solve the subproblem. The solutions to all of the subproblems
are then combined to solve the overall problem.

2. Object-oriented design (OOD) is a widely used programming methodology.


In OOD, the first step in the problem-solving process is to identify the
components called objects, which form the basis of the solution, and to
determine how these objects interact with one another.

Prepared by Joshua C. Reyes

Any question that


you want to ask?

CC 102 Fundamentals of Programming

20
09/10/2022

Prepared by Joshua C. Reyes

CHAPTER
1
CC 102 Fundamentals of Programming

OVERVIEW OF
COMPUTER
AND PROGRAMMING
Part 2: Programming Tools

Prepared by Joshua C. Reyes

CHAPTER
1 Topic Outline
• Introduction
CC 102 Fundamentals of Programming

OVERVIEW OF •

Dev C++
CodeBlocks
COMPUTER •

CxxDroid/CppCode
Coding Rooms
AND PROGRAMMING
Part 2: Programming Tools

21
09/10/2022

Prepared by Joshua C. Reyes

2.1.1 Introduction to IDE

Integrated Development Environment (IDE)


• It is a software suite that consolidates basic tools required to write and
test software. It is a software for building applications that combines
common developer tools into a single graphical user interface (GUI).

• C++ IDE (Integrated Development Environment) is a completely self-


contained environment for creating, compiling, linking and testing C++
programs. It incorporates a range of fully integrated tools designed to make
the whole process of writing C++ programs easy.

Prepared by Joshua C. Reyes

2.1.1 Introduction to IDE

C++ IDE (Integrated Development Environment)

22
09/10/2022

Prepared by Joshua C. Reyes

2.2.1 Dev C++ Overview

Dev-C++, developed by Bloodshed


Software, is a fully-featured graphical IDE
(Integrated Development Environment) for
C and C++ programming. It is distributed
under the GNU General Public License for
programming in C and C++.

Prepared by Joshua C. Reyes

2.2.2 Dev C++ Installation

Step 1 First you must download the Dev C++ on your Windows machine. Visit
to Download Dev C++: http://www.bloodshed.net

Step 2 There are packages for different Operating Systems.


Step 3 Under package Dev-C++ 5.0 (4.9.9.2) with Mingw/GCC 3.4.2 compiler
and GDB 5.2.1 debugger (9.0 MB) Click on the link “Download from
SourceForge”.

Step 4 This package will download C++ .exe file for Windows that can be used
to install on Windows 7/8/XP/Vista/10.

23
09/10/2022

Prepared by Joshua C. Reyes

2.2.2 Dev C++ Installation

Step 5 You will direct to SourceForge website, and your C++ download will start
automatically.

5.1 Click on save button to save. By default, it is saved in “Downloads”


folder.
5.2 After the download completes, go to the saved .exe file and click on
it to Run.
5.3 The installer will ask you a language to select. Select “English” and
click on “OK”.
5.4 Then screen for license agreement will appear. Click on “I agree” to
proceed further.

Prepared by Joshua C. Reyes

2.2.2 Dev C++ Installation

Step 6 In this step, you can see different components of Dev C++ that will be
installed with this package. Just click on “next” button.

Step 7 In this step, by default, the destination folder is in C drive. You are free
to change this destination folder but make sure you have enough
memory. Click on “Install” button.

7.1 In the next screen, installation begins.


7.2 Now, Dev C++ is installed successfully on your Windows.
Select ” Run Dev C++” to run it and click on ” Finish” button.

24
09/10/2022

Prepared by Joshua C. Reyes

2.2.3 Dev C++ Interface

Menu bar

Toolbars

Project manager pane

Report pane

Code editor

Status bar

Prepared by Joshua C. Reyes

2.2.3 Dev C++ Interface

25
09/10/2022

Prepared by Joshua C. Reyes

2.3.1 CodeBlocks Overview

CodeBlocks is an open-source, cross-


platform (Windows, Linux, MacOS), and free
C/C++ IDE. It supports many compilers, such
as GNU GCC (MinGW and Cygwin) and MS
Visual C++. It supports interactive debugging
(via GNU GDB or MS CDB).

CodeBlocks is surprisingly versatile, and in


my opinion, much better than the Visual
Studio suite. The mother site of CodeBlocks
is www.codeblocks.org.

Prepared by Joshua C. Reyes

2.3.2 CodeBlocks Installation

Step 1 Visit codeblocks.org. Click Download from the menu, then click on
download the binary release.
Step 2 Go to your operating platform section (e.g., Windows XP / Vista / 7 / 8.x /
10), then download the installer with GCC Compiler, e.g., codeblocks-
17.12mingw-setup.exe or Click here to download.
Step 3 Double-click to run the downloaded installer and click Next on the pop-
up window. Now click on “I Agree” to accept the license agreement.
Step 4 On the new pop-up, don’t do anything, just click Next and then change
the installation directory if you want (default directory recommended).
Click Install.

26
09/10/2022

Prepared by Joshua C. Reyes

2.3.2 CodeBlocks Installation

Step 5 Wait for a minute for installation to complete. A new pop-up asks you to
run Codeblocks. Click YES, and then it shows the compiler Codeblocks
detected. Click OK.
Step 6 Now we have installed Codeblocks on windows.
Step 7 We need to verify the Compiler and Debugger path (this step is
optional).

Go to menu options and click on Settings >> Compiler. In the selected


compiler, by default, it shows GNU GCC Compiler. Now select the
“Toolchain Executables” tab from the below tabs and check the
Compiler’s Installation Directory is set to “C:\Program
Files\codeblocks\MinGW.

Prepared by Joshua C. Reyes

2.3.2 CodeBlocks Installation

Step 8 Similarly, for debugger path: Settings >> Debugger >> GDB/CDB
debugger >> Default. In Executable, the path should be C:\Program
Files\codeblocks\MinGW\bin\gdb.exe or C:\MinGW\bin\gdb.exe if you
have installed MinGW compiler before installing Codeblocks.

27
09/10/2022

Prepared by Joshua C. Reyes

2.3.3 CodeBlocks Interface

Menu bar

Toolbars

Management

Editor

Editor tab

Logs and others

Status bar

Prepared by Joshua C. Reyes

2.3.3 CodeBlocks Interface

28
09/10/2022

Prepared by Joshua C. Reyes

2.4.1 CxxDroid (Android) / CppCode (iOS) Overview

CppCode is an awesome offline C/C++ IDE


and compiler for iOS platform. Using this you
can easily write and run C/C+ code even on
your iPhone or iPad.

This is a recently launched iOS app which is


available for free on iTunes. CppCode is
same as CxxDroid which is a free C/C++ IDE
for android.

Prepared by Joshua C. Reyes

2.4.2 CxxDroid (Android) / CppCode (iOS) Installation

Step 1 CxxDroid / CppCode – C++ compiler IDE for mobile development app
available on Play Store / App Store. So search and find it.
Step 2 Choose install option under the CxxDroid / CppCode – C++ compiler
IDE for mobile development logo, and enjoy!

29
09/10/2022

Prepared by Joshua C. Reyes

2.4.3 CxxDroid (Android) / CppCode (iOS) Interface

Prepared by Joshua C. Reyes

2.5.1 Coding Rooms Overview

The first real-time platform for teaching


programming online and in-person that
enables you to connect with each student,
see their work, and engage with their code
instantly.

30
09/10/2022

Prepared by Joshua C. Reyes

2.5.2 Coding Rooms Installation

Step 1 Go to the official website of Coding Rooms using the link:


www.codingrooms.com
Step 2 Click on the “Sign up” button from the menu.
Step 3 Enter a valid email address and strong password. Then, click the “Sign
up” button.
Step 4 You will be asked whether you are a student or a teacher. Select “I’m a
student.”

Prepared by Joshua C. Reyes

2.5.2 Coding Rooms Installation

Step 5 You will be asked to give your first name and last name. Answer
correctly then, click the “Finish” button.
Step 6 You will be redirected to the main page of the website called learner
dashboard.
Step 7 Go to the “Workspaces” tab.
Step 8 Create “+ New Workspace” using the following credentials:
Title: Code Block: Lastname, First Name, MI (Sample: CC102 IT1A:
Reyes, Joshua C.)
Code Language: C++ Next (Latest; CR2)
Enable Workspace V2: ON

6.1 Once done, click the “Create workspace” button.

31
09/10/2022

Prepared by Joshua C. Reyes

2.5.2 Coding Rooms Installation

Step 9 You will be redirected to your workspace.


Step 10 Share your workspace with your instructor by clicking the “Share” button
and providing the email address of your instructor: jreyes@psu.edu.ph.
Once entered, change the Role from “Viewer” to “Editor”. Then, click the
“Invite” button.
Step 11 Once done, create the following folders on your “Files” section: Quizzes,
Exams, Activities, Case Studies, Projects

Prepared by Joshua C. Reyes

2.5.2 Coding Rooms Installation

Step 12 You can create cpp files by clicking first the folder where you want to
save the file then click the (+) icon.

12.1 Always rename the file using the format:


LASTNAME_CC102TaskCode#-Prob#.cpp

12.2 Once organized, you are now ready for the course. For further
instructions and tips on using the coding rooms, kindly wait for your
instructor to give them.

32
09/10/2022

Prepared by Joshua C. Reyes

2.5.2 Coding Rooms Interface

Prepared by Joshua C. Reyes

Any question that


you want to ask?

CC 102 Fundamentals of Programming

33
09/10/2022

Prepared by Joshua C. Reyes

CHAPTER
1
CC 102 Fundamentals of Programming

OVERVIEW OF
COMPUTER
AND PROGRAMMING
Part 3: Problem Solving

Prepared by Joshua C. Reyes

CHAPTER
1 Topic Outline
• Basic Steps
CC 102in Problem Solving
Fundamentals of Programming

OVERVIEW OF •

Structured Programming
Flowchart
COMPUTER • Pseudocode

AND PROGRAMMING
Part 3: Problem Solving

34
09/10/2022

Prepared by Joshua C. Reyes

3.1.1 Introduction

• Programming is a process of problem solving.

• To be a good problem solver and a good programmer, you must follow


good problem-solving techniques. One common problem-solving
technique includes analyzing a problem, outlining the problem
requirements, and designing steps, called an algorithm, to solve the
problem.

• Problem solving is the act of defining a problem; analyzing the problem;


selecting alternatives for a solution; and implementing a solution. In the
context of programming, basic steps in problem solving are problem
definition, problem analysis and algorithm design.

Prepared by Joshua C. Reyes

3.1.2 Basic Steps in Problem Solving

Problem Definition
• Defining the problem involves understanding it and being able to state it.

Problem 1

Statement of the Problem Write a program to determine the sum of two numbers.

Definitive Statement of the Give the computer two numbers. It should be able to
Problem add the two numbers and give the result.

35
09/10/2022

Prepared by Joshua C. Reyes

3.1.2 Basic Steps in Problem Solving

Problem Definition

Problem 2

Statement of the Problem Write a program that will compute the area of a circle.

Definitive Statement of the


Problem

Prepared by Joshua C. Reyes

3.1.2 Basic Steps in Problem Solving

Problem Definition

Problem 2

Statement of the Problem Write a program that will compute the area of a circle.

Definitive Statement of the Give the computer the values of pi and radius. It should
Problem be able to square the radius then multiply by pi to get
the area of the circle.

36
09/10/2022

Prepared by Joshua C. Reyes

3.1.2 Basic Steps in Problem Solving

Problem Analysis
• Analyzing the problem involves identifying the nature, scope, input, output, and the
process.

Problem 1
Statement of the Problem Write a program to determine the sum of two numbers.
Definitive Statement of the Give the computer two numbers. It should be able to
Problem add the two numbers and give the result.

Nature Algebra
Scope Integer or whole numbers only

Prepared by Joshua C. Reyes

3.1.2 Basic Steps in Problem Solving

Problem Analysis

Problem 2

Statement of the Problem Write a program that will compute the area of a circle.

Definitive Statement of the Give the computer the values of pi and radius. It should
Problem be able to square the radius then multiply by pi to get
the area of the circle.

Nature

Scope

37
09/10/2022

Prepared by Joshua C. Reyes

3.1.2 Basic Steps in Problem Solving

Problem Analysis

Problem 2
Statement of the Problem Write a program that will compute the area of a circle.
Definitive Statement of the Give the computer the values of pi and radius. It should
Problem be able to square the radius then multiply by pi to get
the area of the circle.
Nature Geometry
Scope Fractions or decimals are accepted values. No negative
values for the radius should be accepted.

Prepared by Joshua C. Reyes

3.1.2 Basic Steps in Problem Solving

Problem Analysis

Problem 1
Statement of the Problem Write a program to determine the sum of two numbers.
Definitive Statement of the Give the computer two numbers. It should be able to
Problem add the two numbers and give the result.

Nature Algebra
Scope Integer or whole numbers only
Input Two (2) integer numbers
Output The sum of the two numbers

38
09/10/2022

Prepared by Joshua C. Reyes

3.1.2 Basic Steps in Problem Solving

Problem Analysis

Problem 2
Statement of the Problem Write a program that will compute the area of a circle.
Definitive Statement of the Give the computer the values of pi and radius. It should
Problem be able to square the radius then multiply by pi to get
the area of the circle.
Nature Geometry
Scope Fractions or decimals are accepted values. No negative
values for the radius should be accepted.
Input
Output

Prepared by Joshua C. Reyes

3.1.2 Basic Steps in Problem Solving

Problem Analysis

Problem 2
Statement of the Problem Write a program that will compute the area of a circle.
Definitive Statement of the Give the computer the values of pi and radius. It should
Problem be able to square the radius then multiply by pi to get
the area of the circle.
Nature Geometry
Scope Fractions or decimals are accepted values. No negative
values for the radius should be accepted.
Input The values of pi and radius
Output The area of the circle

39
09/10/2022

Prepared by Joshua C. Reyes

3.1.2 Basic Steps in Problem Solving

Problem Analysis

Problem 1
Statement of the Problem Write a program to determine the sum of two numbers.
Definitive Statement of the Give the computer two numbers. It should be able to
Problem add the two numbers and give the result.
Process Enter two numbers using the keyboard. The computer
must be able to reject fractions and decimal numbers.
The computer will then add the two numbers. The result
of the addition will be displayed on the computer
screen.

Prepared by Joshua C. Reyes

3.1.2 Basic Steps in Problem Solving

Problem Analysis

Problem 2
Statement of the Problem Write a program that will compute the area of a circle.
Definitive Statement of the Give the computer the values of pi and radius. It should
Problem be able to square the radius then multiply by pi to get
the area of the circle.
Nature Geometry
Scope Fractions or decimals are accepted values. No negative
values for the radius should be accepted.
Input The values of pi and radius.
Output The area of the circle.
Process

40
09/10/2022

Prepared by Joshua C. Reyes

3.1.2 Basic Steps in Problem Solving

Problem Analysis

Problem 2

Statement of the Problem Write a program that will compute the area of a circle.

Definitive Statement of the Give the computer the values of pi and radius. It should
Problem be able to square the radius then multiply by pi to get
the area of the circle.

Process Enter the values of pi and radius. The computer must be


able to accept fractions and decimal numbers. No
negative values must be accepted. The computer must
square the radius and multiply it by pi to get a result.
The result (area of the circle) will be displayed on
screen.

Prepared by Joshua C. Reyes

3.1.2 Basic Steps in Problem Solving

Algorithm Design
• Algorithm is a set of rules for solving a problem in a finite number of steps.

• In the context of computer programming, an algorithm, is defined as a: “well-


ordered collection of unambiguous and effectively computable
operations, that when executed, produces a result and halts in a finite amount
of time.”

• An algorithm can be represented using a flowchart or pseudocode.

41
09/10/2022

Prepared by Joshua C. Reyes

3.1.2 Basic Steps in Problem Solving

Algorithm Design

STEPS IN COOKING SCRAMBLED EGG

Prepare all necessary items needed (egg, pan, oil etc.)


Beat the egg
Add salt
Heat pan
Put oil into the pan
Pour beaten egg if pan is already hot enough
Cook egg for at least two minutes
Serve egg

Prepared by Joshua C. Reyes

3.2.1 Structured Programming

Definition
• It is a technique that emphasizes the breaking of a program or algorithm into logical
sections, or modules following a universal programming standard. (breaking of
programs into smaller modules)

• Also called modular programming.

• An algorithm is composed of control structures – a step, or a series of steps, that


determines what instructions or set of instructions will be done next, to solve a
problem.

• There are three control structures: Sequence, Selection, and Repetition.

42
09/10/2022

Prepared by Joshua C. Reyes

3.2.2 Structured Programming

Structured Programming Constructions: Sequence

• The sequence structure is the construct where one


statement is executed after another. It is the most
straight forward.

• The program will just follow the instructions one after


the other in a sequential manner.

Prepared by Joshua C. Reyes

3.2.2 Structured Programming

Structured Programming Constructions: Sequence

43
09/10/2022

Prepared by Joshua C. Reyes

3.2.2 Structured Programming

Structured Programming Constructions: Selection

• The selection structure is the construct where statements can be executed or


skipped depending on whether a condition evaluates to TRUE or FALSE. There are
three selection structures: IF, IF – ELSE, and SWITCH.

• Let your program or algorithm make a decision. Choose one from two sets of
instructions depending on the condition. IF (condition) THEN (Process 1) ELSE
(Process 2).

Prepared by Joshua C. Reyes

3.2.2 Structured Programming

Structured Programming Constructions: Selection

44
09/10/2022

Prepared by Joshua C. Reyes

3.2.2 Structured Programming

Structured Programming Constructions: Repetition

• The repetition structure is the construct


where statements can be executed repeatedly
until a condition evaluates to TRUE or FALSE.
There are three repetition structures: WHILE,
DO – WHILE, and FOR.

• We use when we want our algorithm or


program to repeat a process a specified
number of times.

• The structure that repeats an instruction or a


set of instructions until a condition is met is
known as iteration or loop.

Prepared by Joshua C. Reyes

3.2.2 Structured Programming

Structured Programming Constructions: Repetition

45
09/10/2022

Prepared by Joshua C. Reyes

3.3.1 Flowchart

Definition

• It is a graphical tool that diagrammatically depicts the steps and structure of an


algorithm or program.

• It is one method of pictorially representing a procedural (step-by-step) solution to a


problem before you actually start to write the computer instructions required to
produce the desired results.

• There are two types of flowcharts:


• System (data) flowcharts. Defines the major phases of the processing, as well
as the various data media used.
• Programming flowcharts.

Prepared by Joshua C. Reyes

3.3.2 Flowchart

Flowcharting Symbols

46
09/10/2022

Prepared by Joshua C. Reyes

3.3.3 Flowchart

Examples of Flowcharts

Problem 1: Write a program


to determine the sum of two
numbers

Prepared by Joshua C. Reyes

3.3.3 Flowchart

Examples of Flowcharts

47
09/10/2022

Prepared by Joshua C. Reyes

3.3.3 Flowchart

Examples of Flowcharts

Prepared by Joshua C. Reyes

3.4.1-2 Pseudocode

Definition and Pseudocode Language Constructs

• Pseudocode is an artificial and informal language that helps programmers develop


algorithms. Pseudocode is a "text-based" detail (algorithmic) design tool.

NOTATION USE OTHER NOTATIONS USED


INPUT Used when reading or entering data in any READ, ENTER
of the input devices.
OUTPUT Used when we wish a value to be WRITE, DISPLAY, PRINT
displayed.
BEGIN Marks the start of a pseudocode. START
END Marks the end of a pseudocode. STOP, HALT

48
09/10/2022

Prepared by Joshua C. Reyes

3.4.3 Pseudocode

Pseudocode Example

Problem 1
Statement of the Problem Write a program to determine the sum of two numbers.
Pseudocode BEGIN
INPUT the first number
INPUT the second number
Add the two numbers
OUTPUT the sum
END

Prepared by Joshua C. Reyes

CHAPTER
1
CC 102 Fundamentals of Programming

OVERVIEW OF
COMPUTER
AND PROGRAMMING
Part 4: Coding and Debugging

49
09/10/2022

Prepared by Joshua C. Reyes

CHAPTER
1 Topic Outline
• Introduction
CC 102 Fundamentals of Programming

OVERVIEW OF • Coding
• Debugging
COMPUTER
AND PROGRAMMING
Part 4: Coding and Debugging

Prepared by Joshua C. Reyes

4.1.1 Introduction

• Once you have designed the algorithm and verified its correctness, the next step is to
convert it into an equivalent programming code. You then use a text editor to
enter the programming code or the program into a computer.

• Next, you must make sure that the program follows the language’s syntax. To
verify the correctness of the syntax, you run the code through a compiler.

• If the compiler generates error messages, you must identify the errors in the
code, remove them, and then run the code through the compiler again. When
all the syntax errors are removed, the compiler generates the equivalent machine
code, the linker links the machine code with the system’s resources, and the loader
places the program into main memory so that it can be executed.

• The final step is to execute the program.

50
09/10/2022

Prepared by Joshua C. Reyes

4.2.1 Coding

Problem 1
Statement of the Write a program to determine the sum of two numbers.
Problem

Pseudocode Equivalent C++ Statements


BEGIN
INPUT the first number cin >> num1;
INPUT the second number cin >> num2;
Add the two numbers sum = num1 + num2;
OUTPUT the sum cout << sum;
END

Prepared by Joshua C. Reyes

4.2.1 Debugging

Definition

• Bug it the program contains a defect in the source code, either


due to a design misunderstanding or an implementation mistake.

• Debugging is a methodical process of finding and reducing the


number of bugs (or defects) in a computer program, thus making
it behave as originally expected.

51
09/10/2022

Prepared by Joshua C. Reyes

4.2.1 Debugging

Kinds of Errors

Syntax Error

Run-Time Error

Linker Error

Logical Error

Semantic Error

Prepared by Joshua C. Reyes

Any question that


you want to ask?

CC 102 Fundamentals of Programming

52

You might also like