[go: up one dir, main page]

0% found this document useful (0 votes)
2 views37 pages

Cos Merged

The document provides an introduction to computer programming, emphasizing its importance in problem-solving across various fields. It outlines the programming process, including writing, testing, and debugging code, and discusses the significance of algorithms and flowcharts in structuring solutions. Additionally, it highlights the problem-solving process through practical examples, such as planning a birthday party and preparing for school resumption.

Uploaded by

tdg1lawxv
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)
2 views37 pages

Cos Merged

The document provides an introduction to computer programming, emphasizing its importance in problem-solving across various fields. It outlines the programming process, including writing, testing, and debugging code, and discusses the significance of algorithms and flowcharts in structuring solutions. Additionally, it highlights the problem-solving process through practical examples, such as planning a birthday party and preparing for school resumption.

Uploaded by

tdg1lawxv
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/ 37

COS 201

Computer Programming I
Module 1:Introduction to Computer
Programming
Introduction
 Computers are used for various tasks in various settings,
such as school, work, and home. Creating applications to
run these tasks
 How do we make these applications to handle these tasks?
 We program these apps to perform diverse functions
through software created by programmers and developers.
 A programmer, or software developer, is a person with the
training and skills necessary to design, create, and test
computer programs.
 Computer programming is an important and versatile
career employed across many industries and fields.
 In this course we will be learning how this application are
Computer Programming
 A program is a set of instructions that tells the computer what to do.
 Computer programming (often shortened or coding), is the process of;
 writing, testing, debugging/troubleshooting and maintaining instructions
(source code) for solving a problem with the computer.
 A source code is written in an acceptable computer programming
language. (C++, Java, Python etc.)
 The purpose of programming is to create a program that exhibits a
certain described behaviour (customization).
 The process of writing source code requires expertise in many
different subjects, including knowledge of the application domain.
What is Programming
 Programming is the craft of transforming requirements
into something that a computer can execute.
 It is also the process of creating a set of instructions
(called a program) that tells a computer how to perform a
task. It involves:
 Writing precise, step-by-step commands
 Using specific programming languages that the computer can
understand
 Converting human thoughts and solutions into machine-executable
format (Coding)
Why Programming Matters
An essential skill for problem-solving
 programming is a fundamental tool for problem-solving, as
it allows for;
 The development of analytical and logical thinking,
The automation of tasks,
The modelling and simulation of scenarios,
The manipulation and analysis of data,
The rapid prototyping of solutions,
These capabilities make programming an essential skill
for effective problem-solving in a wide range of
domains.
Key Ways Programming Contributes To
Problem-Solving
 Algorithmic Thinking: Programming requires the ability to break
down complex problems into a series of logical steps or
algorithms. This helps develop analytical and problem-solving
skills
 Automation: Programming allows for the automation of
repetitive or tedious tasks, freeing up time and resources to
focus on more complex problem-solving.

 Modeling and Simulation: Programming enables the creation of


models and simulations to test hypotheses, explore scenarios,
and experiment with potential solutions without the risks or
constraints of the real world..
Key Ways Programming Contributes To
Problem-Solving
 Data Manipulation and Analysis: Programming provides the
tools to collect, organize, and analyze data, which is crucial for
identifying patterns, trends, and insights that can inform problem-
solving approaches.
 Rapid Prototyping: The iterative nature of programming allows
for the rapid development and testing of solutions, enabling quick
feedback and the ability to iterate on ideas.
Key Ways Programming Contributes To
Problem-Solving
 Scalability and Adaptability: Well-designed programs can
be easily scaled and adapted to handle larger or more
complex problems, making them a valuable tool for
problem-solving.
 Collaboration and Communication: Programming often
involves working with teams, which fosters collaboration,
communication, and the sharing of diverse perspectives to
tackle complex problems.
The Problem-Solving Process
The Problem-Solving Process

 Problem Identification: Understanding what needs to be


solved, Identifying inputs and required outputs and determining
constraints and requirements
 Problem Analysis: Breaking down complex problems into
smaller parts, identifying patterns and relationships and
determining necessary resources
 Solution Design: Creating algorithms to solve the problem,
planning data structures and Designing user interfaces (if
needed)
 Implementation: Writing the actual code, Testing and debugging
and Optimizing performance
Example: Planning a Birthday Party
 Problem Identification
 Understanding what needs to be solved: You want to plan a fun birthday party.
 Identifying inputs and required outputs: You need to know how many guests are
coming, what food and drinks to provide, and what activities/entertainment you
should include.
 Determining constraints and requirements: You have a limited budget, a small venue,
and a specific date and time.
 Problem Analysis
 Breaking down complex problems into smaller parts:
 List the tasks: sending invitations, ordering food, buying decorations, planning
games, etc.
 Identifying patterns and relationships: Figure out how many guests will attend which
helps dictate the amount of food and drinks needed.
 Determining necessary resources: Determine what you need to buy (cake, drinks,
decorations) and who can help (friends, family).
Planning a Birthday Party
 Solution Design
 Creating algorithms: Outline steps for each task, like:
 Create a guest list, Send invitations, Confirm attendance, and Order food based
on headcount.
 Planning data structures: Create a simple spreadsheet to keep track of guest
RSVPs and budgets.
 Designing user interfaces: If you're using an online invitation service, design the
page to be easy to navigate for your guests.
 Implementation
 Writing the actual code: Not literally code here, but putting your plan into action
—send invitations, order food, buy decorations.
 Testing and debugging: Check if guests received invitations, adjust if food order
is too small or too large based on RSVPs.
 Optimizing performance: If the budget allows, consider things like double-
checking supplies to avoid last-minute rushes or tweaking the game schedule
based on what works well previously.
Class work

Planning my resumption
Using the Problem-Solving Process, to help solve this
problem of a student preparing for school resumption
after a break.
Example: Planning for school resumption
 Problem Identification
 Understanding what needs to be solved: The student needs to
get ready for school.
 Identifying inputs and required outputs: The student needs school
supplies (notebooks, pens, textbooks), a schedule for classes, and
potentially new clothes.
 Determining constraints and requirements: There’s a limited budget
for new supplies, and the student needs to be ready by a specific
date.
 Problem Analysis
 Breaking down complex problems into smaller parts:
 Create a list of required supplies, review the school schedule, and
plan clothing needs.
 Identifying patterns and relationships: Analyze which subjects require
specific textbooks and what items are left over from the previous
term.
 Determining necessary resources: Check what supplies can be reused
and what needs to be bought.
Planning for school resumption
Solution Design
 Creating algorithms: Outline the steps to follow:
 List all subjects for the new term.
 Research the needs for each subject (books, materials).
 Create a shopping list for supplies and clothes.
 Set aside time for back-to-school shopping.
 Planning data structures: Use a checklist or a digital app to
track what items are needed and which ones have already been
purchased.

 Designing user interfaces: If using an online store, make it user-


friendly for quick navigation and purchasing of items.
Planning for school resumption

Implementation
 Writing the actual code: In this context, it means putting the
plan into action—shopping for supplies, organizing the
backpack, and laying out clothes for the first day.
 Testing and debugging: After shopping, check to ensure all
items on the list have been bought; if something is missing,
adjust plans to acquire it.
 Optimizing performance: If the budget is tight, prioritize
essential items first and consider second-hand options for items
that are still in good condition.
COS 201
Computer Programming I
Algorithm
Algorithms

 An algorithm is a step-by-step procedure or formula for solving a


problem or performing a task.
 Used to instruct computers on how to process data and execute
specific operations.
 Each algorithm consists of a finite sequence of well-defined steps that
lead to the desired output, given a particular input.
Characteristics of an Algorithm

 Stepwise Procedure: An algorithm is a well-defined sequence of steps


or instructions that must be followed to solve a specific problem or
accomplish a particular task.
 Definiteness: The steps in an algorithm must be clear, unambiguous,
and executable in a finite amount of time.
 Input and Output: Algorithms typically take one or more inputs and
outputs, which can be data, values, or parameters needed to perform
the computation or task as well as the results of the computation or the
solution to the problem.
Characteristics of an Algorithm

 Effectiveness: An algorithm must be able to produce the correct output


for a given input within a reasonable amount of time and resources.
 Finiteness: An algorithm must terminate after a finite number of steps,
leading to a final solution or output
 Efficiency: Algorithms should be designed to minimize the use of
resources, such as time, memory, and computational power, while still
producing the desired output.
Methods of Representing Algorithm

 The steps to the solutions are broken into a series of logical steps in
English-like form
 There can’t be a solution if there is no recognized problem and once a
problem exists, one must take certain steps in order to get a desired
solution.
 The methods that can be used include;
English-like form (Pseudo code)
Flowchart
Decision table
Pseudo Code

 A pseudo-code is the English-like representation of the program logic.


 It does not make use of standard symbols like the flowchart.
 It is a sequential step by step arrangements of the instructions to be
performed to accomplish a task.
 It is an informal and artificial language that helps programmers
develop algorithms.
 The English form of representing as algorithm entails breaking down
the solution steps of the problem into single and sequential English
words.
 The steps are represented in English to say what action should be
taken in such a step.
Example 1

 Write a pseudo code for finding the area of a room.


 Solution:
Begin process
Input room length
Input room width
Multiply length by width to get area
Print area
End process
Example 2

 Write a Pseudo code for finding the greatest of 3 numbers represented as A,


B, and C.
Begin process
Input A,B,C
If A>B then big = A
Else big = B
If big >C then bigst = big
Else bigst = C
Print bigst
Example 3
 Write an Algorithm to determine a student’s final grade and indicate
whether it is passing or failing.

Input a set of 4 marks Step 1: Input M1, M2, M3, M4


Calculate their average by Step 2: Grade ← (M1 + M2 + M3 + M4)/4
summing and dividing by 4.
Step 3: If (Grade < 50) then
If average is below 50
Print “FALL”
Print “Fail” Print “Pass”
else
End it.
Print “Pass”
Flowchart

 Flowchart is a representation of the algorithm using standard symbols.


 Each symbols has a new function.
 The Algorithm steps determine which symbol to use to represent it in
the flow each step is linked to another step by using the directional
arrows.
 The symbols include:

Do Something Decision Connector Start/stop Input /


output

Direction or Flow Output


Start

Address Envelop

A flow chart for mailing letter


Fold Letter

Place in
Envelop

Have
stamp

Place in Envelop

Place in
Envelop

Stop
Example 1
 Write an algorithm and draw a flowchart to convert the length in feet to
centimeter.

Start
 (Pseudocode)
Input the length in feet (Lft) Input Lft

Calculate the length in an (LCM)


by multiplying LFT with 30 LCM ← Lft*30
Print Length in Cm (LCM)

Print LCM
Step 1: Input Lft
Step 2: Lcm ← Lft * 30
Stop
Step 3: Print Lcm Step 4: Stop
Uses of Flow chart

 It gives us an opportunity to see the entire system as a whole.


 It makes us to examine all possible logical outcomes in any process.
 It provides a tool for communicating i.e a flowchart helps to explain
the system to others.
 To provide insight into alternative solutions.
 It allows us to see what will happen if we change the values of the
variable in the system.
Advantage of flow chart
 Communication: flowcharts are visual aids for communicating the
logic of a system to all concerned

 Documentation: flowcharts are a means of documentation because


programmers may leave the arrangement or they may forget the logic
of the program.

 Easy to understand

 Analysis: flowcharts help to clarify the logic of a system i.e the


overall picture of the organization can be seen.
Disadvantage of Flowchart

 Complex logic: Where the logic of a problem is complex, the flowchart


quickly becomes clustered and lacks clarity.
 Alterations: If alterations are required the flowchart may require redrawing
completely.
 Reproduction: As the flowchart symbols cannot be typed, reproduction of
flowchart is often a problem
Decision Table

 A decision table is a form of truth table that structures the logic of a


problem into simple YES and No form.
 It breaks down different conditions and actions into a tabular format,
helping to visualize and compute various possible outcomes based on
specific conditions.
 It is a rectangle divided into four sections called quadrants.
 It provides a structure for showing logical relationships between
conditions that exist and actions to be taken as a result of these
conditions.
Key Components of a Decision Table

 Conditions: These are the inputs that trigger different actions. Each
condition can have two or more possible states (e.g., true/false,
high/low).

 Actions: These define the outcomes or what should happen when


certain conditions are met.

 Rules: Each combination of conditions leads to a specific rule that


dictates which action to take.
Structure of a Decision Table

 Condition Stubs: Lists all the conditions.

 Action Stubs: Lists all the possible actions.

 Rules: Specifies which action(s) to take for each combination of


conditions.

 Legend: Clarifies the meaning of different symbols or codes used in


the table (e.g., Y for yes, N for no)
Example

 Here’s a simple example of a decision table for a loan approval


process:
Applications

 Decision tables are widely used in various fields, including:


 Software development (specifically in testing)
 Business rules management
 Expert systems
 Decision analysis in various domains, like finance, healthcare, and
manufacturing.

You might also like